Skip to content

Avijit0001/MedAssist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MedAssist - AI-Powered Medical Consultation Platform

GitHub License Python React FastAPI

An intelligent healthcare assistant platform powered by LLM

Features β€’ Tech Stack β€’ Getting Started β€’ API Documentation β€’ Contributing


🎯 Overview

MedAssist is a full-stack medical consultation platform that leverages Google's Gemini AI to provide preliminary medical advice, symptom analysis, and AI-assisted medical image interpretation. Built with a modern React frontend and FastAPI backend, it offers a seamless experience for users seeking health information and medical insights.

⚠️ Disclaimer

This platform is designed for informational purposes only and should not replace professional medical advice, diagnosis, or treatment. Always consult with qualified healthcare professionals for proper medical care.


🌟 Features

Core Capabilities

  • πŸ’¬ Medical Consultations: Get preliminary medical advice through conversational AI interaction
  • πŸ” Symptom Analysis: Describe your symptoms and receive potential insights about your condition
  • πŸ“Έ Medical Image Analysis: Upload X-rays, CT scans, MRI, ultrasound, and blood test images for AI-assisted analysis
  • πŸ“‹ Patient Profiles: Track patient details including name, age, gender, and chief complaints
  • πŸ“„ PDF Report Generation: Generate professional medical reports and prescriptions with recommendations
  • πŸ”„ Conversation History: Maintain context across multiple consultations for better AI responses
  • ⚑ Real-time Responses: Fast, intelligent responses powered by Gemini 2.5 Flash model

πŸ› οΈ Tech Stack

Backend

  • Framework: FastAPI - Modern, fast web framework
  • Language: Python 3.8+
  • AI Models: Google Gemini 2.5 Flash (Chat & Vision)
  • PDF Generation: ReportLab
  • Image Processing: Pillow (PIL)
  • APIs: FastAPI with CORS middleware

Frontend

  • Library: React 19.1+
  • Build Tool: Vite 7.1+
  • Routing: React Router 7.9+
  • Markdown Rendering: React Markdown 10.1+
  • Styling: CSS3 with responsive design

Key Dependencies

  • google-genai: Google Gemini AI integration
  • python-dotenv: Environment variable management
  • reportlab: PDF generation
  • pillow: Image processing
  • cors: Cross-Origin Resource Sharing middleware

πŸ“‹ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Frontend (React + Vite)                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Home β€’ Chat Interface β€’ Patient Forms β€’ Reports    β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚ HTTP/REST
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Backend (FastAPI + Python)                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  β€’ Chat Endpoint (/api/chat)                        β”‚   β”‚
β”‚  β”‚  β€’ Report Generation (/api/generate-report)         β”‚   β”‚
β”‚  β”‚  β€’ X-ray Analysis (Gemini Vision)                   β”‚   β”‚
β”‚  β”‚  β€’ PDF Generation & Download                        β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚ Google Gemini  β”‚
         β”‚ AI (2.5 Flash) β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

Prerequisites

  • Python 3.8+ installed on your system
  • Node.js 16+ and npm for frontend development
  • Google Gemini API Key (Get it here)
  • Git for version control

Backend Setup

1. Clone the Repository

git clone https://github.com/yourusername/MedAssist.git
cd MedAssist/back

2. Create Virtual Environment

# Windows
python -m venv venv
venv\Scripts\activate

# macOS/Linux
python3 -m venv venv
source venv/bin/activate

3. Install Dependencies

pip install fastapi uvicorn google-genai python-dotenv pillow reportlab python-multipart

4. Configure Environment

Create a .env file in the back directory:

GEMINI_API_KEY=your_gemini_api_key_here

5. Start the Backend Server

uvicorn main:app --reload --host 127.0.0.1 --port 8000

The API will be available at http://127.0.0.1:8000

Interactive API Documentation: Visit http://127.0.0.1:8000/docs (Swagger UI)


Frontend Setup

1. Navigate to Frontend Directory

cd ../front

2. Install Dependencies

npm install

3. Start Development Server

npm run dev

The application will open at http://localhost:5173 (or specified port)

4. Build for Production

npm run build

πŸ“‘ API Documentation

Endpoints Overview

Method Endpoint Purpose
GET / Health check and API information
POST /api/chat Send messages and analyze medical images
POST /api/generate-report Generate professional PDF reports
GET /api/status System status check

POST /api/chat

Unified Chat Endpoint - Handle both text conversations and X-ray analysis

Request (Form Data):

{
  "message": "I have a persistent headache and fever",
  "conversation_history": "[{\"role\": \"user\", \"content\": \"...\"}, ...]",
  "xray_image": "<binary image file>"
}

Response:

{
  "response": "Based on your symptoms of headache and fever...",
  "xray_analysis": "The X-ray shows...",
  "timestamp": "2024-01-15T10:30:00.123456"
}

cURL Example:

curl -X POST "http://127.0.0.1:8000/api/chat" \
  -F "message=Analyze my X-ray image" \
  -F "conversation_history=[]" \
  -F "xray_image=@xray.jpg"

POST /api/generate-report

PDF Report Generation - Create professional medical reports

Request (JSON):

{
  "patient_name": "John Doe",
  "patient_age": 35,
  "patient_gender": "Male",
  "symptoms": "Chest pain, shortness of breath",
  "diagnosis": "Suspected acute coronary syndrome",
  "xray_analysis": "Chest X-ray shows normal cardiac silhouette",
  "medications": [
    "Aspirin 500mg - twice daily for 5 days",
    "Atorvastatin 20mg - once daily"
  ],
  "instructions": "Rest for 48 hours, avoid strenuous activity, follow-up with cardiologist"
}

Response:

  • Returns a PDF file for download with formatted medical report

GET /api/status

System Status Check - Verify API and model initialization

Response:

{
  "message": "Medical Chatbot API",
  "status": "running",
  "version": "1.0.0",
  "models": {
    "gemini_client_initialized": true,
    "vision_model": "gemini-2.5-flash",
    "chat_model": "gemini-2.5-flash"
  }
}

πŸ“ Project Structure

MedAssist/
β”œβ”€β”€ back/                          # Backend (FastAPI)
β”‚   β”œβ”€β”€ main.py                   # Main API application
β”‚   β”œβ”€β”€ requirements.txt           # Python dependencies
β”‚   └── .env                       # Environment variables (create this)
β”‚
β”œβ”€β”€ front/                         # Frontend (React + Vite)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/           # Reusable React components
β”‚   β”‚   β”‚   β”œβ”€β”€ ChatInterface.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ChatWindow.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ MessageInput.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Navbar.jsx
β”‚   β”‚   β”‚   └── PatientList.jsx
β”‚   β”‚   β”œβ”€β”€ pages/                # Page components
β”‚   β”‚   β”‚   β”œβ”€β”€ Home.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Chat.jsx
β”‚   β”‚   β”‚   └── About.jsx
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   β”œβ”€β”€ main.jsx
β”‚   β”‚   └── index.css
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ vite.config.js
β”‚   └── index.html
β”‚
└── README.md                      # This file

🎨 User Interface

Home Page

  • Hero section with welcome message
  • Feature cards highlighting capabilities
  • Quick-start button to begin consultations

Chat Interface

  • Patient information form (name, age, gender, symptoms)
  • Real-time message display
  • File upload for medical images
  • Report type selection dropdown
  • PDF report generation

Component Hierarchy

App
β”œβ”€β”€ Home
β”œβ”€β”€ Chat
β”‚   └── ChatInterface
β”‚       β”œβ”€β”€ ChatWindow
β”‚       └── MessageInput
β”œβ”€β”€ About
└── Navbar

πŸ” Security Considerations

Current Implementation

  • CORS is enabled for all origins (*)
  • Environment variables for API keys
  • Input validation for file uploads

Production Recommendations

  • πŸ”’ Restrict CORS to specific frontend domain
  • πŸ” Implement authentication and authorization
  • πŸ›‘οΈ Add rate limiting to API endpoints
  • πŸ“ Validate all user inputs on backend
  • πŸ”‘ Rotate API keys regularly
  • πŸ“Š Implement logging and monitoring

Important Notes

  • Never commit .env files to version control
  • Store sensitive API keys securely
  • Use HTTPS in production
  • Implement HIPAA compliance if handling real patient data

🚦 Getting Help

Common Issues

Backend won't start

# Clear cache and reinstall
rm -r venv
python -m venv venv
pip install -r requirements.txt

API connection errors

  • Verify backend is running: http://127.0.0.1:8000/docs
  • Check vite proxy configuration in vite.config.js
  • Ensure CORS middleware is properly configured

Gemini API errors

  • Verify API key is correct in .env
  • Check API key has proper permissions
  • Ensure API is enabled in Google Cloud Console

πŸ“š Additional Resources


🀝 Contributing

Contributions are welcome! Here's how to help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 for Python code
  • Use React functional components with hooks
  • Include comments for complex logic
  • Test changes before submitting PR
  • Update documentation as needed

⚠️ Medical Disclaimer

MedAssist is NOT a substitute for professional medical advice. This platform:

  • Provides general information only
  • Should not be used for diagnosis or treatment decisions
  • Cannot replace consultation with licensed healthcare providers
  • Is designed for educational purposes

Always consult with qualified healthcare professionals for proper medical evaluation and treatment.


πŸ‘¨β€πŸ’» About

MedAssist is an AI-powered medical consultation assistant that demonstrates the capabilities of modern AI in healthcare informatics. Built with modern web technologies and powered by Google's Gemini AI.


⬆ Back to Top

Made with ❀️ By Avijit0001

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors