Spaces:
Sleeping
Sleeping
Upload gradio_interface.py
Browse files- src/gradio_interface.py +20 -5
src/gradio_interface.py
CHANGED
|
@@ -1,9 +1,23 @@
|
|
| 1 |
"""
|
| 2 |
Gradio Interface Module
|
| 3 |
Creates the main Gradio web interface for the RAG system
|
|
|
|
| 4 |
"""
|
| 5 |
import gradio as gr
|
| 6 |
from typing import Optional
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from .rag_query import RAGQueryEngine
|
| 8 |
from .question_generator import QuestionGenerator
|
| 9 |
from .knowledge_graph import KnowledgeGraphGenerator
|
|
@@ -45,27 +59,28 @@ class GradioInterfaceBuilder:
|
|
| 45 |
|
| 46 |
# Create tabs with proper order: Setup -> Ask Questions -> Knowledge Map -> Test -> Personalized Learning
|
| 47 |
# Ask Questions is set as default selected tab
|
|
|
|
| 48 |
with gr.Tabs(selected=1 if self.user_profiling else 0) as tabs:
|
| 49 |
# Tab 1: Setup (Cold Start/Onboarding) - only shown if user_profiling is available
|
| 50 |
if self.user_profiling:
|
| 51 |
-
with
|
| 52 |
self._create_onboarding_tab()
|
| 53 |
|
| 54 |
# Tab 2: Ask Questions (Default selected tab)
|
| 55 |
-
with
|
| 56 |
self._create_qa_tab()
|
| 57 |
|
| 58 |
# Tab 3: Knowledge Map
|
| 59 |
-
with
|
| 60 |
self._create_knowledge_map_tab()
|
| 61 |
|
| 62 |
# Tab 4: Test Your Knowledge
|
| 63 |
-
with
|
| 64 |
self._create_test_tab()
|
| 65 |
|
| 66 |
# Tab 5: Personalized Learning Path (if available)
|
| 67 |
if self.adaptive_engine:
|
| 68 |
-
with
|
| 69 |
self._create_learning_path_tab()
|
| 70 |
|
| 71 |
return demo
|
|
|
|
| 1 |
"""
|
| 2 |
Gradio Interface Module
|
| 3 |
Creates the main Gradio web interface for the RAG system
|
| 4 |
+
Compatible with Gradio 4.x and 6.x
|
| 5 |
"""
|
| 6 |
import gradio as gr
|
| 7 |
from typing import Optional
|
| 8 |
+
|
| 9 |
+
# Gradio 6.0 compatibility: TabItem was renamed to Tab
|
| 10 |
+
# Use Tab for Gradio 6.0, fallback to TabItem for older versions
|
| 11 |
+
try:
|
| 12 |
+
# Try to use Tab (Gradio 6.0+)
|
| 13 |
+
if hasattr(gr, 'Tab'):
|
| 14 |
+
Tab = gr.Tab
|
| 15 |
+
else:
|
| 16 |
+
# Fallback to TabItem (Gradio 4.x)
|
| 17 |
+
Tab = gr.TabItem
|
| 18 |
+
except AttributeError:
|
| 19 |
+
# If neither exists, use Tab (shouldn't happen)
|
| 20 |
+
Tab = gr.Tab if hasattr(gr, 'Tab') else gr.TabItem
|
| 21 |
from .rag_query import RAGQueryEngine
|
| 22 |
from .question_generator import QuestionGenerator
|
| 23 |
from .knowledge_graph import KnowledgeGraphGenerator
|
|
|
|
| 59 |
|
| 60 |
# Create tabs with proper order: Setup -> Ask Questions -> Knowledge Map -> Test -> Personalized Learning
|
| 61 |
# Ask Questions is set as default selected tab
|
| 62 |
+
# Gradio 6.0 compatibility: Use Tab (which is gr.Tab for 6.0, gr.TabItem for 4.x)
|
| 63 |
with gr.Tabs(selected=1 if self.user_profiling else 0) as tabs:
|
| 64 |
# Tab 1: Setup (Cold Start/Onboarding) - only shown if user_profiling is available
|
| 65 |
if self.user_profiling:
|
| 66 |
+
with Tab("Setup"):
|
| 67 |
self._create_onboarding_tab()
|
| 68 |
|
| 69 |
# Tab 2: Ask Questions (Default selected tab)
|
| 70 |
+
with Tab("Ask Questions"):
|
| 71 |
self._create_qa_tab()
|
| 72 |
|
| 73 |
# Tab 3: Knowledge Map
|
| 74 |
+
with Tab("Knowledge Map"):
|
| 75 |
self._create_knowledge_map_tab()
|
| 76 |
|
| 77 |
# Tab 4: Test Your Knowledge
|
| 78 |
+
with Tab("Test Your Knowledge"):
|
| 79 |
self._create_test_tab()
|
| 80 |
|
| 81 |
# Tab 5: Personalized Learning Path (if available)
|
| 82 |
if self.adaptive_engine:
|
| 83 |
+
with Tab("Personalized Learning"):
|
| 84 |
self._create_learning_path_tab()
|
| 85 |
|
| 86 |
return demo
|