Spaces:
Sleeping
Sleeping
π MedeX - Deployment Instructions for Hugging Face Spaces
Prerequisites
- Hugging Face account
- Moonshot AI API Key (Get from: https://platform.moonshot.ai/)
Step-by-Step Deployment
1. Create a New Space
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Fill in the details:
- Space name:
medex-medical-ai(or your preferred name) - License: MIT
- Select SDK: Docker (IMPORTANT!)
- Space hardware: CPU Basic (free tier works fine)
- Visibility: Public or Private (your choice)
- Space name:
2. Configure Space Settings
After creating the Space:
- Go to Settings tab
- Under Repository secrets, add:
- Name:
KIMI_API_KEY - Value: Your Moonshot AI API key
- Click "Add new secret"
- Name:
3. Upload Files
You have two options:
Option A: Git Clone & Push (Recommended)
# Clone your Space repository
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
cd YOUR_SPACE_NAME
# Copy all MedeX files to the repository
# (Copy all files from MedeX-main folder)
# Stage and commit
git add .
git commit -m "Initial MedeX deployment"
# Push to HF Spaces
git push
Option B: Web Upload
- Go to Files tab in your Space
- Click "Add file" β "Upload files"
- Upload ALL files from MedeX-main folder:
streamlit_app.pyDockerfile.dockerignorerequirements.txtconfig.pyMEDEX_ULTIMATE_RAG.pymedical_knowledge_base.pymedical_rag_system.pypharmaceutical_database.pybanner.png.streamlit/config.tomlcore/folder (all files)rag_cache/folderREADME_HF.md(rename to README.md in the Space)
- Commit the changes
4. Update README.md Metadata
Make sure your Space's README.md starts with this metadata:
---
title: MedeX - Medical AI System
emoji: π₯
colorFrom: green
colorTo: blue
sdk: docker
app_port: 7860
pinned: false
license: mit
---
5. Wait for Build
- The Space will automatically start building
- Monitor the build logs in the "Logs" tab
- Build typically takes 3-5 minutes
- Once complete, the Space will automatically start
6. Verify Deployment
- Open your Space URL:
https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME - You should see the MedeX interface
- Test with a query: "ΒΏQuΓ© es la diabetes tipo 2?"
- Verify that responses are being generated
Troubleshooting
Build Fails
Issue: Docker build fails Solution:
- Check build logs for specific error
- Ensure all files were uploaded correctly
- Verify Dockerfile syntax
API Key Not Working
Issue: "Error initializing MedeX" or API errors Solution:
- Verify KIMI_API_KEY is set in Space secrets
- Check API key is valid on Moonshot AI platform
- Restart the Space
Space Not Starting
Issue: Space shows "Runtime Error" Solution:
- Check that port 7860 is specified in Dockerfile
- Verify streamlit_app.py exists
- Review application logs
Memory Issues
Issue: Out of memory errors Solution:
- Upgrade to better hardware in Space settings
- Consider CPU Upgrade or T4 GPU
File Structure Required
YOUR_SPACE/
βββ README.md (with metadata)
βββ Dockerfile
βββ .dockerignore
βββ requirements.txt
βββ streamlit_app.py
βββ config.py
βββ MEDEX_ULTIMATE_RAG.py
βββ medical_knowledge_base.py
βββ medical_rag_system.py
βββ pharmaceutical_database.py
βββ banner.png
βββ api_key.txt (optional, empty is fine)
βββ .streamlit/
β βββ config.toml
βββ core/
β βββ ai_engine.py
β βββ enhanced_ai_engine.py
β βββ pure_kimi_medex.py
β βββ real_kimi_client.py
βββ rag_cache/
βββ (empty or with rag_index.pkl)
Configuration Options
Environment Variables (Optional)
You can set these in Space settings:
KIMI_API_KEY: Your Moonshot AI API key (REQUIRED)MOONSHOT_BASE_URL: API base URL (default: https://api.moonshot.ai/v1)
Hardware Recommendations
- CPU Basic (Free): Good for testing and light usage
- CPU Upgrade: Better performance for multiple users
- T4 GPU: Recommended for production with high traffic
Post-Deployment
Test Functionality
- Patient Query: "Me duele el pecho y estoy preocupado"
- Professional Query: "Paciente 65 aΓ±os con dolor precordial"
- Emergency Query: "Dolor torΓ‘cico intenso, no puedo respirar"
- Educational Query: "ΒΏQuΓ© es la hipertensiΓ³n arterial?"
Monitor Performance
- Check "Logs" tab regularly
- Monitor response times
- Review error logs if issues occur
Share Your Space
- Share URL with colleagues
- Embed in your website using iframe
- Create duplicates for specific use cases
Support
For issues:
- Check Hugging Face Spaces documentation
- Review Moonshot AI API documentation
- Check build and application logs
- Contact support if needed
Security Notes
β οΈ IMPORTANT:
- Never commit API keys to git
- Use HF Spaces secrets for sensitive data
- Keep
.gitignoreupdated - Regularly rotate API keys
Updates
To update your deployed Space:
# Make changes locally
# Commit and push
git add .
git commit -m "Update description"
git push
The Space will automatically rebuild with your changes.
Quick Reference
| Action | Command/Location |
|---|---|
| View Space | https://huggingface.co/spaces/USERNAME/SPACENAME |
| Edit files | Files tab or git push |
| View logs | Logs tab |
| Settings | Settings tab |
| Restart | Settings β Restart Space |
Ready to deploy? Follow the steps above and your MedeX Space will be live in minutes! π