Sp3ctreDEV commited on
Commit
eea98e8
·
verified ·
1 Parent(s): 3a9c5c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +258 -76
app.py CHANGED
@@ -1,133 +1,315 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # ---------------------------------------------------------
5
- # L U A U S T A U S T I C T H E M E
6
- # ---------------------------------------------------------
7
  custom_css = """
8
- /* PAGE BACKGROUND ----------------------------------------------------- */
9
  body, .gradio-container {
10
- background: linear-gradient(135deg, #141e30, #243b55);
11
- color: #f0f0f0;
12
- font-family: 'Inter', sans-serif;
13
  }
14
 
15
- /* TITLE ------------------------------------------------------------- */
 
 
 
 
 
 
 
 
 
 
 
 
16
  #title {
17
- font-size: 48px;
18
  font-weight: 900;
19
  text-align: center;
20
- margin-bottom: 24px;
 
21
  color: #00f7ff;
22
- text-shadow: 0 0 30px #00f7ff;
 
 
 
23
  }
24
 
25
- /* CHATBOT BOX -------------------------------------------------------- */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  .gr-chatbot {
27
- border-radius: 20px;
28
- box-shadow: 0 4px 12px rgba(0,0,0,0.2);
29
- background: rgba(0, 0, 0, 0.25);
30
- backdrop-filter: blur(10px);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
32
 
33
- /* USER MESSAGES ----------------------------------------------------- */
34
  .message.user {
35
- background: rgba(0, 200, 255, 0.2);
36
- border-radius: 15px;
37
- padding: 12px 18px;
38
- animation: typing 0.6s forwards;
39
  }
40
 
41
- /* BOT MESSAGES ------------------------------------------------------ */
42
  .message.bot {
43
- background: rgba(0, 255, 110, 0.15);
44
- border-radius: 15px;
45
- padding: 12px 18px;
46
- animation: fadeIn 0.4s ease-out;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  }
48
 
49
- /* INPUT TEXTBOX ----------------------------------------------------- */
50
- textarea {
51
- border-radius: 15px;
52
- background: rgba(255,255,255,0.1);
53
- color: #ffffff;
54
- padding: 12px;
55
- border: none;
56
- outline: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  }
58
 
59
- /* ANIMATIONS -------------------------------------------------------- */
60
- @keyframes fadeIn {
61
- from { opacity: 0; transform: translateY(10px); }
62
- to { opacity: 1; transform: translateY(0); }
63
  }
64
- @keyframes typing {
65
- 0% { width: 0; opacity: 0.4; }
66
- 50% { opacity: 0.6; }
67
- 100%{ width: 100%; opacity: 1; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  }
69
  """
70
 
71
- # ---------------------------------------------------------
72
- # L U A U B O T L O G I C
73
- # ---------------------------------------------------------
74
  def respond(
75
- message: str,
76
  history: list[dict[str, str]],
77
- system_message: str,
78
- hf_token: str,
 
 
 
79
  ):
80
- """
81
- Stream the assistant's response.
82
- """
83
- # Prepare the system prompt
84
- system_prompt = (
85
  "You are Luau, a friendly, stylish AI assistant. "
86
- "Speak clearly, helpfully, and keep a calm, fun tone."
 
 
87
  )
88
 
89
- # Initialise HuggingFace inference client
90
  client = InferenceClient(
91
- token=hf_token,
92
- model="openai/gpt-oss-20b" # replace with your actual model ID
93
  )
94
 
95
- # Build the message list for the LLM
96
- messages = [{"role": "system", "content": system_prompt}]
97
  messages.extend(history)
98
  messages.append({"role": "user", "content": message})
99
 
100
- # Stream tokens from the model
101
  response = ""
102
- for chunk in client.chat_completion(
103
- messages,
104
- temperature=1.0,
105
- top_p=0.9,
106
  stream=True,
 
 
107
  ):
108
- token = chunk.choices[0].delta.content or ""
 
 
 
 
109
  response += token
110
  yield response
111
 
112
- # ---------------------------------------------------------
113
- # UI + ANIMATIONS
114
- # ---------------------------------------------------------
 
 
115
  chatbot = gr.ChatInterface(
116
- respond,
117
  type="messages",
118
  title="⭐ L U A U — The Animated AI Chatbot ⭐",
119
  css=custom_css,
120
  additional_inputs=[
121
- gr.Textbox(value="You are Luau, a friendly AI.", label="System Message"),
122
- gr.Textbox(value="", label="HuggingFace Token", placeholder="hf_..."),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  ],
124
  )
125
 
126
- with gr.Blocks(css=custom_css) as demo:
127
  gr.HTML("<div id='title'>⭐ Meet Luau — Your AI Companion ⭐</div>")
128
- with gr.Sidebar():
129
- gr.LoginButton()
130
- chatbot.render()
 
 
 
 
 
 
 
 
 
 
131
 
132
  if __name__ == "__main__":
133
- demo.launch(share=False)
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # ---------------------------
5
+ # L U A U S T A T I C T H E M E
6
+ # ---------------------------
7
  custom_css = """
8
+ /* GLOBAL PAGE BACKGROUND + FONT */
9
  body, .gradio-container {
10
+ background: radial-gradient(circle at top left, #1f2a3c 0%, #050812 40%, #050812 100%) !important;
11
+ color: #f8feff !important;
12
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", sans-serif;
13
  }
14
 
15
+ /* SCROLLBAR */
16
+ ::-webkit-scrollbar {
17
+ width: 8px;
18
+ }
19
+ ::-webkit-scrollbar-track {
20
+ background: rgba(255,255,255,0.05);
21
+ }
22
+ ::-webkit-scrollbar-thumb {
23
+ background: linear-gradient(180deg, #00f7ff, #00ff9d);
24
+ border-radius: 10px;
25
+ }
26
+
27
+ /* TITLE */
28
  #title {
29
+ font-size: 42px;
30
  font-weight: 900;
31
  text-align: center;
32
+ margin-top: 10px;
33
+ margin-bottom: 6px;
34
  color: #00f7ff;
35
+ text-shadow: 0 0 18px #00f7ff, 0 0 35px rgba(0, 247, 255, 0.9);
36
+ letter-spacing: 0.12em;
37
+ text-transform: uppercase;
38
+ animation: glowPulse 3s ease-in-out infinite;
39
  }
40
 
41
+ /* SUBTITLE */
42
+ #subtitle {
43
+ font-size: 14px;
44
+ text-align: center;
45
+ color: #9fdfff;
46
+ opacity: 0.9;
47
+ margin-bottom: 18px;
48
+ }
49
+
50
+ /* SIDEBAR */
51
+ .gradio-container .sidebar {
52
+ background: linear-gradient(180deg, rgba(0,0,0,0.35), rgba(0,0,0,0.8)) !important;
53
+ border-right: 1px solid rgba(0,247,255,0.2);
54
+ backdrop-filter: blur(20px);
55
+ box-shadow: 12px 0 25px rgba(0, 0, 0, 0.7);
56
+ }
57
+
58
+ /* LOGIN BUTTON */
59
+ button.login-button {
60
+ border-radius: 999px !important;
61
+ border: 1px solid rgba(0,247,255,0.4) !important;
62
+ background: radial-gradient(circle at 0 0, #00f7ff 0%, #006eff 40%, #002b7f 100%) !important;
63
+ color: white !important;
64
+ font-weight: 600 !important;
65
+ letter-spacing: 0.06em;
66
+ text-transform: uppercase;
67
+ box-shadow: 0 0 15px rgba(0,247,255,0.6);
68
+ transition: transform 0.18s ease-out, box-shadow 0.18s ease-out, filter 0.18s ease-out;
69
+ }
70
+ button.login-button:hover {
71
+ transform: translateY(-1px) scale(1.02);
72
+ box-shadow: 0 0 24px rgba(0,247,255,0.9);
73
+ filter: saturate(1.4);
74
+ }
75
+
76
+ /* CHATBOT CONTAINER */
77
  .gr-chatbot {
78
+ border-radius: 24px !important;
79
+ box-shadow: 0 0 35px rgba(0,255,255,0.42), 0 0 60px rgba(0,0,0,0.9) !important;
80
+ background: radial-gradient(circle at 0 0, rgba(0,247,255,0.1), rgba(0,0,0,0.85)) !important;
81
+ border: 1px solid rgba(0,247,255,0.45) !important;
82
+ overflow: hidden !important;
83
+ }
84
+
85
+ /* CHAT AREA BACKGROUND */
86
+ .gr-chatbot > div {
87
+ background: linear-gradient(145deg, rgba(0,0,0,0.74), rgba(3,16,40,0.95)) !important;
88
+ }
89
+
90
+ /* USER & BOT MESSAGES (Gradio v4 structure) */
91
+ .message.user, .message.bot {
92
+ border-radius: 16px !important;
93
+ padding: 10px 12px !important;
94
+ margin: 4px 0 !important;
95
+ max-width: 92%;
96
+ line-height: 1.45;
97
+ font-size: 14px;
98
+ backdrop-filter: blur(12px);
99
+ border: 1px solid transparent;
100
  }
101
 
102
+ /* USER MESSAGES */
103
  .message.user {
104
+ background: linear-gradient(135deg, rgba(0, 200, 255, 0.35), rgba(0, 76, 255, 0.35)) !important;
105
+ border-color: rgba(0,247,255,0.6);
106
+ box-shadow: 0 0 12px rgba(0,247,255,0.5);
107
+ animation: fadeInRight 0.35s ease-out;
108
  }
109
 
110
+ /* BOT MESSAGES */
111
  .message.bot {
112
+ background: linear-gradient(135deg, rgba(62, 252, 167, 0.3), rgba(20, 140, 90, 0.18)) !important;
113
+ border-color: rgba(0,255,153,0.6);
114
+ box-shadow: 0 0 12px rgba(0,255,153,0.4);
115
+ animation: fadeInUp 0.4s ease-out;
116
+ }
117
+
118
+ /* AVATARS (if enabled) */
119
+ .message.user .avatar, .message.bot .avatar {
120
+ filter: drop-shadow(0 0 5px rgba(0,247,255,0.8));
121
+ }
122
+
123
+ /* INPUT AREA */
124
+ textarea, .gr-textbox textarea {
125
+ border-radius: 18px !important;
126
+ background: linear-gradient(135deg, rgba(255,255,255,0.06), rgba(0,0,0,0.7)) !important;
127
+ backdrop-filter: blur(18px) !important;
128
+ color: #f7feff !important;
129
+ border: 1px solid rgba(0,247,255,0.45) !important;
130
+ box-shadow: 0 0 18px rgba(0,247,255,0.3);
131
+ resize: none !important;
132
+ }
133
+ textarea::placeholder {
134
+ color: rgba(200, 240, 255, 0.65);
135
  }
136
 
137
+ /* GLOBAL BUTTON STYLE */
138
+ button {
139
+ border-radius: 999px !important;
140
+ font-weight: 600 !important;
141
+ letter-spacing: 0.04em;
142
+ text-transform: uppercase;
143
+ border: 1px solid rgba(0,247,255,0.45) !important;
144
+ background: linear-gradient(120deg, #00f7ff, #00ff9d) !important;
145
+ color: #021318 !important;
146
+ box-shadow: 0 0 15px rgba(0,247,255,0.7);
147
+ transition: transform 0.16s ease-out, box-shadow 0.16s ease-out, filter 0.16s ease-out;
148
+ }
149
+ button:hover {
150
+ transform: translateY(-1px) scale(1.02);
151
+ box-shadow: 0 0 24px rgba(0,247,255,0.95);
152
+ filter: saturation(1.3);
153
+ }
154
+
155
+ /* SLIDERS + LABELS */
156
+ label, .gr-slider label, .gr-textbox label {
157
+ font-weight: 600 !important;
158
+ letter-spacing: 0.05em;
159
+ text-transform: uppercase;
160
+ font-size: 11px;
161
+ color: #88f6ff !important;
162
  }
163
 
164
+ input[type="range"]::-webkit-slider-thumb {
165
+ background: #00f7ff;
 
 
166
  }
167
+ input[type="range"]::-moz-range-thumb {
168
+ background: #00f7ff;
169
+ }
170
+
171
+ /* FOOTER / POWERED BY */
172
+ #footer {
173
+ text-align: center;
174
+ color: #7bc5ff;
175
+ font-size: 11px;
176
+ margin-top: 10px;
177
+ opacity: 0.75;
178
+ }
179
+ #footer a {
180
+ color: #00f7ff;
181
+ text-decoration: none;
182
+ }
183
+ #footer a:hover {
184
+ text-decoration: underline;
185
+ }
186
+
187
+ /* ANIMATIONS */
188
+ @keyframes glowPulse {
189
+ 0% {
190
+ text-shadow: 0 0 10px #00f7ff, 0 0 25px rgba(0, 247, 255, 0.7);
191
+ }
192
+ 50% {
193
+ text-shadow: 0 0 20px #00f7ff, 0 0 55px rgba(0, 247, 255, 1);
194
+ }
195
+ 100% {
196
+ text-shadow: 0 0 10px #00f7ff, 0 0 25px rgba(0, 247, 255, 0.7);
197
+ }
198
+ }
199
+
200
+ @keyframes fadeInRight {
201
+ from { opacity: 0; transform: translateX(14px); }
202
+ to { opacity: 1; transform: translateX(0); }
203
+ }
204
+
205
+ @keyframes fadeInUp {
206
+ from { opacity: 0; transform: translateY(8px); }
207
+ to { opacity: 1; transform: translateY(0); }
208
  }
209
  """
210
 
211
+ # ---------------------------
212
+ # L U A U B O T L O G I C
213
+ # ---------------------------
214
  def respond(
215
+ message,
216
  history: list[dict[str, str]],
217
+ system_message,
218
+ max_tokens,
219
+ temperature,
220
+ top_p,
221
+ hf_token: gr.OAuthToken,
222
  ):
223
+ # Inject Luau personality, but still allow overriding a bit via UI
224
+ merged_system_message = (
 
 
 
225
  "You are Luau, a friendly, stylish AI assistant. "
226
+ "You speak clearly and helpfully. Respond in a calm and fun tone. "
227
+ "Keep answers informative and concise unless asked for more detail. "
228
+ f"Extra instructions: {system_message}"
229
  )
230
 
 
231
  client = InferenceClient(
232
+ token=hf_token.token,
233
+ model="openai/gpt-oss-20b"
234
  )
235
 
236
+ messages = [{"role": "system", "content": merged_system_message}]
 
237
  messages.extend(history)
238
  messages.append({"role": "user", "content": message})
239
 
 
240
  response = ""
241
+ # Streaming response
242
+ for msg in client.chat_completion(
243
+ messages=messages,
244
+ max_tokens=max_tokens,
245
  stream=True,
246
+ temperature=temperature,
247
+ top_p=top_p,
248
  ):
249
+ choices = getattr(msg, "choices", [])
250
+ token = ""
251
+ if choices and choices[0].delta and choices[0].delta.get("content"):
252
+ token = choices[0].delta["content"]
253
+
254
  response += token
255
  yield response
256
 
257
+
258
+ # ---------------------------
259
+ # U I + A N I M A T I O N S
260
+ # ---------------------------
261
+
262
  chatbot = gr.ChatInterface(
263
+ fn=respond,
264
  type="messages",
265
  title="⭐ L U A U — The Animated AI Chatbot ⭐",
266
  css=custom_css,
267
  additional_inputs=[
268
+ gr.Textbox(
269
+ value="You are Luau, a friendly AI.",
270
+ label="System Message",
271
+ lines=2,
272
+ ),
273
+ # Remove artificial cap, allow big values; actual cap depends on model
274
+ gr.Slider(
275
+ minimum=1,
276
+ maximum=4096,
277
+ value=1024,
278
+ step=1,
279
+ label="Max Tokens",
280
+ ),
281
+ gr.Slider(
282
+ minimum=0.1,
283
+ maximum=4.0,
284
+ value=1.0,
285
+ step=0.1,
286
+ label="Temperature",
287
+ ),
288
+ gr.Slider(
289
+ minimum=0.1,
290
+ maximum=1.0,
291
+ value=0.9,
292
+ step=0.05,
293
+ label="Top-p",
294
+ ),
295
  ],
296
  )
297
 
298
+ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
299
  gr.HTML("<div id='title'>⭐ Meet Luau — Your AI Companion ⭐</div>")
300
+ gr.HTML("<div id='subtitle'>Neon-lit, glassy, and ready to chat in style.</div>")
301
+
302
+ with gr.Row(equal_height=True):
303
+ with gr.Column(scale=1):
304
+ with gr.Sidebar():
305
+ gr.HTML("<h3 style='color:#9ffcff;letter-spacing:0.15em;text-transform:uppercase;font-size:11px;margin-top:0;'>Luau Panel</h3>")
306
+ gr.LoginButton()
307
+ with gr.Column(scale=4):
308
+ chatbot.render()
309
+
310
+ gr.HTML(
311
+ "<div id='footer'>Powered by <a href='https://huggingface.co' target='_blank'>Hugging Face</a> • Styled for Luau</div>"
312
+ )
313
 
314
  if __name__ == "__main__":
315
+ demo.launch()