yogies commited on
Commit
d8ae15c
·
verified ·
1 Parent(s): 7ecc18a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -95
app.py CHANGED
@@ -54,9 +54,6 @@ MODEL_NAMES = list(MODELS.keys())
54
  # Core Chat Logic
55
  # ----------------------------------------------------------------------
56
  def generate_response(history, system_message, max_tokens, selected_model):
57
- """
58
- Generates the response.
59
- """
60
  if not history:
61
  return history
62
 
@@ -78,7 +75,6 @@ def generate_response(history, system_message, max_tokens, selected_model):
78
  final_system_message = system_message
79
 
80
  messages = [{"role": "system", "content": final_system_message}]
81
- # Sanitize history
82
  api_history = [{"role": m["role"], "content": m["content"]} for m in history]
83
  messages.extend(api_history)
84
 
@@ -127,30 +123,33 @@ def user_input(user_message, history):
127
  return history, ""
128
 
129
  # ----------------------------------------------------------------------
130
- # CSS / Visual System ("The Alabaster Construct")
131
  # ----------------------------------------------------------------------
132
  current_date_display = datetime.now().strftime("%B %d, %Y")
133
 
134
  css = """
135
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500&family=JetBrains+Mono:wght@400;500&family=Space+Grotesk:wght@300;400;600&display=swap');
136
-
137
- /* 1. GLOBAL VARIABLES & RESET */
138
- :root {
 
 
 
 
 
 
 
139
  --bg-core: #FAFAFA;
140
- --bg-light: #FFFFFF;
141
- --text-primary: #111111; /* Ink */
142
- --text-body: #444444; /* Graphite */
143
  --text-dim: #999999;
144
- --border-glass: rgba(0, 0, 0, 0.06);
145
- --border-highlight: rgba(0, 0, 0, 0.12);
146
- --surface-glass: rgba(255, 255, 255, 0.7);
147
  --font-head: 'Space Grotesk', sans-serif;
148
  --font-body: 'Inter', sans-serif;
149
- --font-mono: 'JetBrains Mono', monospace;
150
  }
151
 
152
- body, .gradio-container {
153
- background-color: var(--bg-core) !important;
154
  background: radial-gradient(circle at 50% 50%, #FFFFFF 0%, #F2F2F4 100%) !important;
155
  background-size: 150% 150% !important;
156
  animation: daylight 25s ease-in-out infinite alternate;
@@ -182,19 +181,16 @@ body, .gradio-container {
182
  font-weight: 600;
183
  font-size: 2rem;
184
  color: var(--text-primary);
185
- letter-spacing: -0.04em;
186
  margin: 0;
187
  }
188
  .liquid-header .meta {
189
- font-family: var(--font-mono);
190
- font-size: 0.75rem;
191
  color: var(--text-dim);
192
  margin-top: 0.5rem;
193
- letter-spacing: 0.1em;
194
- text-transform: uppercase;
195
  }
196
 
197
- /* 4. CHATBOT (The Data Blocks) */
198
  .gradio-container .chatbot {
199
  background: transparent !important;
200
  border: none !important;
@@ -203,120 +199,97 @@ body, .gradio-container {
203
  overflow-y: auto;
204
  }
205
  .message {
206
- border-radius: 4px !important;
207
  border: 1px solid var(--border-glass) !important;
208
- padding: 1rem !important;
209
  margin-bottom: 1rem !important;
210
- box-shadow: 0 2px 8px rgba(0,0,0,0.02) !important;
211
  }
212
- /* User Block */
213
  .message.user {
214
- background-color: #F4F4F5 !important; /* Slight Grey Wash */
215
- border-left: 2px solid var(--text-dim) !important;
216
  justify-content: flex-end;
217
  }
218
- /* Bot Block */
219
  .message.bot {
220
- background-color: #FFFFFF !important;
221
- border-left: 2px solid var(--text-primary) !important;
222
  }
223
  .message * {
224
  font-family: var(--font-body);
225
  color: var(--text-body) !important;
226
- font-size: 0.95rem !important;
227
  line-height: 1.6 !important;
228
  }
229
 
230
- /* 5. COMMAND BAR (Input) */
231
  .command-bar textarea {
232
- background: var(--surface-glass) !important;
233
  backdrop-filter: blur(12px) !important;
234
  -webkit-backdrop-filter: blur(12px) !important;
235
- border: 1px solid var(--border-highlight) !important;
236
  border-radius: 12px !important;
237
- box-shadow: 0 8px 30px rgba(0,0,0,0.06) !important;
238
  color: var(--text-primary) !important;
239
  font-family: var(--font-body) !important;
240
  padding: 1rem !important;
241
  font-size: 1rem !important;
242
- transition: all 0.2s ease;
243
  }
244
  .command-bar textarea:focus {
245
- border-color: var(--text-primary) !important;
246
  background: #FFFFFF !important;
247
- box-shadow: 0 12px 40px rgba(0,0,0,0.1) !important;
248
  }
249
 
250
- /* 6. HUD (Settings Accordion) */
251
  .hud-accordion {
252
  background: transparent !important;
253
  border: none !important;
254
  margin-top: 1rem !important;
255
  }
256
  .hud-accordion .label-wrap {
257
- font-family: var(--font-mono) !important;
258
- font-size: 0.7rem !important;
259
- text-transform: uppercase !important;
260
- letter-spacing: 0.1em !important;
261
  color: var(--text-dim) !important;
262
- cursor: pointer;
263
  }
264
- /* HUD Inputs */
265
  .hud-panel {
266
  border-top: 1px solid var(--border-glass);
267
  padding-top: 1rem;
268
  }
269
- .hud-panel .block {
270
- background: transparent !important;
271
- border: none !important;
 
 
272
  }
273
- .hud-panel label span {
274
- font-family: var(--font-mono) !important;
275
- font-size: 0.7rem !important;
276
  color: var(--text-dim) !important;
277
- text-transform: uppercase;
278
- }
279
- .hud-panel input, .hud-panel textarea, .hud-panel .wrap {
280
- background: rgba(255,255,255,0.5) !important;
281
- border: 1px solid var(--border-glass) !important;
282
- font-family: var(--font-mono) !important;
283
- font-size: 0.8rem !important;
284
- color: var(--text-primary) !important;
285
  }
286
 
287
- /* 7. BUTTONS & EXAMPLES */
288
- button.primary-btn {
289
- background: var(--text-primary) !important;
290
- color: #FFF !important;
291
- font-family: var(--font-mono) !important;
292
- border-radius: 6px !important;
293
- text-transform: uppercase;
294
- letter-spacing: 0.05em;
295
- font-size: 0.75rem !important;
296
- }
297
  .examples-container button {
298
- background: #FFF !important;
299
  border: 1px solid var(--border-glass) !important;
300
- font-family: var(--font-body) !important;
301
- font-size: 0.85rem !important;
302
  color: var(--text-body) !important;
303
- border-radius: 4px !important;
304
- transition: all 0.2s;
 
 
305
  }
306
  .examples-container button:hover {
307
- border-color: var(--text-primary) !important;
308
- transform: translateY(-1px);
309
  }
310
 
311
- /* Hide Footer */
312
  footer { display: none !important; }
313
  """
314
 
315
  header_html = f"""
316
  <div class="liquid-header">
317
- <h1>ALABASTER CONSTRUCT</h1>
318
  <div class="meta">
319
- SYSTEM ONLINE • {current_date_display} • SECURE CHANNEL
320
  </div>
321
  </div>
322
  """
@@ -325,7 +298,7 @@ header_html = f"""
325
  # Layout Construction
326
  # ----------------------------------------------------------------------
327
  with gr.Blocks(
328
- title="Alabaster AI",
329
  theme=gr.themes.Soft(primary_hue="neutral", radius_size="none"),
330
  css=css
331
  ) as demo:
@@ -335,19 +308,19 @@ with gr.Blocks(
335
  # 1. Header
336
  gr.HTML(header_html)
337
 
338
- # 2. Chat Area (Data Blocks)
339
  chatbot = gr.Chatbot(
340
  type="messages",
341
  show_label=False,
342
- avatar_images=None,
343
  render_markdown=True,
344
  elem_id="main-chatbot"
345
  )
346
 
347
- # 3. Command Bar (Input)
348
  with gr.Row():
349
  msg_input = gr.Textbox(
350
- placeholder="Enter command or query...",
351
  label=None,
352
  show_label=False,
353
  lines=1,
@@ -356,31 +329,31 @@ with gr.Blocks(
356
  autofocus=True
357
  )
358
 
359
- # 4. HUD / Settings (Below Input, Compact)
360
- with gr.Accordion("/// SYSTEM PARAMETERS", open=False, elem_classes="hud-accordion"):
361
  with gr.Column(elem_classes="hud-panel"):
362
  with gr.Row():
363
  selected_model = gr.Dropdown(
364
  choices=MODEL_NAMES,
365
  value=MODEL_NAMES[0],
366
- label="INFERENCE ENGINE",
367
  interactive=True,
368
  scale=2
369
  )
370
  max_tokens = gr.Slider(
371
  minimum=1, maximum=30000, value=4000, step=100,
372
- label="TOKEN LIMIT",
373
  scale=1
374
  )
375
  with gr.Row():
376
  system_message = gr.Textbox(
377
  value="Anda adalah asisten AI. Jawab dalam Bahasa Indonesia, di bawah 100 kata. Berikan label yang jelas antara fakta dan inferensi.",
378
- label="PRIME DIRECTIVE (SYSTEM PROMPT)",
379
- lines=1,
380
  max_lines=3
381
  )
382
 
383
- # 5. Examples (Fixed: Wrapped in Column to apply CSS class)
384
  with gr.Column(elem_classes="examples-container"):
385
  gr.Examples(
386
  examples=[
@@ -407,7 +380,7 @@ with gr.Blocks(
407
  if __name__ == "__main__":
408
  demo.launch(
409
  auth=gradio_auth,
410
- auth_message="ACCESS CONTROL: IDENTIFY YOURSELF",
411
  server_name="0.0.0.0",
412
  ssr_mode=False,
413
  server_port=7860,
 
54
  # Core Chat Logic
55
  # ----------------------------------------------------------------------
56
  def generate_response(history, system_message, max_tokens, selected_model):
 
 
 
57
  if not history:
58
  return history
59
 
 
75
  final_system_message = system_message
76
 
77
  messages = [{"role": "system", "content": final_system_message}]
 
78
  api_history = [{"role": m["role"], "content": m["content"]} for m in history]
79
  messages.extend(api_history)
80
 
 
123
  return history, ""
124
 
125
  # ----------------------------------------------------------------------
126
+ # CSS / Visual System ("Alabaster Clean")
127
  # ----------------------------------------------------------------------
128
  current_date_display = datetime.now().strftime("%B %d, %Y")
129
 
130
  css = """
131
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500&family=Space+Grotesk:wght@400;600&display=swap');
132
+
133
+ /* 1. FORCE LIGHT MODE / RESET DARK THEME LEAKS */
134
+ :root, .dark, body, .gradio-container {
135
+ --body-background-fill: #FAFAFA !important;
136
+ --body-text-color: #444444 !important;
137
+ --background-fill-primary: #FFFFFF !important;
138
+ --background-fill-secondary: #FAFAFA !important;
139
+ --block-background-fill: #FFFFFF !important;
140
+ --block-label-text-color: #999999 !important;
141
+ --input-background-fill: rgba(255, 255, 255, 0.7) !important;
142
  --bg-core: #FAFAFA;
143
+ --text-primary: #111111;
144
+ --text-body: #444444;
 
145
  --text-dim: #999999;
146
+ --border-glass: rgba(0, 0, 0, 0.08);
 
 
147
  --font-head: 'Space Grotesk', sans-serif;
148
  --font-body: 'Inter', sans-serif;
 
149
  }
150
 
151
+ /* Force background animation on body */
152
+ body {
153
  background: radial-gradient(circle at 50% 50%, #FFFFFF 0%, #F2F2F4 100%) !important;
154
  background-size: 150% 150% !important;
155
  animation: daylight 25s ease-in-out infinite alternate;
 
181
  font-weight: 600;
182
  font-size: 2rem;
183
  color: var(--text-primary);
 
184
  margin: 0;
185
  }
186
  .liquid-header .meta {
187
+ font-family: var(--font-body);
188
+ font-size: 0.85rem;
189
  color: var(--text-dim);
190
  margin-top: 0.5rem;
 
 
191
  }
192
 
193
+ /* 4. CHATBOT (Clean Paper Look) */
194
  .gradio-container .chatbot {
195
  background: transparent !important;
196
  border: none !important;
 
199
  overflow-y: auto;
200
  }
201
  .message {
202
+ border-radius: 8px !important;
203
  border: 1px solid var(--border-glass) !important;
204
+ padding: 1.2rem !important;
205
  margin-bottom: 1rem !important;
206
+ box-shadow: 0 2px 6px rgba(0,0,0,0.03) !important;
207
  }
208
+ /* User Message */
209
  .message.user {
210
+ background-color: #F4F4F5 !important; /* Light Grey */
211
+ border-left: none !important;
212
  justify-content: flex-end;
213
  }
214
+ /* Bot Message */
215
  .message.bot {
216
+ background-color: #FFFFFF !important; /* Pure White */
217
+ border-left: none !important;
218
  }
219
  .message * {
220
  font-family: var(--font-body);
221
  color: var(--text-body) !important;
222
+ font-size: 1rem !important;
223
  line-height: 1.6 !important;
224
  }
225
 
226
+ /* 5. INPUT BAR */
227
  .command-bar textarea {
228
+ background: rgba(255, 255, 255, 0.85) !important;
229
  backdrop-filter: blur(12px) !important;
230
  -webkit-backdrop-filter: blur(12px) !important;
231
+ border: 1px solid var(--border-glass) !important;
232
  border-radius: 12px !important;
233
+ box-shadow: 0 4px 20px rgba(0,0,0,0.05) !important;
234
  color: var(--text-primary) !important;
235
  font-family: var(--font-body) !important;
236
  padding: 1rem !important;
237
  font-size: 1rem !important;
 
238
  }
239
  .command-bar textarea:focus {
240
+ border-color: var(--text-dim) !important;
241
  background: #FFFFFF !important;
242
+ box-shadow: 0 8px 30px rgba(0,0,0,0.08) !important;
243
  }
244
 
245
+ /* 6. SETTINGS (Simple HUD) */
246
  .hud-accordion {
247
  background: transparent !important;
248
  border: none !important;
249
  margin-top: 1rem !important;
250
  }
251
  .hud-accordion .label-wrap {
252
+ font-family: var(--font-body) !important;
253
+ font-size: 0.85rem !important;
 
 
254
  color: var(--text-dim) !important;
 
255
  }
 
256
  .hud-panel {
257
  border-top: 1px solid var(--border-glass);
258
  padding-top: 1rem;
259
  }
260
+ /* Force white backgrounds on inputs inside settings to kill dark mode leaks */
261
+ .hud-panel input, .hud-panel textarea, .hud-panel .single-select, .hud-panel .wrap {
262
+ background-color: #FFFFFF !important;
263
+ color: #000000 !important;
264
+ border: 1px solid var(--border-glass) !important;
265
  }
266
+ .hud-panel span {
 
 
267
  color: var(--text-dim) !important;
 
 
 
 
 
 
 
 
268
  }
269
 
270
+ /* 7. EXAMPLES */
 
 
 
 
 
 
 
 
 
271
  .examples-container button {
272
+ background: #FFFFFF !important;
273
  border: 1px solid var(--border-glass) !important;
 
 
274
  color: var(--text-body) !important;
275
+ border-radius: 6px !important;
276
+ font-size: 0.9rem !important;
277
+ padding: 0.5rem 1rem !important;
278
+ margin: 4px !important;
279
  }
280
  .examples-container button:hover {
281
+ background-color: #F9FAFB !important;
282
+ border-color: var(--text-dim) !important;
283
  }
284
 
 
285
  footer { display: none !important; }
286
  """
287
 
288
  header_html = f"""
289
  <div class="liquid-header">
290
+ <h1>AI Workspace</h1>
291
  <div class="meta">
292
+ {current_date_display} • Secure Environment
293
  </div>
294
  </div>
295
  """
 
298
  # Layout Construction
299
  # ----------------------------------------------------------------------
300
  with gr.Blocks(
301
+ title="AI Workspace",
302
  theme=gr.themes.Soft(primary_hue="neutral", radius_size="none"),
303
  css=css
304
  ) as demo:
 
308
  # 1. Header
309
  gr.HTML(header_html)
310
 
311
+ # 2. Chat Area
312
  chatbot = gr.Chatbot(
313
  type="messages",
314
  show_label=False,
315
+ avatar_images=None,
316
  render_markdown=True,
317
  elem_id="main-chatbot"
318
  )
319
 
320
+ # 3. Input Bar
321
  with gr.Row():
322
  msg_input = gr.Textbox(
323
+ placeholder="Type a message...",
324
  label=None,
325
  show_label=False,
326
  lines=1,
 
329
  autofocus=True
330
  )
331
 
332
+ # 4. Settings (Accordion below input)
333
+ with gr.Accordion("Settings", open=False, elem_classes="hud-accordion"):
334
  with gr.Column(elem_classes="hud-panel"):
335
  with gr.Row():
336
  selected_model = gr.Dropdown(
337
  choices=MODEL_NAMES,
338
  value=MODEL_NAMES[0],
339
+ label="Select Model",
340
  interactive=True,
341
  scale=2
342
  )
343
  max_tokens = gr.Slider(
344
  minimum=1, maximum=30000, value=4000, step=100,
345
+ label="Token Limit",
346
  scale=1
347
  )
348
  with gr.Row():
349
  system_message = gr.Textbox(
350
  value="Anda adalah asisten AI. Jawab dalam Bahasa Indonesia, di bawah 100 kata. Berikan label yang jelas antara fakta dan inferensi.",
351
+ label="System Prompt",
352
+ lines=2,
353
  max_lines=3
354
  )
355
 
356
+ # 5. Examples
357
  with gr.Column(elem_classes="examples-container"):
358
  gr.Examples(
359
  examples=[
 
380
  if __name__ == "__main__":
381
  demo.launch(
382
  auth=gradio_auth,
383
+ auth_message="Please login to access the chat interface",
384
  server_name="0.0.0.0",
385
  ssr_mode=False,
386
  server_port=7860,