Spaces:
Running
on
Zero
Running
on
Zero
File size: 2,759 Bytes
52b4ed7 0ae46fb abad335 e4c0a6a 52b4ed7 ffcfd50 52b4ed7 0ae46fb 63e92ef fce8688 ffcfd50 fce8688 ffcfd50 c67b4e7 fce8688 63e92ef 0ae46fb 52b4ed7 |
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 |
"""Main entry point for MedLLM Agent"""
import os
os.environ["TOKENIZERS_PARALLELISM"] = "false"
from logger import logger
from config import DEFAULT_MEDICAL_MODEL
import config
from models import initialize_medical_model, initialize_tts_model
from client import MCP_AVAILABLE
from ui import create_demo
if __name__ == "__main__":
# Note: Models are loaded on-demand when first needed (lazy loading)
# This avoids CUDA initialization in the main process, which is not allowed
# in ZeroGPU's stateless environment. Models will be loaded when stream_chat
# is called (which has the GPU decorator).
logger.info("App starting - models will be loaded on-demand when first needed")
logger.info(f"Default medical model: {DEFAULT_MEDICAL_MODEL}")
# TTS model also uses GPU decorator, so skip preloading
logger.info("TTS model will be loaded on-demand if needed")
# Check Gemini MCP availability
if MCP_AVAILABLE:
logger.info("✅ Gemini MCP SDK is available")
if config.GEMINI_API_KEY:
logger.info(f"✅ GEMINI_API_KEY is set: {config.GEMINI_API_KEY[:10]}...{config.GEMINI_API_KEY[-4:]}")
# Test MCP connection asynchronously (don't block startup)
try:
import asyncio
from client import test_mcp_connection
try:
loop = asyncio.get_event_loop()
if loop.is_running():
# If loop is running, schedule test in background
logger.info("ℹ️ Testing MCP connection in background...")
else:
# Test synchronously
result = loop.run_until_complete(test_mcp_connection())
if result:
logger.info("✅ MCP connection test passed - Gemini MCP is ready!")
else:
logger.warning("⚠️ MCP connection test failed - will use fallback methods")
except Exception as e:
logger.warning(f"Could not test MCP connection: {e}")
except Exception as e:
logger.debug(f"MCP connection test skipped: {e}")
else:
logger.warning("⚠️ GEMINI_API_KEY not set - Gemini MCP features will not work")
logger.warning(" Set it in Hugging Face Space secrets or environment variables")
else:
logger.info("ℹ️ Gemini MCP SDK not available - app will use fallback methods (direct API calls)")
logger.info(" This is normal and the app will continue to work. MCP is optional.")
logger.info("App initialization complete!")
demo = create_demo()
demo.launch()
|