A full-stack application that extracts text from medication or supplement images, supports downstream AI analysis, and can find nearby specialists using Google Maps.
HootHacks_Project/
├── backend/
│ ├── app.py # Flask backend with OCR integration
│ ├── requirements.txt # Python dependencies
│ ├── .env.example # Environment variables template
│ └── uploads/ # Directory for storing uploaded images
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ │ ├── ImageUploader.jsx # Main image upload component
│ │ │ └── ImageUploader.css # Styling for uploader
│ │ ├── App.jsx # Main App component
│ │ ├── App.css # App styling
│ │ ├── index.jsx # React entry point
│ │ └── index.css # Global styles
│ ├── public/
│ │ └── index.html # HTML template
│ ├── package.json # Frontend dependencies
│ └── .env # Frontend environment variables
└── README.md # This file
- Drag-and-drop interface for easy image uploading
- File preview before processing
- Supported formats: PNG, JPG, JPEG, GIF, BMP
- File size limit: 16MB
- Primary engine order:
- EasyOCR when installed
- PaddleOCR when installed
- Tesseract fallback
- Image preprocessing:
- Denoising to reduce glare effects
- Contrast enhancement using CLAHE
- Works on:
- prescription labels
- supplement facts panels
- photographed bottle / package text
- Full extracted text from prescription bottle
- Confidence scores for each detected text block
- Structured results with bounding boxes
- Average confidence display for quality assessment
- Copy to clipboard functionality
- POST /api/upload - Upload image and get OCR results
- POST /api/ocr - Process OCR on existing image
- POST /api/find-specialists - Find up to 5 nearby specialists / pharmacies
- GET /health - Health check endpoint
- Python 3.8 or higher
- Node.js 16 or higher
- npm or yarn package manager
Create the root .env file if it does not already exist:
cp backend/.env.example .envThen fill in the API keys you actually want to use:
PUBMED_API_KEY=your_pubmed_key
OPENAI_API_KEY=your_openai_key
GOOGLE_MAPS_API_KEY=your_google_maps_keyThe backend now loads the project root .env automatically.
source backend/.venv312/bin/activate
PORT=5001 python backend/app.pyThe backend will run at http://localhost:5001
cd frontend
npm install
npm startThe frontend will run at http://localhost:3000
- Open the application in your browser at
http://localhost:3000 - Upload an image of a prescription bottle by:
- Clicking the drop zone to select a file, or
- Dragging and dropping an image onto the drop zone
- Click "Extract Text from Image" to process the image
- View results including:
- Extracted text from the bottle label
- Confidence score of the OCR detection
- Copy button to copy extracted text
- Click "Find Specialists In This Area" after OCR completes
- Enter city and country and search up to 5 nearby specialists / pharmacies
- Click a result to preview its location on the embedded map
source backend/.venv312/bin/activate
PORT=5001 python backend/app.pycd frontend
npm startsource backend/.venv312/bin/activate
python -m unittest discover -s backend/tests -vsource backend/.venv312/bin/activate
python -m unittest backend.tests.test_specialist_service backend.tests.test_routes -vcd frontend
npm run buildcurl http://localhost:5001/healthcurl -F "file=@tests/IMG_7027.webp" http://localhost:5001/api/uploadcurl -X POST http://localhost:5001/api/find-specialists \
-H "Content-Type: application/json" \
-d '{
"medication_name": "Metformin for diabetes",
"user_location": {
"city": "Boston",
"country": "United States"
},
"radius": 5000
}'Upload an image and get OCR results
Request:
Content-Type: multipart/form-data
Body: {
"file": <binary image data>
}
Response (Success):
{
"status": "success",
"message": "Image processed successfully",
"file_id": "20240418_120530_abc123.jpg",
"upload_time": "2024-04-18T12:05:30.123456",
"ocr_data": {
"status": "success",
"full_text": "Aspirin 500mg...",
"structured_results": [
{
"text": "Aspirin",
"confidence": 0.98,
"bbox": [[x1, y1], [x2, y2], ...]
}
],
"text_count": 15,
"average_confidence": 0.95
}
}Response (Error):
{
"status": "error",
"message": "Error description"
}- Image Processing Time: 2-5 seconds depending on image quality
- Model Memory: ~250MB RAM
- Optimal Image Size: 1080x1920px to 2160x3840px
- Recommended Lighting: Well-lit environment, minimize glare on bottle
After image upload and OCR:
- Research Agent → Pass extracted text to PubMed API for ingredient / side-effect research
- Analysis Agent → Use OpenAI API for extraction, normalization, and summarization
- Specialist Finder → Use Google Maps API to locate local specialists
FLASK_ENV=development
FLASK_DEBUG=True
MAX_FILE_SIZE=16777216
OCR_USE_GPU=False
OCR_LANGUAGE=en
API_PORT=5001
API_HOST=0.0.0.0
PUBMED_API_KEY=your_pubmed_key
OPENAI_API_KEY=your_openai_key
GOOGLE_MAPS_API_KEY=your_google_maps_key
CORS_ORIGINS=["http://localhost:3000", "http://localhost:5001"]
REACT_APP_API_URL=http://localhost:5001
- Ensure
CORS_ORIGINSin backend .env includes frontend URL - Flask-CORS should handle this automatically
- Ensure
GOOGLE_MAPS_API_KEYis present in the root.env - The frontend sends
city+country; the backend geocodes them before nearby search - Results are limited to 5 entries
- Large or complex images may take longer
- Try reducing image dimensions
- Ensure backend has sufficient resources
- Flask - Web framework
- EasyOCR / PaddleOCR / Tesseract - OCR engines
- OpenCV - Image processing
- Pillow - Image handling
- Flask-CORS - CORS handling
- Google Maps Places + Geocoding APIs - Specialist lookup
- React 18.2.0 - UI framework
- CSS3 - Styling with animations
- Fetch API - HTTP requests
backend/app.py
├── Flask app initialization
├── OCR model initialization (PaddleOCR)
├── Image preprocessing pipeline
├── API routes:
│ ├── /health - Health check
│ ├── /api/upload - Main upload endpoint
│ ├── /api/ocr - Process stored image
│ └── /api/text-extraction - Combined upload + OCR
└── Error handlers
frontend/src/components/ImageUploader.jsx
├── React component with hooks
├── File upload handling
├── Drag-and-drop functionality
├── API integration
├── Results display
└── Accessibility features
- GPU acceleration support for faster processing
- Multi-language OCR support
- Batch image processing
- Image quality feedback
- OCR result editing interface
- Database integration for history
- Authentication and user accounts
- Integration with PubMed research API
- Integration with Google Maps API for specialist finder
- Mobile app version
MIT License - Feel free to use this project for educational and commercial purposes
For issues or questions, please check:
- Backend logs in terminal
- Browser console for frontend errors
- OCR model initialization logs