File size: 1,735 Bytes
d41f2a9 0bf764e c86c516 d41f2a9 7519ca8 a26146b d41f2a9 51cd0b6 d41f2a9 2e2f40a d41f2a9 2e2f40a d41f2a9 2e2f40a d41f2a9 58c4751 d41f2a9 31a4523 d41f2a9 2e2f40a d41f2a9 31a4523 d41f2a9 31a4523 d41f2a9 0e061fe a26146b d41f2a9 a26146b 0bf764e d41f2a9 | 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 | """
Main application file for ELAN-Bot.
"""
import os
import sys
import warnings
# Set environment variable for CPU-only torch
os.environ["CUDA_VISIBLE_DEVICES"] = ""
# Suppress warnings for cleaner startup
warnings.filterwarnings("ignore", category=UserWarning)
warnings.filterwarnings("ignore", category=FutureWarning)
from services import ElanAssistant
from ui import GradioInterface
class ElanBotApp:
"""Main application class for ELAN-Bot."""
def __init__(self):
"""Initialize the ELAN-Bot application."""
self.assistant = ElanAssistant()
self.interface = GradioInterface(self.chat_handler)
def chat_handler(self, message: str, history) -> str:
"""
Handle chat messages from Gradio interface.
Args:
message: User's input message
history: Chat history (unused but required by Gradio)
Returns:
str: Assistant's response
"""
try:
return self.assistant.process_message(message)
except Exception as e:
print(f"Error in chat handler: {e}")
return "I'm sorry, an error occurred while processing your request."
def launch(self, share: bool = False, **kwargs):
"""
Launch the application.
Args:
share: Whether to create a public link (False for HF Spaces)
**kwargs: Additional arguments for Gradio launch
"""
# For Hugging Face Spaces, we don't need share=True
self.interface.launch(share=share, **kwargs)
def main():
"""Main entry point for the application."""
app = ElanBotApp()
app.launch()
if __name__ == "__main__":
main() |