File size: 2,458 Bytes
a537907
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
034e43a
a537907
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
Main Application Entry Point
Multilingual Question Answering System with Gradio Interface
"""

import sys
from pathlib import Path

# Add project root to path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

from app.model_loader import ModelLoader
from app.inference import QAInference
from app.interface import create_interface


def main():
    """Main application entry point"""
    
    print("=" * 80)
    print("πŸš€ INITIALIZING MULTILINGUAL QA SYSTEM")
    print("=" * 80)
    
    # Configuration
    MODEL_PATH = "Praanshull/multilingual-qa-model"  # Change this to your model path
    
    # Load model
    print(f"\nπŸ“‚ Model path: {MODEL_PATH}")
    loader = ModelLoader(model_path=MODEL_PATH)
    
    try:
        model, tokenizer = loader.load()
    except Exception as e:
        print(f"\n❌ Failed to load model: {e}")
        print("\nπŸ’‘ Please ensure:")
        print(f"   1. Model exists at: {MODEL_PATH}")
        print("   2. All required files are present")
        print("   3. You have sufficient memory")
        return
    
    # Create inference engine
    print("\nπŸ”§ Initializing inference engine...")
    inference_engine = QAInference(
        model=model,
        tokenizer=tokenizer,
        device=loader.device
    )
    print("βœ… Inference engine ready")
    
    # Create interface
    print("\n🎨 Building Gradio interface...")
    demo = create_interface(inference_engine)
    print("βœ… Interface created")
    
    # Launch
    print("\n" + "=" * 80)
    print("πŸš€ LAUNCHING APPLICATION")
    print("=" * 80)

    # Custom CSS
    custom_css = """
    .gradio-container {
        font-family: 'Arial', sans-serif;
    }
    .header {
        text-align: center;
        padding: 20px;
        background: linear-gradient(90deg, #3498db, #e74c3c);
        color: white;
        border-radius: 10px;
        margin-bottom: 20px;
    }
    """
    
    demo.launch(
        server_name="0.0.0.0",  # Allow external access
        server_port=7860,        # Default Gradio port
        share=False,             # Set to True for public URL
        show_error=True,
        quiet=False,
        css=custom_css
    )
    
    print("\nβœ… Application launched successfully!")
    print("πŸ“± Access the interface at: http://localhost:7860")
    print("\nπŸ’‘ TIP: Set share=True in demo.launch() to get a public URL")
    print("=" * 80)


if __name__ == "__main__":
    main()