CoolFace
Apppublic

gnumanth/MedGemma-Symptoms

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
12likes
App README

MedGemma Symptom Analyzer

A modern medical AI application using Google's MedGemma model via HuggingFace Inference API for symptom analysis and medical consultation.

๐Ÿฅ Features

  • โ€”AI-Powered Symptom Analysis: Uses Google's MedGemma-4B model for medical insights
  • โ€”Comprehensive Medical Reports: Provides differential diagnoses, next steps, and red flags
  • โ€”Interactive Web Interface: Built with Gradio for easy use
  • โ€”Demo Mode: Fallback functionality when API is unavailable
  • โ€”Medical Safety: Includes appropriate disclaimers and safety guidance

๐Ÿš€ Quick Start

1. Installation

bash
# Clone the repository
git clone <your-repo-url>
cd medgemma-symptomps

# Install dependencies
pip install -r requirements.txt

2. HuggingFace Access Setup

The app uses Google's MedGemma model, which requires special access:

  1. 1.Get HuggingFace Token:
  2. 2.Visit HuggingFace Settings
  3. 3.Create a new token with read permissions
  1. 1.Request MedGemma Access:
  2. 2.Visit google/medgemma-4b-it
  3. 3.Click "Request access to this model"
  4. 4.Wait for approval from Google (may take some time)
  1. 1.Set Environment Variable:
bash
   export HF_TOKEN="your_huggingface_token_here"

3. Run the Application

bash
python3 app.py

The app will start on http://localhost:7860 (or next available port).

๐Ÿ”ง Configuration

Environment Variables

  • โ€”HF_TOKEN: Your HuggingFace API token (required for model access)
  • โ€”FORCE_CPU: Set to true to force CPU usage (not needed for API version)

Model Access Status

The app handles different access scenarios:

  • โ€”โœ… Full Access: MedGemma model available via API
  • โ€”โš ๏ธ Pending Access: Waiting for model approval (uses demo mode)
  • โ€”โŒ No Access: Falls back to demo responses

๐Ÿงช Testing

Test the API connection:

bash
python3 test_api.py

This will verify:

  • โ€”HuggingFace API connectivity
  • โ€”Token validity
  • โ€”Model access permissions

๐Ÿ“‹ Usage

Web Interface

  1. 1.Open the app in your browser
  2. 2.Enter patient symptoms in the text area
  3. 3.Adjust creativity slider if desired
  4. 4.Click "Analyze Symptoms"
  5. 5.Review the comprehensive medical analysis

Example Symptoms

Try these example symptom descriptions:

  • โ€”Flu-like: "Fever, headache, body aches, and fatigue for 3 days"
  • โ€”Chest pain: "Sharp chest pain worsening with breathing, shortness of breath"
  • โ€”Digestive: "Abdominal pain, nausea, and diarrhea after eating"

๐Ÿ”’ Medical Disclaimer

โš ๏ธ IMPORTANT: This tool is for educational purposes only. It should never replace professional medical advice, diagnosis, or treatment. Always consult qualified healthcare professionals for medical concerns.

๐Ÿ—๏ธ Architecture

API-Based Design

The app now uses HuggingFace Inference API instead of local model loading:

  • โ€”Advantages:
  • โ€”No local GPU/CPU requirements
  • โ€”Faster startup time
  • โ€”Always up-to-date model
  • โ€”Reduced memory usage
  • โ€”Requirements:
  • โ€”Internet connection
  • โ€”Valid HuggingFace token
  • โ€”Model access approval

File Structure

medgemma-symptomps/
โ”œโ”€โ”€ app.py                    # Main Gradio application
โ”œโ”€โ”€ test_api.py              # API connection test script
โ”œโ”€โ”€ requirements.txt         # Python dependencies
โ”œโ”€โ”€ README.md               # This file
โ””โ”€โ”€ medgemma_app.log        # Application logs

๐Ÿ› ๏ธ Development

Key Components

  1. 1.MedGemmaSymptomAnalyzer: Main class handling API connections
  2. 2.Gradio Interface: Web UI with symptom input and analysis display
  3. 3.Demo Responses: Fallback functionality for offline use

API Integration

python
from huggingface_hub import InferenceClient

client = InferenceClient(token=hf_token)
response = client.text_generation(
    prompt=medical_prompt,
    model="google/medgemma-4b-it",
    max_new_tokens=400,
    temperature=0.7
)

๐Ÿ” Troubleshooting

Common Issues

  1. 1.404 Model Not Found:
  2. 2.Ensure you have requested access to MedGemma
  3. 3.Wait for Google's approval
  4. 4.Verify your HuggingFace token is valid
  1. 1.Demo Mode Only:
  2. 2.Check your internet connection
  3. 3.Verify HF_TOKEN environment variable
  4. 4.Confirm model access approval status
  1. 1.Slow Responses:
  2. 2.API responses may take 10-30 seconds
  3. 3.Consider adjusting max_tokens parameter

Getting Help

  • โ€”Check the application logs: tail -f medgemma_app.log
  • โ€”Test API connection: python3 test_api.py
  • โ€”Verify model access: Visit the HuggingFace model page

๐Ÿ“š Resources

๐Ÿ“„ License

This project uses the MedGemma model which has its own licensing terms. Please review the model license before use.


Remember: Always prioritize patient safety and consult healthcare professionals for medical decisions.