Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,12 +1,27 @@
|
|
| 1 |
"""Gradio Web Interface for Unified RAG System"""
|
| 2 |
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
import time
|
| 6 |
import json
|
| 7 |
from datetime import datetime
|
| 8 |
from typing import Dict, List, Tuple
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
print("Initializing RAG System...")
|
| 12 |
rag_system = UnifiedRAGSystem()
|
|
@@ -157,14 +172,23 @@ def get_example_queries() -> List[str]:
|
|
| 157 |
|
| 158 |
|
| 159 |
def create_interface():
|
| 160 |
-
"""Create the Gradio web interface"""
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
|
| 164 |
primary_hue="blue",
|
| 165 |
secondary_hue="gray",
|
| 166 |
neutral_hue="gray"
|
| 167 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
css="""
|
| 169 |
.gradio-container {
|
| 170 |
max-width: 1200px !important;
|
|
@@ -172,7 +196,7 @@ def create_interface():
|
|
| 172 |
.output-box {
|
| 173 |
min-height: 200px;
|
| 174 |
}
|
| 175 |
-
"""
|
| 176 |
) as app:
|
| 177 |
|
| 178 |
# Header
|
|
@@ -326,20 +350,40 @@ def create_interface():
|
|
| 326 |
if __name__ == "__main__":
|
| 327 |
print("\n" + "="*60)
|
| 328 |
print("Starting RAG System Web Interface")
|
|
|
|
| 329 |
print("="*60)
|
| 330 |
|
| 331 |
# Create and launch the interface
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""Gradio Web Interface for Unified RAG System"""
|
| 2 |
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
import time
|
| 6 |
import json
|
| 7 |
from datetime import datetime
|
| 8 |
from typing import Dict, List, Tuple
|
| 9 |
+
|
| 10 |
+
# Handle Python 3.13 compatibility issues with gradio/pydub
|
| 11 |
+
try:
|
| 12 |
+
import gradio as gr
|
| 13 |
+
except ImportError as e:
|
| 14 |
+
print(f"Initial Gradio import failed: {e}")
|
| 15 |
+
# Try with minimal configuration
|
| 16 |
+
try:
|
| 17 |
+
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
| 18 |
+
import gradio as gr
|
| 19 |
+
print("Successfully imported Gradio with analytics disabled")
|
| 20 |
+
except Exception as final_error:
|
| 21 |
+
print(f"Final Gradio import attempt failed: {final_error}")
|
| 22 |
+
raise ImportError("Could not import Gradio. Please check your Python version and dependencies.")
|
| 23 |
+
|
| 24 |
+
from unified_rag_system import UnifiedRAGSystem
|
| 25 |
|
| 26 |
print("Initializing RAG System...")
|
| 27 |
rag_system = UnifiedRAGSystem()
|
|
|
|
| 172 |
|
| 173 |
|
| 174 |
def create_interface():
|
| 175 |
+
"""Create the Gradio web interface with Python 3.13 compatibility"""
|
| 176 |
+
|
| 177 |
+
# Use a simple theme to avoid complex dependencies
|
| 178 |
+
theme = None
|
| 179 |
+
try:
|
| 180 |
+
theme = gr.themes.Soft(
|
| 181 |
primary_hue="blue",
|
| 182 |
secondary_hue="gray",
|
| 183 |
neutral_hue="gray"
|
| 184 |
+
)
|
| 185 |
+
except Exception as e:
|
| 186 |
+
print(f"Could not load custom theme, using default: {e}")
|
| 187 |
+
theme = gr.themes.Default()
|
| 188 |
+
|
| 189 |
+
with gr.Blocks(
|
| 190 |
+
title="RAG System - Technical Manual Assistant",
|
| 191 |
+
theme=theme,
|
| 192 |
css="""
|
| 193 |
.gradio-container {
|
| 194 |
max-width: 1200px !important;
|
|
|
|
| 196 |
.output-box {
|
| 197 |
min-height: 200px;
|
| 198 |
}
|
| 199 |
+
""" if theme else None
|
| 200 |
) as app:
|
| 201 |
|
| 202 |
# Header
|
|
|
|
| 350 |
if __name__ == "__main__":
|
| 351 |
print("\n" + "="*60)
|
| 352 |
print("Starting RAG System Web Interface")
|
| 353 |
+
print(f"Python version: {sys.version}")
|
| 354 |
print("="*60)
|
| 355 |
|
| 356 |
# Create and launch the interface
|
| 357 |
+
try:
|
| 358 |
+
app = create_interface()
|
| 359 |
+
|
| 360 |
+
print("\nLaunching Gradio interface...")
|
| 361 |
+
print("The web interface will open in your browser.")
|
| 362 |
+
print("Press Ctrl+C to stop the server.\n")
|
| 363 |
+
|
| 364 |
+
# Launch with error handling
|
| 365 |
+
app.launch(
|
| 366 |
+
server_name="0.0.0.0", # Allow external access
|
| 367 |
+
server_port=7860, # Default Gradio port
|
| 368 |
+
share=False, # Set to True to create a public link
|
| 369 |
+
show_error=True,
|
| 370 |
+
quiet=False,
|
| 371 |
+
show_tips=False, # Reduce console output
|
| 372 |
+
enable_queue=True # Enable request queuing
|
| 373 |
+
)
|
| 374 |
+
except Exception as e:
|
| 375 |
+
print(f"❌ Failed to launch Gradio interface: {e}")
|
| 376 |
+
print("\nTrying fallback launch configuration...")
|
| 377 |
+
try:
|
| 378 |
+
# Fallback launch with minimal configuration
|
| 379 |
+
app = create_interface()
|
| 380 |
+
app.launch(
|
| 381 |
+
server_name="0.0.0.0",
|
| 382 |
+
server_port=7860,
|
| 383 |
+
share=False,
|
| 384 |
+
quiet=True
|
| 385 |
+
)
|
| 386 |
+
except Exception as fallback_error:
|
| 387 |
+
print(f"❌ Fallback launch also failed: {fallback_error}")
|
| 388 |
+
print("Please check your Python environment and dependencies.")
|
| 389 |
+
sys.exit(1)
|