Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -7,8 +7,6 @@ from pathlib import Path
|
|
7 |
import spaces
|
8 |
import gradio as gr
|
9 |
|
10 |
-
# WARNING: Don't import torch, cuda, or GPU-related modules at the top level
|
11 |
-
# They must ONLY be imported inside functions decorated with @spaces.GPU
|
12 |
|
13 |
# Helper functions that don't use GPU
|
14 |
def safe_tokenize(text):
|
@@ -327,7 +325,6 @@ Question: {query} [/INST]</s>"""
|
|
327 |
self.conversation_history = []
|
328 |
return "Conversation has been reset."
|
329 |
|
330 |
-
|
331 |
def main():
|
332 |
# Create the Vision 2030 service
|
333 |
service = Vision2030Service()
|
@@ -365,35 +362,46 @@ def main():
|
|
365 |
.lang-btn { min-width: 100px; }
|
366 |
.chat-input { background-color: white; border-radius: 8px; border: 1px solid #ddd; }
|
367 |
.info-box { background-color: #f8f9fa; padding: 10px; border-radius: 8px; margin-top: 10px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
368 |
""") as demo:
|
369 |
# Header with stylized title (no external images)
|
370 |
with gr.Row():
|
371 |
with gr.Column():
|
372 |
-
gr.
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
</div>
|
385 |
-
</div>
|
386 |
-
""")
|
387 |
-
|
388 |
-
# Language toggle in the header
|
389 |
with gr.Row(elem_classes=["language-toggle"]):
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
|
|
397 |
|
398 |
# Main interface with tabs
|
399 |
with gr.Tabs() as tabs:
|
@@ -447,20 +455,18 @@ def main():
|
|
447 |
|
448 |
init_btn = gr.Button("Initialize System", variant="primary")
|
449 |
|
450 |
-
#
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
interactive=True
|
463 |
-
)
|
464 |
|
465 |
# Analytics and insights tab
|
466 |
with gr.TabItem("📊 Analytics", id="analytics"):
|
@@ -823,11 +829,13 @@ def main():
|
|
823 |
|
824 |
init_btn.click(initialize_system, None, [status_box, system_status])
|
825 |
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
)
|
|
|
|
|
831 |
|
832 |
pdf_btn.click(check_pdfs, None, pdf_status)
|
833 |
sys_btn.click(check_dependencies, None, sys_status)
|
|
|
7 |
import spaces
|
8 |
import gradio as gr
|
9 |
|
|
|
|
|
10 |
|
11 |
# Helper functions that don't use GPU
|
12 |
def safe_tokenize(text):
|
|
|
325 |
self.conversation_history = []
|
326 |
return "Conversation has been reset."
|
327 |
|
|
|
328 |
def main():
|
329 |
# Create the Vision 2030 service
|
330 |
service = Vision2030Service()
|
|
|
362 |
.lang-btn { min-width: 100px; }
|
363 |
.chat-input { background-color: white; border-radius: 8px; border: 1px solid #ddd; }
|
364 |
.info-box { background-color: #f8f9fa; padding: 10px; border-radius: 8px; margin-top: 10px; }
|
365 |
+
/* Style for sample question buttons */
|
366 |
+
.gradio-button.secondary {
|
367 |
+
margin-bottom: 8px;
|
368 |
+
text-align: left;
|
369 |
+
background-color: #f0f9ff;
|
370 |
+
transition: all 0.3s ease;
|
371 |
+
display: block;
|
372 |
+
width: 100%;
|
373 |
+
padding: 8px 12px;
|
374 |
+
}
|
375 |
+
.gradio-button.secondary:hover {
|
376 |
+
background-color: #e0f2fe;
|
377 |
+
transform: translateX(3px);
|
378 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
379 |
+
}
|
380 |
""") as demo:
|
381 |
# Header with stylized title (no external images)
|
382 |
with gr.Row():
|
383 |
with gr.Column():
|
384 |
+
with gr.Row():
|
385 |
+
# Add local logo image on the left
|
386 |
+
with gr.Column(scale=1, min_width=100):
|
387 |
+
gr.Image("logo.png", show_label=False, height=80)
|
388 |
+
# Title and tagline on the right
|
389 |
+
with gr.Column(scale=4):
|
390 |
+
gr.Markdown("""
|
391 |
+
# Vision 2030 Assistant
|
392 |
+
### Your interactive guide to Saudi Arabia's national transformation program
|
393 |
+
""")
|
394 |
+
|
395 |
+
# Language toggle in the header with better styling
|
|
|
|
|
|
|
|
|
|
|
396 |
with gr.Row(elem_classes=["language-toggle"]):
|
397 |
+
with gr.Column(scale=1):
|
398 |
+
language_toggle = gr.Radio(
|
399 |
+
choices=["English", "العربية (Arabic)", "Auto-detect"],
|
400 |
+
value="Auto-detect",
|
401 |
+
label="Interface Language",
|
402 |
+
info="Choose your preferred language",
|
403 |
+
elem_classes=["lang-btn"]
|
404 |
+
)
|
405 |
|
406 |
# Main interface with tabs
|
407 |
with gr.Tabs() as tabs:
|
|
|
455 |
|
456 |
init_btn = gr.Button("Initialize System", variant="primary")
|
457 |
|
458 |
+
# Replace dropdown with clickable buttons
|
459 |
+
gr.Markdown("### Sample Questions")
|
460 |
+
with gr.Group():
|
461 |
+
# English questions
|
462 |
+
q1_btn = gr.Button("What is Saudi Vision 2030?", variant="secondary")
|
463 |
+
q2_btn = gr.Button("What are the economic goals of Vision 2030?", variant="secondary")
|
464 |
+
q3_btn = gr.Button("How does Vision 2030 aim to improve quality of life?", variant="secondary")
|
465 |
+
|
466 |
+
# Arabic questions
|
467 |
+
q4_btn = gr.Button("ما هي رؤية السعودية 2030؟", variant="secondary")
|
468 |
+
q5_btn = gr.Button("ما هي الأهداف الاقتصادية لرؤية 2030؟", variant="secondary")
|
469 |
+
q6_btn = gr.Button("كيف تعزز رؤية 2030 الإرث الثقافي السعودي؟", variant="secondary")
|
|
|
|
|
470 |
|
471 |
# Analytics and insights tab
|
472 |
with gr.TabItem("📊 Analytics", id="analytics"):
|
|
|
829 |
|
830 |
init_btn.click(initialize_system, None, [status_box, system_status])
|
831 |
|
832 |
+
# Connect all sample question buttons to the message input
|
833 |
+
q1_btn.click(lambda: "What is Saudi Vision 2030?", None, msg)
|
834 |
+
q2_btn.click(lambda: "What are the economic goals of Vision 2030?", None, msg)
|
835 |
+
q3_btn.click(lambda: "How does Vision 2030 aim to improve quality of life?", None, msg)
|
836 |
+
q4_btn.click(lambda: "ما هي رؤية السعودية 2030؟", None, msg)
|
837 |
+
q5_btn.click(lambda: "ما هي الأهداف الاقتصادية لرؤية 2030؟", None, msg)
|
838 |
+
q6_btn.click(lambda: "كيف تعزز رؤية 2030 الإرث الثقافي السعودي؟", None, msg)
|
839 |
|
840 |
pdf_btn.click(check_pdfs, None, pdf_status)
|
841 |
sys_btn.click(check_dependencies, None, sys_status)
|