This is a web application that allows users to upload food images for AI-powered calorie analysis. Built with Python Flask (serverless) backend and TypeScript frontend, optimized for Vercel deployment.
π Live Demo: https://calorie-counter-vercel-lrd4zgumb-shosseini811s-projects.vercel.app
- πΈ Upload food images for analysis
- π€ AI-powered calorie estimation using Google Gemini API
- π Food item identification
- β‘ Serverless backend deployment on Vercel
- π± Responsive web interface
calorie-counter-vercel/
βββ backend/
β βββ api/
β β βββ index.py # Vercel serverless function
β βββ app.py # Local development server
β βββ vercel_app.py # Alternative local server
β βββ requirements.txt # Python dependencies
β βββ .env.example # Environment variables template
β βββ .env # Your API key (local only)
βββ frontend/
β βββ index.html # Main HTML page
β βββ style.css # Styling
β βββ main.ts # TypeScript source
β βββ main.js # Compiled JavaScript (for deployment)
β βββ tsconfig.json # TypeScript configuration
βββ vercel.json # Vercel deployment configuration
βββ package.json # Node.js dependencies
βββ README.md # This file
- Google Gemini API Key (Get one here)
- Vercel account (Sign up here)
- Node.js (for TypeScript compilation)
-
Clone this repository
git clone <your-repo-url> cd calorie-counter-vercel
-
Install Vercel CLI
npm install -g vercel
-
Login to Vercel
vercel login
-
Deploy to Vercel
vercel --prod
-
Set Environment Variable
- Go to your Vercel Dashboard
- Select your deployed project
- Navigate to Settings β Environment Variables
- Add:
GEMINI_API_KEY
=your_actual_api_key
- Click Save
-
Redeploy (to apply environment variables)
vercel --prod
-
Navigate to backend directory
cd backend
-
Install Python dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env # Edit .env and add your GEMINI_API_KEY
-
Run local server
python app.py
Server runs on
http://localhost:5001
-
Compile TypeScript (if modified)
npx tsc frontend/main.ts --outDir frontend
-
Serve frontend (any HTTP server)
cd frontend python -m http.server 8080
Frontend available at
http://localhost:8080
- Frontend: Static HTML/CSS/JS served by Vercel
- Backend: Python Flask serverless function at
/api/upload
- AI: Google Gemini API for image analysis
- Deployment: Fully serverless on Vercel
POST /api/upload
- Upload and analyze food images
The frontend automatically detects the environment:
- Local: Calls
http://localhost:5001/upload
- Production: Calls
/api/upload
- πΈ Upload Image: Click "Choose File" and select a food image
- π Preview: Image preview appears automatically
- π Analyze: Click "Analyze Image" button
- β³ Wait: AI processes the image (few seconds)
- π Results: View calorie count and identified food items
{
"version": 2,
"builds": [
{
"src": "frontend/**/*",
"use": "@vercel/static"
},
{
"src": "backend/api/index.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/api/(.*)",
"dest": "backend/api/index.py"
},
{
"src": "/(.*)",
"dest": "frontend/$1"
}
]
}
GEMINI_API_KEY
: Your Google Gemini API key (required)
-
"GEMINI_API_KEY not found"
- Ensure environment variable is set in Vercel dashboard
- Redeploy after adding environment variables
-
"Failed to analyze image"
- Check if API key is valid
- Verify image format (JPEG, PNG supported)
- Check Vercel function logs
-
Frontend not loading
- Ensure
main.js
is compiled frommain.ts
- Check browser console for errors
- Ensure
- Go to Vercel Dashboard β Your Project β Functions tab
- Click on the function to view logs and errors
- β API key stored securely in Vercel environment variables
- β CORS enabled for cross-origin requests
- β No sensitive data exposed in frontend code
β οΈ Never commit.env
files to version control
- Frontend: HTML5, CSS3, TypeScript/JavaScript
- Backend: Python 3.9, Flask, Google Generative AI
- Deployment: Vercel (Serverless)
- AI: Google Gemini 2.5 Flash Preview
- Fork the repository
- Create a feature branch
- Make your changes
- Test locally and on Vercel
- Submit a pull request
MIT License - see LICENSE file for details
Made with β€οΈ for Vercel deployment