|
"""
|
|
MediSync: Multi-Modal Medical Analysis System - Hugging Face Spaces Entry Point
|
|
==============================================================================
|
|
This is the main entry point for the Hugging Face Space deployment.
|
|
"""
|
|
|
|
import logging
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
handlers=[logging.StreamHandler()],
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
current_dir = Path(__file__).resolve().parent
|
|
sys.path.append(str(current_dir))
|
|
|
|
|
|
try:
|
|
logger.info("Pre-downloading models for caching...")
|
|
from transformers import AutoModel, AutoModelForImageClassification, AutoTokenizer
|
|
|
|
|
|
os.environ["TRANSFORMERS_CACHE"] = os.path.join(os.getcwd(), "model_cache")
|
|
os.makedirs(os.environ["TRANSFORMERS_CACHE"], exist_ok=True)
|
|
|
|
|
|
vision_model_name = "facebook/deit-base-patch16-224-medical-cxr"
|
|
logger.info(f"Downloading vision model: {vision_model_name}")
|
|
AutoModelForImageClassification.from_pretrained(vision_model_name)
|
|
|
|
|
|
text_model_name = "medicalai/ClinicalBERT"
|
|
logger.info(f"Downloading text model: {text_model_name}")
|
|
AutoModel.from_pretrained(text_model_name)
|
|
AutoTokenizer.from_pretrained(text_model_name)
|
|
|
|
logger.info("All models downloaded and cached successfully!")
|
|
except Exception as e:
|
|
logger.warning(f"Warning: Could not pre-download models: {e}")
|
|
|
|
|
|
from mediSync.app import create_interface
|
|
|
|
|
|
logger.info("Creating and launching the interface...")
|
|
interface = create_interface()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
interface.launch()
|
|
|