|
|
""" |
|
|
Main Application Entry Point |
|
|
Multilingual Question Answering System with Gradio Interface |
|
|
""" |
|
|
|
|
|
import sys |
|
|
from pathlib import 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) |
|
|
|
|
|
|
|
|
MODEL_PATH = "Praanshull/multilingual-qa-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 |
|
|
|
|
|
|
|
|
print("\nπ§ Initializing inference engine...") |
|
|
inference_engine = QAInference( |
|
|
model=model, |
|
|
tokenizer=tokenizer, |
|
|
device=loader.device |
|
|
) |
|
|
print("β
Inference engine ready") |
|
|
|
|
|
|
|
|
print("\nπ¨ Building Gradio interface...") |
|
|
demo = create_interface(inference_engine) |
|
|
print("β
Interface created") |
|
|
|
|
|
|
|
|
print("\n" + "=" * 80) |
|
|
print("π LAUNCHING APPLICATION") |
|
|
print("=" * 80) |
|
|
|
|
|
|
|
|
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", |
|
|
server_port=7860, |
|
|
share=False, |
|
|
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() |