arnnv/xray-classification
0
MediSync Backend
This is the backend service for MediSync, providing API endpoints for medical image analysis and report generation using AI models.
Prerequisites
- Python 3.10 or higher
- pip (Python package manager)
- Docker (optional, for containerized deployment)
Project Structure
backend/
├── api.py # Main API endpoints
├── app.py # FastAPI application setup
├── predict.py # Prediction logic
├── langgraph_agent.py # LangGraph agent implementation
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── weights/ # Directory for model weights
└── .env # Environment variablesSetup Instructions
1. Local Development Setup
- Create and activate a virtual environment (recommended):
python -m venv venv
# On Windows
.\venv\Scripts\activate
# On Unix or MacOS
source venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
- Create a
.envfile in the backend directory - Add required environment variables:
GOOGLE_API_KEY=your_google_api_key_here- Download model weights:
- Create a
weightsdirectory in the backend folder - Download the required model weights and place them in the
weightsdirectory
- Run the development server:
python app.py The server will start on http://localhost:7860
2. Docker Setup
- Build the Docker image:
docker build -t medisync-backend .- Run the container:
docker run -p 7860:7860 --env-file .env medisync-backendAPI Endpoints
The backend provides the following main endpoints:
POST /predict: Upload and analyze medical imagesPOST /generate-report: Generate medical reports based on analysis- Additional endpoints are documented in
api.py
Dependencies
Key dependencies include:
- TensorFlow (2.10.x)
- LangChain & LangGraph for AI processing
- FastAPI for API endpoints
- Google Generative AI for report generation
- Additional dependencies listed in
requirements.txt
Environment Variables
Required environment variables:
GOOGLE_API_KEY: API key for Google's Generative AI services
Development Guidelines
- Code Structure:
api.py: Contains all API endpoint definitionspredict.py: Handles image processing and model predictionslanggraph_agent.py: Implements the LangGraph agent for report generation
- Adding New Features:
- Add new endpoints in
api.py - Implement corresponding logic in appropriate modules
- Update requirements.txt if new dependencies are added
Troubleshooting
Common issues and solutions:
- Model weights not found:
- Ensure model weights are properly placed in the
weightsdirectory - Check file permissions
- API key issues:
- Verify
.envfile exists and contains valid API key - Check environment variable loading in application
- Dependencies issues:
- Try removing the virtual environment and recreating it
- Update pip:
pip install --upgrade pip - Install dependencies one by one if bulk installation fails
