Spaces:
Sleeping
Sleeping
""" | |
Initialize tab functionality for the Gradio app | |
""" | |
import gradio as gr | |
from utils.rag_system import DocumentIngestion, RAGSystem | |
def initialize_systems(global_vars): | |
"""Initialize the RAG systems""" | |
try: | |
print("π Initializing document ingestion system...") | |
global_vars['doc_ingestion'] = DocumentIngestion() | |
print("π Initializing RAG system...") | |
global_vars['rag_system'] = RAGSystem() | |
return "β Systems initialized successfully! You can now upload documents." | |
except Exception as e: | |
error_msg = f"β Error initializing systems: {str(e)}\n\n" | |
if "sentence-transformers" in str(e): | |
error_msg += """ | |
**Possible solutions:** | |
1. Install sentence-transformers: `pip install sentence-transformers` | |
2. Or provide OpenAI API key in environment variables | |
3. Check that PyTorch is properly installed | |
**For deployment:** | |
- Ensure requirements.txt includes: sentence-transformers, torch, transformers | |
""" | |
return error_msg | |
def create_initialize_tab(global_vars): | |
"""Create the Initialize System tab""" | |
with gr.Tab("π Initialize System", id="init"): | |
gr.Markdown(""" | |
### Step 1: Initialize the System | |
The AI models and embedding systems are initialized automatically. | |
This may take a few moments on first run as models are downloaded. | |
""") | |
# Automatically initialize systems and show status | |
init_status = gr.Textbox( | |
label="Initialization Status", | |
interactive=False, | |
lines=8, | |
value=initialize_systems(global_vars), # Call on load | |
placeholder="Initializing systems..." | |
) | |