The ScrapAI platform uses Google's Gemini Pro Vision AI to analyze waste images and verify waste types. This feature helps ensure accurate waste reporting and provides users with detailed analysis.
- Go to Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Copy the generated API key
Create a .env.local file in your project root and add:
# Google AI (Gemini) API Key
GOOGLE_AI_API_KEY=your_actual_api_key_here
# Other required environment variables
DATABASE_URL=your_database_url_here
NEXT_PUBLIC_WEB3AUTH_CLIENT_ID=your_web3auth_client_id_here- User uploads an image in the Report Waste page
- Image is sent to the server via API route
- Real-time feedback shows analysis progress
- Results are displayed to the user
/api/analyze-wastehandles image processing- Uses Google Gemini Pro Vision for analysis
- Returns structured JSON with waste details
- Handles errors gracefully
The AI analyzes images and provides:
- Waste Type: plastic, paper, organic, metal, glass, electronic, hazardous, mixed
- Confidence Score: 0-100% accuracy rating
- Description: Detailed description of the waste
- Amount Estimation: small, medium, large
- Hazard Assessment: true/false for dangerous materials
- Recommendations: Proper disposal methods
- Verified Reports: 15 points (AI confirms waste type)
- Pending Reports: 10 points (no AI analysis)
- Rejected Reports: 5 points (AI disagrees with user input)
- Start your development server:
npm run dev - Go to the Report Waste page
- Upload an image of waste
- Watch the AI analysis in real-time
- Submit the report to see verification results
- Check that
GOOGLE_AI_API_KEYis set in.env.local - Restart your development server after adding the key
- Check your internet connection
- Verify the API key is valid
- Check browser console for detailed error messages
- Ensure image is under 10MB
- Use JPEG, PNG, or WebP format
- Minimum resolution: 200x200 pixels
- API key is stored server-side only
- Images are processed securely via API route
- No sensitive data is exposed to the client
- Rate limiting can be added for production
For production deployment:
- Set environment variables in your hosting platform
- Consider adding rate limiting to the API route
- Monitor API usage and costs
- Implement image compression for better performance
{
"success": true,
"result": {
"wasteType": "plastic",
"confidence": 85,
"description": "Clear plastic water bottle with cap",
"estimatedAmount": "small",
"isHazardous": false,
"recommendations": [
"Rinse container before recycling",
"Check local recycling guidelines"
],
"verificationStatus": "verified"
}
}- Google Gemini Pro Vision has usage-based pricing
- Typical cost: ~$0.01-0.05 per image analysis
- Monitor usage in Google AI Studio dashboard
- Consider implementing caching for repeated images