OthnnyEL commited on
Commit
33afad4
·
verified ·
1 Parent(s): 2f13802

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -52
app.py CHANGED
@@ -1,6 +1,6 @@
1
  # -*- coding: utf-8 -*-
2
  """
3
- FOIA CHAT ASSISTANCE - Text-only chatbot (STT and TTS removed)
4
  Drop this file into your Hugging Face Space (replace existing app.py) or run locally.
5
 
6
  Notes:
@@ -65,9 +65,9 @@ class WeeboAssistant:
65
  "Respond only in English. No long answers.\n"
66
  )
67
  # generation defaults tuned for speed (adjust if you need different behavior)
68
- self.MAX_NEW_TOKENS = 256 # lowered from 512 for speed
69
- self.DO_SAMPLE = False # greedy = faster; set True if you want sampling
70
- self.NUM_BEAMS = 1 # keep 1 for greedy (increase >1 for beam search)
71
  self._init_models()
72
 
73
  def _init_models(self):
@@ -212,10 +212,10 @@ class WeeboAssistant:
212
  generation_kwargs = dict(
213
  input_ids=inputs["input_ids"],
214
  attention_mask=inputs.get("attention_mask", None),
215
- max_length=max_length, # input_len + max_new
216
- max_new_tokens=max_new, # explicit
217
- do_sample=self.DO_SAMPLE, # greedy if False -> faster
218
- num_beams=self.NUM_BEAMS, # keep 1 for speed
219
  streamer=streamer,
220
  eos_token_id=getattr(self.llm_tokenizer, "eos_token_id", None),
221
  pad_token_id=getattr(self.llm_tokenizer, "pad_token_id", None),
@@ -259,74 +259,150 @@ def clear_textbox():
259
  return gr.Textbox.update(value="")
260
 
261
 
262
- # -------------------- Dark UI CSS --------------------
263
- DARK_CSS = """
264
- /* Base background & text */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  body, .gradio-container {
266
- background: linear-gradient(180deg, #04060a 0%, #0b1220 100%) !important;
267
- color: #E6EEF8 !important;
 
 
 
 
 
268
  }
269
 
270
- /* Header / Markdown text */
271
  h1, h2, h3, .markdown {
272
- color: #E6EEF8 !important;
273
  }
274
 
275
- /* Card backgrounds */
276
- .gr-block, .gr-box, .gr-row, .gr-column, .gradio-container .container {
277
- background-color: transparent !important;
 
278
  }
279
 
280
- /* Chatbot area */
281
  .gr-chatbot {
282
- background: rgba(10, 14, 22, 0.6) !important;
283
- border: 1px solid rgba(255,255,255,0.04) !important;
284
- color: #E6EEF8 !important;
 
285
  }
286
 
287
- /* Chat messages - user and assistant bubbles */
288
- .gr-chatbot .message.user, .gr-chatbot .message.user p {
289
- background: linear-gradient(180deg, #0f1724, #0b1220) !important;
290
- color: #CFE7FF !important;
291
- border: 1px solid rgba(255,255,255,0.04) !important;
292
  }
293
- .gr-chatbot .message.bot, .gr-chatbot .message.bot p {
294
- background: linear-gradient(180deg, #071126, #081426) !important;
295
- color: #E6EEF8 !important;
296
- border: 1px solid rgba(255,255,255,0.03) !important;
297
  }
 
 
 
 
 
 
298
 
299
- /* Input textbox and button */
300
  .gr-textbox, .gr-textbox textarea {
301
- background: #071226 !important;
302
- color: #E6EEF8 !important;
303
- border: 1px solid rgba(255,255,255,0.04) !important;
 
 
304
  }
305
- .gr-button, .gr-button:hover {
306
- background: linear-gradient(180deg, #0b63ff, #0a4ad6) !important;
307
- color: white !important;
308
- border: none !important;
309
- box-shadow: 0 6px 18px rgba(6, 18, 55, 0.5) !important;
310
  }
311
 
312
- /* Small UI tweaks */
313
- footer, .footer {
314
- display: none;
 
 
 
 
 
 
 
 
 
315
  }
316
- .gradio-container * {
317
- font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  }
319
  """
320
 
321
- # -------------------- Gradio UI (dark) --------------------
322
- with gr.Blocks(css=DARK_CSS, title="YOUR FOIA CHAT ASSISTANCE") as demo:
323
- gr.Markdown("# YOUR FOIA CHAT ASSISTANCE")
324
- gr.Markdown("Chat (text-based) with the FOIA assistant. Use the box below to type your question.")
 
 
 
 
 
 
 
 
 
325
 
326
  t2t_chatbot = gr.Chatbot(label="Conversation", bubble_full_width=False, height=520)
 
 
327
  with gr.Row():
328
- t2t_text_in = gr.Textbox(show_label=False, placeholder="Type your message here...", scale=4, container=False)
329
- t2t_submit_btn = gr.Button("Send", variant="primary", scale=1)
 
 
 
 
 
 
 
 
 
 
330
 
331
  t2t_submit_btn.click(
332
  fn=t2t_pipeline,
@@ -351,4 +427,5 @@ with gr.Blocks(css=DARK_CSS, title="YOUR FOIA CHAT ASSISTANCE") as demo:
351
  )
352
 
353
  # launch
354
- demo.queue().launch(debug=True)
 
 
1
  # -*- coding: utf-8 -*-
2
  """
3
+ YOUR FOIA CHAT ASSISTANCE - Text-only chatbot (STT and TTS removed)
4
  Drop this file into your Hugging Face Space (replace existing app.py) or run locally.
5
 
6
  Notes:
 
65
  "Respond only in English. No long answers.\n"
66
  )
67
  # generation defaults tuned for speed (adjust if you need different behavior)
68
+ self.MAX_NEW_TOKENS = 256 # lowered from 512 for speed
69
+ self.DO_SAMPLE = False # greedy = faster; set True if you want sampling
70
+ self.NUM_BEAMS = 1 # keep 1 for greedy (increase >1 for beam search)
71
  self._init_models()
72
 
73
  def _init_models(self):
 
212
  generation_kwargs = dict(
213
  input_ids=inputs["input_ids"],
214
  attention_mask=inputs.get("attention_mask", None),
215
+ max_length=max_length, # input_len + max_new
216
+ max_new_tokens=max_new, # explicit
217
+ do_sample=self.DO_SAMPLE, # greedy if False -> faster
218
+ num_beams=self.NUM_BEAMS, # keep 1 for speed
219
  streamer=streamer,
220
  eos_token_id=getattr(self.llm_tokenizer, "eos_token_id", None),
221
  pad_token_id=getattr(self.llm_tokenizer, "pad_token_id", None),
 
259
  return gr.Textbox.update(value="")
260
 
261
 
262
+ # -------------------- MODIFIED: Modern Dark UI CSS --------------------
263
+ MODERN_CSS = """
264
+ @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');
265
+
266
+ :root {
267
+ --body-bg: linear-gradient(135deg, #10141a 0%, #06090f 100%);
268
+ --chat-bg: #0b0f19;
269
+ --border-color: rgba(255, 255, 255, 0.08);
270
+ --text-color: #E6EEF8;
271
+ --input-bg: #131926;
272
+ --user-msg-bg: #1B2336;
273
+ --bot-msg-bg: #0F1522;
274
+ --primary-color: #0084ff;
275
+ --primary-hover: #006fdb;
276
+ --font-family: 'Poppins', sans-serif;
277
+ }
278
+
279
  body, .gradio-container {
280
+ background: var(--body-bg) !important;
281
+ color: var(--text-color) !important;
282
+ font-family: var(--font-family) !important;
283
+ }
284
+
285
+ .gradio-container * {
286
+ font-family: var(--font-family) !important;
287
  }
288
 
 
289
  h1, h2, h3, .markdown {
290
+ color: var(--text-color) !important;
291
  }
292
 
293
+ .gr-block, .gr-box, .gr-row, .gr-column {
294
+ background: transparent !important;
295
+ border: none !important;
296
+ box-shadow: none !important;
297
  }
298
 
 
299
  .gr-chatbot {
300
+ background: var(--chat-bg) !important;
301
+ border: 1px solid var(--border-color) !important;
302
+ border-radius: 12px !important;
303
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
304
  }
305
 
306
+ .gr-chatbot .message {
307
+ border-radius: 8px !important;
308
+ padding: 12px !important;
309
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
310
+ border: none !important;
311
  }
312
+
313
+ .gr-chatbot .message.user {
314
+ background: var(--user-msg-bg) !important;
315
+ color: var(--text-color) !important;
316
  }
317
+ .gr-chatbot .message.bot {
318
+ background: var(--bot-msg-bg) !important;
319
+ color: var(--text-color) !important;
320
+ }
321
+
322
+ .gr-chatbot .message p { margin: 0; }
323
 
 
324
  .gr-textbox, .gr-textbox textarea {
325
+ background: var(--input-bg) !important;
326
+ color: var(--text-color) !important;
327
+ border: 1px solid var(--border-color) !important;
328
+ border-radius: 8px !important;
329
+ transition: all 0.2s ease-in-out;
330
  }
331
+ .gr-textbox:focus, .gr-textbox textarea:focus {
332
+ border-color: var(--primary-color) !important;
333
+ box-shadow: 0 0 0 2px rgba(0, 132, 255, 0.3) !important;
 
 
334
  }
335
 
336
+ .gr-button {
337
+ background: var(--primary-color) !important;
338
+ color: white !important;
339
+ border: none !important;
340
+ border-radius: 8px !important;
341
+ box-shadow: 0 4px 12px rgba(0, 132, 255, 0.2) !important;
342
+ transition: all 0.2s ease-in-out !important;
343
+ font-weight: 500 !important;
344
+ display: flex;
345
+ justify-content: center;
346
+ align-items: center;
347
+ gap: 8px; /* Space between icon and text */
348
  }
349
+
350
+ .gr-button:hover {
351
+ background: var(--primary-hover) !important;
352
+ transform: translateY(-2px);
353
+ box-shadow: 0 6px 16px rgba(0, 132, 255, 0.3) !important;
354
+ }
355
+ /* Hide default Gradio button text when we add our own */
356
+ .send-btn span {
357
+ font-size: 1rem;
358
+ }
359
+ /* Add a send icon to the button */
360
+ .send-btn::before {
361
+ content: '';
362
+ display: inline-block;
363
+ width: 20px;
364
+ height: 20px;
365
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M2.01 21L23 12 2.01 3 2 10l15 2-15 2z'/%3E%3C/svg%3E");
366
+ background-size: contain;
367
+ background-repeat: no-repeat;
368
+ background-position: center;
369
+ }
370
+
371
+ footer, .footer {
372
+ display: none !important;
373
  }
374
  """
375
 
376
+ # -------------------- MODIFIED: Gradio UI with Logo --------------------
377
+ with gr.Blocks(css=MODERN_CSS, title="DimChi FOIA Assistant") as demo:
378
+ # NEW: Centered header with logo
379
+ with gr.Row():
380
+ gr.Markdown(
381
+ """
382
+ <div style="text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px;">
383
+ <img src="file/logo.png" alt="DimChi Logo" style="max-width: 120px; margin-bottom: 15px;">
384
+ <h1 style="margin: 0; font-size: 2.5rem; font-weight: 700;">DimChi FOIA Assistant</h1>
385
+ <p style="margin: 5px 0 0 0; font-size: 1.1rem; color: #a0b0c0;">Your intelligent chat partner for FOIA inquiries.</p>
386
+ </div>
387
+ """
388
+ )
389
 
390
  t2t_chatbot = gr.Chatbot(label="Conversation", bubble_full_width=False, height=520)
391
+
392
+ # NEW: Added elem_classes for specific button styling
393
  with gr.Row():
394
+ t2t_text_in = gr.Textbox(
395
+ show_label=False,
396
+ placeholder="Type your message here...",
397
+ scale=4,
398
+ container=False
399
+ )
400
+ t2t_submit_btn = gr.Button(
401
+ "Send",
402
+ variant="primary",
403
+ scale=1,
404
+ elem_classes="send-btn" # NEW: Class for CSS targeting
405
+ )
406
 
407
  t2t_submit_btn.click(
408
  fn=t2t_pipeline,
 
427
  )
428
 
429
  # launch
430
+ # MODIFIED: Removed debug=True for a cleaner console in production
431
+ demo.queue().launch()