A web application that analyzes products through images using Google's Gemini AI to provide sustainability insights, disposal recommendations, and eco-friendly alternatives.
β¨ Real-time Product Analysis
- Take photos using your webcam
- Upload existing product images
- Get instant AI-powered sustainability assessments
π Comprehensive Sustainability Report
- Sustainability score (0-10)
- Detailed breakdown: Packaging, Production, Company Ethics, Lifecycle Impact
- Pros and cons of the current product
- 3 eco-friendly alternative recommendations, with up-to-date pricing and brands
- Actionable tips for recycling, reducing impact, and making better choices
π¨ User-Friendly Interface
- Clean, green-themed design
- Progress bar visualization of sustainability scores
- Real-time preview of selected images
- Both camera and file upload options
Frontend:
- HTML5 / CSS3
- Vanilla JavaScript
- W3.CSS framework for styling
- Camera API (getUserMedia)
Backend:
- Node.js
- Express.js
- Google GenAI SDK (Gemini 2.5 Flash)
- SerpAPI (Google Shopping data)
- dotenv for environment variables
- Node.js (v16 or higher)
- npm
- Google Gemini API Key
- SerpAPI Key (for alternative product pricing)
- Clone the repository
git clone <repo-url>
cd new- Install dependencies
npm i- Configure environment variables
Create a
.envfile in the root directory:
PORT=3000
GEMINI_API_KEY=your_google_gemini_api_key_here
SERPAPI_KEY=your_serpapi_key_here
Get your API keys from:
- Gemini: Google AI Studio
- SerpAPI: SerpAPI Dashboard
- Start the development server
npm run devServer will run at http://localhost:3000
- Open the app in your browser at
http://localhost:3000 - Choose input method:
- Click "Start Camera" to take a photo with your webcam
- Click "Upload Image" to select an image file
- Capture/Select image and click the "Analyze" button
- View results:
- Sustainability score with progress bar
- Product details (name, brand, category)
- Pros and cons breakdown
- Recommended eco-friendly alternatives with live pricing
- Direct shopping links to alternatives
- Actionable sustainability tips
- Overall verdict
Analyzes a product image and returns sustainability information.
Request:
{
"image": "data:image/jpeg;base64,..."
}Response:
{
"productName": "Product Name",
"brand": "Brand Name",
"category": "Category",
"sustainabilityScore": 7,
"scoreDetails": {
"packaging": {"score": 2, "max": 3, "reason": "..."},
"production": {"score": 2, "max": 3, "reason": "..."},
"companyEthics": {"score": 2, "max": 2, "reason": "..."},
"lifecycleImpact": {"score": 1, "max": 2, "reason": "..."}
},
"pros": ["...", "...", "..."],
"cons": ["...", "...", "..."],
"alternatives": [
{
"name": "Alternative Name",
"brand": "Brand",
"whyBetter": "reason",
"price": "cheaper/similar/expensive",
"where": "availability"
}
],
"actionTips": {
"recycling": ["...", "...", "..."],
"reduceImpact": ["...", "...", "..."],
"betterChoices": ["...", "...", "..."]
},
"verdict": "Overall assessment"
}Enriches alternative product suggestions with real-time pricing and shopping links using SerpAPI.
Request:
{
"alternatives": [
{
"name": "Alternative Product Name",
"brand": "Brand Name",
"whyBetter": "reason why this is better",
"price": "cheaper/similar/expensive",
"where": "availability"
}
]
}Response:
{
"alternatives": [
{
"name": "Alternative Product Name",
"brand": "Brand Name",
"whyBetter": "reason why this is better",
"price": "actual price from Google Shopping",
"link": "https://shopping.google.com/...",
"source": "retailer name",
"where": "availability"
}
]
}Note: This endpoint requires SERPAPI_KEY to be set in environment variables. It searches for current pricing and product links to provide users with direct shopping options.
# Development mode (with auto-reload)
npm run dev
# Production mode
npm startβββ index.html # Main HTML file
βββ styles.css # Application styling
βββ script.js # Frontend logic
βββ server.js # Express server
βββ prompt.js # Gemini AI prompt template
βββ package.json # Project dependencies
βββ README.md # This file
- Frontend captures or uploads an image and converts it to base64
- Image is sent to the backend as JSON
- Backend extracts the base64 data and sends it to Gemini 2.5 Flash API with a custom prompt
- Gemini analyzes the product and returns structured JSON data
- Response is parsed and displayed with percentage bar visualization
- Optional enrichment: Alternative eco-sustainable options are are sent to
/collectAlternativesendpoint - SerpAPI searches Google Shopping for current pricing and store links
- User sees live prices, retailer information, and direct shopping links for each alternative
| Variable | Description | Example |
|---|---|---|
PORT |
Server port | 3000 |
GEMINI_API_KEY |
Google Gemini API key | AIzaSy... |
SERPAPI_KEY |
SerpAPI key for shopping data | 1234567890... |
# Server Configuration
PORT=3000
# Google Gemini API
GEMINI_API_KEY=your_google_gemini_api_key_here
# SerpAPI for shopping alternatives
SERPAPI_KEY=your_serpapi_key_hereGet your API keys from:
- Gemini API: Google AI Studio
- SerpAPI: SerpAPI Dashboard
- Chrome/Chromium (recommended)
- Firefox
- Safari
- Edge
Note: Camera access requires HTTPS in production or localhost in development
This project is licensed under the ISC License - see the LICENSE file for details.
"Camera not working"
- Ensure you're using HTTPS (production) or localhost (development)
- Check browser camera permissions
"GEMINI_API_KEY not set"
- Create a
.envfile in the root directory - Add your API key:
GEMINI_API_KEY=your_key_here
"SERPAPI_KEY not set"
- Create a
.envfile if it doesn't exist - Add your SerpAPI key:
SERPAPI_KEY=your_key_here - Get it from SerpAPI Dashboard
- Without this, the app will work but alternatives won't have live pricing/links
"JSON parsing error"
- Ensure the Gemini API is responding properly
- Check API quota and rate limits
"Alternative enrichment failed"
- Verify SERPAPI_KEY is valid and has available quota
- Check SerpAPI account at serpapi.com
- The app still shows alternatives even if enrichment fails
- Batch image analysis
- Save analysis history
- Dark mode theme
- Multi-language support
- Mobile app version
- Integration with recycling facility locator
- One-click purchase for alternatives
- Price tracking and alerts
- Carbon footprint calculator
- Store location finder for alternatives
- Community reviews on products
- Barcode scanning support
For issues, questions, or suggestions, please open an issue on the repository.