Spaces:
Sleeping
Medical AI Platform - Public Model Configuration
Overview
This Medical AI Platform is designed to work WITHOUT requiring HuggingFace authentication for most use cases. All core medical AI models used are public and freely available.
Model Access Strategy
Public Models (No Authentication Required)
The following models are public on HuggingFace and work without HF_TOKEN:
Bio_ClinicalBERT (
emilyalsentzer/Bio_ClinicalBERT)- Document type classification
- Clinical text understanding
- Public - No auth needed
BioGPT-Large (
microsoft/BioGPT-Large)- Clinical text generation
- Medical summarization
- Public - No auth needed
Biomedical NER (
d4data/biomedical-ner-all)- Named entity recognition
- Medical entity extraction
- Public - No auth needed
PubMedBERT (
microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext)- Medical text understanding
- General analysis
- Public - No auth needed
SciBERT (
allenai/scibert_scivocab_uncased)- Drug interaction detection
- Scientific text analysis
- Public - No auth needed
RoBERTa-SQuAD2 (
deepset/roberta-base-squad2)- Medical question answering
- Public - No auth needed
BigBird-Pegasus (
google/bigbird-pegasus-large-pubmed)- Clinical summarization
- Long document processing
- Public - No auth needed
When HF_TOKEN Is Needed
HF_TOKEN is ONLY required for:
- Gated models (e.g., some Google MedGemma models)
- Private organization models
- Models with specific access restrictions
For this platform: HF_TOKEN is OPTIONAL
Architecture Design
Robust Fallback System
1. Try loading public model WITHOUT authentication
β
2. If model requires auth AND HF_TOKEN available β Use token
β
3. If model fails β Use alternative public model
β
4. If all AI models fail β Fallback to keyword analysis
Error Handling
The system gracefully handles:
- Missing HF_TOKEN (uses public models)
- Network connectivity issues (cached models)
- Model download failures (alternative models)
- Authentication errors (informative logs)
Deployment Configuration
HuggingFace Spaces
No HF_TOKEN required in Space secrets
The platform will:
- Check if HF_TOKEN exists
- Log: "HF_TOKEN not configured - using public models"
- Load all public models successfully
- Provide full functionality
Environment Variables
Optional:
HF_TOKEN=hf_xxx # Only for gated models
Always Available:
TRANSFORMERS_CACHE=/app/.cache/huggingface
HF_HOME=/app/.cache/huggingface
PYTHONUNBUFFERED=1
TOKENIZERS_PARALLELISM=false
Code Implementation
Model Loader (model_loader.py)
# Get HF token from environment (optional - most models are public)
HF_TOKEN = os.getenv("HF_TOKEN", None)
if HF_TOKEN:
logger.info("HF_TOKEN found - will use for gated models if needed")
else:
logger.info("HF_TOKEN not found - using public models only (this is normal)")
Loading Strategy
def load_model(self, model_key: str):
# Try without token first (works for public models)
pipeline_kwargs = {
"task": task,
"model": model_id,
"device": device,
"trust_remote_code": True
}
# Only add token if it exists
if HF_TOKEN:
pipeline_kwargs["token"] = HF_TOKEN
model = pipeline(**pipeline_kwargs)
Error Messages
if "401" in error or "unauthorized" in error:
if not HF_TOKEN:
logger.error("Model requires auth but HF_TOKEN not available")
logger.error("Using public alternative")
else:
logger.error("Auth failed even with HF_TOKEN")
Testing Without HF_TOKEN
Steps:
- Deploy to HuggingFace Spaces without adding HF_TOKEN secret
- Platform starts successfully
- Logs show: "HF_TOKEN not configured - using public models"
- Upload medical PDF
- Bio_ClinicalBERT loads from public HuggingFace Hub
- Analysis completes successfully
- Results display AI classification
Expected Logs:
INFO - HF_TOKEN not configured - using public models (Bio_ClinicalBERT, BioGPT, etc.)
INFO - This is normal - most HuggingFace models are public
INFO - Model Loader initialized on device: cuda
INFO - Loading model: emilyalsentzer/Bio_ClinicalBERT for task: text-classification
INFO - Successfully loaded model: emilyalsentzer/Bio_ClinicalBERT
INFO - Document classified as: radiology (confidence: 0.89, method: ai_model)
Benefits of This Approach
- Reliability: No dependency on external secrets
- Simplicity: Works out-of-the-box without configuration
- Robustness: Handles token expiration gracefully
- Transparency: Clear logs about model availability
- Flexibility: Can still use HF_TOKEN for gated models if needed
Troubleshooting
If Models Don't Load
Issue: "Failed to load model"
Check:
- Is the model ID correct?
- Is the model public on HuggingFace?
- Does the model exist? (some may be renamed/moved)
- Network connectivity to huggingface.co?
Solution:
- All models used are verified public
- Platform will fallback to keyword analysis if models fail
- Check logs for specific error messages
If Authentication Errors Occur
Issue: "401 Unauthorized" or "Authentication required"
This means:
- Model is gated/private (not expected for our models)
- Model access changed to require auth
Solution:
- Replace with alternative public model
- Add HF_TOKEN if model is critical
- Use keyword fallback (already implemented)
Verified Public Models
All models have been verified as public on HuggingFace Hub:
- β Bio_ClinicalBERT - Public
- β BioGPT-Large - Public
- β biomedical-ner-all - Public
- β PubMedBERT - Public
- β SciBERT - Public
- β RoBERTa-SQuAD2 - Public
- β BigBird-Pegasus-PubMed - Public
Last verified: 2025-10-28
Conclusion
The Medical AI Platform does NOT require HF_TOKEN for normal operation.
All core functionality works with public HuggingFace models. The platform is designed to be robust, reliable, and work without external authentication dependencies.
Status: Production Ready
Authentication: Optional
Public Models: 7+ verified
Fallback System: Implemented