Spaces:
Running
on
Zero
Running
on
Zero
File size: 2,860 Bytes
52b4ed7 0ae46fb abad335 e4c0a6a 52b4ed7 ffcfd50 52b4ed7 0ae46fb f89165d 8d74e9c d74506f f89165d 1c59c7e 52b4ed7 1c59c7e 5040e2f 1c59c7e 5040e2f fce8688 ffcfd50 fce8688 ffcfd50 c67b4e7 fce8688 1c59c7e 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 59 60 61 62 63 |
"""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__":
# Preload models on startup
logger.info("Preloading models on startup...")
logger.info("Initializing default medical model (MedSwin TA)...")
initialize_medical_model(DEFAULT_MEDICAL_MODEL)
logger.info("Preloading TTS model...")
try:
initialize_tts_model()
if config.global_tts_model is not None:
logger.info("TTS model preloaded successfully!")
else:
logger.warning("TTS model not available - will use MCP or disable voice generation")
except Exception as e:
logger.warning(f"TTS model preloading failed: {e}")
logger.warning("Text-to-speech will use MCP or be disabled")
# 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("Model preloading complete!")
demo = create_demo()
demo.launch()
|