Spaces:
Sleeping
Sleeping
Upload gradio_interface.py
Browse files- src/gradio_interface.py +31 -3
src/gradio_interface.py
CHANGED
|
@@ -426,7 +426,14 @@ class GradioInterfaceBuilder:
|
|
| 426 |
gr.Markdown("## π Test Your Understanding of Mercedes E-class ADAS")
|
| 427 |
gr.Markdown("Select a topic to test your knowledge with multiple-choice questions based on Bloom's taxonomy levels.")
|
| 428 |
|
| 429 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
|
| 431 |
with gr.Row():
|
| 432 |
test_questions = gr.State(None)
|
|
@@ -436,13 +443,34 @@ class GradioInterfaceBuilder:
|
|
| 436 |
|
| 437 |
topic_dropdown = gr.Dropdown(
|
| 438 |
label="Select a Topic",
|
| 439 |
-
choices=
|
| 440 |
-
value=
|
| 441 |
interactive=True
|
| 442 |
)
|
| 443 |
|
|
|
|
|
|
|
|
|
|
| 444 |
start_test_btn = gr.Button("Start Test", variant="primary")
|
| 445 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
# Progress indicator
|
| 447 |
with gr.Column(visible=False) as progress_container:
|
| 448 |
progress_html = gr.HTML()
|
|
|
|
| 426 |
gr.Markdown("## π Test Your Understanding of Mercedes E-class ADAS")
|
| 427 |
gr.Markdown("Select a topic to test your knowledge with multiple-choice questions based on Bloom's taxonomy levels.")
|
| 428 |
|
| 429 |
+
# Use default files instead of calling API during interface creation
|
| 430 |
+
# This avoids blocking during initialization
|
| 431 |
+
default_files = [
|
| 432 |
+
"Function of Active Distance Assist DISTRONIC.pdf",
|
| 433 |
+
"Function of Active Lane Change Assist.pdf",
|
| 434 |
+
"Function of Active Steering Assist.pdf",
|
| 435 |
+
"Function of Active Stop-and-Go Assist.pdf"
|
| 436 |
+
]
|
| 437 |
|
| 438 |
with gr.Row():
|
| 439 |
test_questions = gr.State(None)
|
|
|
|
| 443 |
|
| 444 |
topic_dropdown = gr.Dropdown(
|
| 445 |
label="Select a Topic",
|
| 446 |
+
choices=default_files,
|
| 447 |
+
value=default_files[0] if default_files else None,
|
| 448 |
interactive=True
|
| 449 |
)
|
| 450 |
|
| 451 |
+
# Add a button to refresh files from vector store (lazy loading)
|
| 452 |
+
refresh_files_btn = gr.Button("π Refresh Topic List", variant="secondary", size="sm")
|
| 453 |
+
|
| 454 |
start_test_btn = gr.Button("Start Test", variant="primary")
|
| 455 |
|
| 456 |
+
# Function to refresh files from vector store (called when button is clicked)
|
| 457 |
+
def refresh_topic_list():
|
| 458 |
+
try:
|
| 459 |
+
topic_files = self.rag_engine.get_files_from_vector_store()
|
| 460 |
+
if topic_files:
|
| 461 |
+
return gr.Dropdown.update(choices=topic_files, value=topic_files[0] if topic_files else None)
|
| 462 |
+
else:
|
| 463 |
+
return gr.Dropdown.update(choices=default_files, value=default_files[0] if default_files else None)
|
| 464 |
+
except Exception as e:
|
| 465 |
+
print(f"β οΈ Error refreshing files: {e}")
|
| 466 |
+
return gr.Dropdown.update(choices=default_files, value=default_files[0] if default_files else None)
|
| 467 |
+
|
| 468 |
+
refresh_files_btn.click(
|
| 469 |
+
fn=refresh_topic_list,
|
| 470 |
+
inputs=None,
|
| 471 |
+
outputs=topic_dropdown
|
| 472 |
+
)
|
| 473 |
+
|
| 474 |
# Progress indicator
|
| 475 |
with gr.Column(visible=False) as progress_container:
|
| 476 |
progress_html = gr.HTML()
|