"""Configuration constants and global storage""" import os import threading # Model configurations MEDSWIN_MODELS = { "MedSwin DT": "MedSwin/MedSwin-Merged-DaRE-TIES-KD-0.7", "MedSwin Nsl": "MedSwin/MedSwin-Merged-NuSLERP-KD-0.7", "MedSwin DL": "MedSwin/MedSwin-Merged-DaRE-Linear-KD-0.7", "MedSwin Ti": "MedSwin/MedSwin-Merged-TIES-KD-0.7", "MedSwin TA": "MedSwin/MedSwin-Merged-TA-SFT-0.7", "MedSwin SFT": "MedSwin/MedSwin-7B-SFT", "MedSwin KD": "MedSwin/MedSwin-7B-KD", } DEFAULT_MEDICAL_MODEL = "MedSwin DT" EMBEDDING_MODEL = "abhinand/MedEmbed-large-v0.1" TTS_MODEL = "maya-research/maya1" HF_TOKEN = os.environ.get("HF_TOKEN") if not HF_TOKEN: raise ValueError("HF_TOKEN not found in environment variables") # Gemini MCP configuration GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY") GEMINI_MODEL = os.environ.get("GEMINI_MODEL", "gemini-2.5-flash") GEMINI_MODEL_LITE = os.environ.get("GEMINI_MODEL_LITE", "gemini-2.5-flash-lite") USE_API = os.environ.get("USE_API", "false").lower() == "true" # MCP server configuration script_dir = os.path.dirname(os.path.abspath(__file__)) agent_path = os.path.join(script_dir, "agent.py") MCP_SERVER_COMMAND = os.environ.get("MCP_SERVER_COMMAND", "python") MCP_SERVER_ARGS = os.environ.get("MCP_SERVER_ARGS", agent_path).split() if os.environ.get("MCP_SERVER_ARGS") else [agent_path] MCP_TOOLS_CACHE_TTL = int(os.environ.get("MCP_TOOLS_CACHE_TTL", "60")) # Global model storage global_medical_models = {} global_medical_tokenizers = {} global_file_info = {} global_tts_model = None global_whisper_model = None global_embed_model = None # MCP client storage global_mcp_session = None global_mcp_stdio_ctx = None global_mcp_lock = threading.Lock() global_mcp_tools_cache = {"timestamp": 0.0, "tools": None} # UI constants TITLE = "

🩺 MedLLM Agent - Medical RAG & Web Search System

" DESCRIPTION = """

Advanced Medical AI Assistant powered by MedSwin models

📄 Document RAG: Answer based on uploaded medical documents

🌐 Web Search: Fetch knowledge from reliable online medical resources

🌍 Multi-language: Automatic translation for non-English queries

Tips: Customise configurations & system prompt to see the magic!

Note: Case GPU aborted or MedSwin not ready, please try another model!

""" CSS = """ .upload-section { max-width: 400px; margin: 0 auto; padding: 10px; border: 2px dashed #ccc; border-radius: 10px; } .upload-button { background: #34c759 !important; color: white !important; border-radius: 25px !important; } .chatbot-container { margin-top: 20px; } .status-output { margin-top: 10px; font-size: 14px; } .processing-info { margin-top: 5px; font-size: 12px; color: #666; } .info-container { margin-top: 10px; padding: 10px; border-radius: 5px; } .file-list { margin-top: 0; max-height: 200px; overflow-y: auto; padding: 5px; border: 1px solid #eee; border-radius: 5px; } .stats-box { margin-top: 10px; padding: 10px; border-radius: 5px; font-size: 12px; } .submit-btn { background: #1a73e8 !important; color: white !important; border-radius: 25px !important; margin-left: 10px; padding: 5px 10px; font-size: 16px; } .input-row { display: flex; align-items: center; } .recording-timer { font-size: 12px; color: #666; text-align: center; margin-top: 5px; } .feature-badge { display: inline-block; padding: 3px 8px; margin: 2px; border-radius: 12px; font-size: 11px; font-weight: bold; } .badge-rag { background: #e3f2fd; color: #1976d2; } .badge-web { background: #f3e5f5; color: #7b1fa2; } .model-status { margin-top: 5px; padding: 8px; border-radius: 5px; font-size: 13px; font-weight: 500; background-color: #f5f5f5; border: 1px solid #e0e0e0; overflow-y: auto; max-height: 120px; } @media (min-width: 768px) { .main-container { display: flex; justify-content: space-between; gap: 20px; } .upload-section { flex: 1; max-width: 300px; } .chatbot-container { flex: 2; margin-top: 0; } } """