File size: 1,999 Bytes
9a01245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""

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

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    handlers=[logging.StreamHandler()],
)
logger = logging.getLogger(__name__)

# Add the current directory to Python path
current_dir = Path(__file__).resolve().parent
sys.path.append(str(current_dir))

# Pre-download models (important for Hugging Face Spaces)
try:
    logger.info("Pre-downloading models for caching...")
    from transformers import AutoModel, AutoModelForImageClassification, AutoTokenizer

    # Set cache directory (HF Spaces specific)
    os.environ["TRANSFORMERS_CACHE"] = os.path.join(os.getcwd(), "model_cache")
    os.makedirs(os.environ["TRANSFORMERS_CACHE"], exist_ok=True)

    # Medical vision model
    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)

    # Clinical BERT model
    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}")

# Import and run the MediSync application
from mediSync.app import create_interface

# Create and launch the interface
logger.info("Creating and launching the interface...")
interface = create_interface()

# For Hugging Face Spaces
if __name__ == "__main__":
    interface.launch()