File size: 1,883 Bytes
846f122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
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
        Click the button below to initialize the AI models and embedding systems.
        This may take a few moments on first run as models are downloaded.
        """)
        
        init_btn = gr.Button(
            "πŸš€ Initialize Systems", 
            variant="primary", 
            size="lg"
        )
        
        init_status = gr.Textbox(
            label="Initialization Status", 
            interactive=False, 
            lines=8,
            placeholder="Click 'Initialize Systems' to start..."
        )
        
        init_btn.click(
            lambda: initialize_systems(global_vars),
            outputs=init_status
        )