Skip to content

ackshatiwari/TalkTrash

Repository files navigation

TalkTrash πŸ—‘οΈ

A web application that analyzes products through images using Google's Gemini AI to provide sustainability insights, disposal recommendations, and eco-friendly alternatives.

Features

✨ 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

Tech Stack

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

Installation

Prerequisites

  • Node.js (v16 or higher)
  • npm
  • Google Gemini API Key
  • SerpAPI Key (for alternative product pricing)

Setup Steps

  1. Clone the repository
git clone <repo-url>
cd new
  1. Install dependencies
npm i
  1. Configure environment variables Create a .env file 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:

  1. Start the development server
npm run dev

Server will run at http://localhost:3000

Usage

  1. Open the app in your browser at http://localhost:3000
  2. Choose input method:
    • Click "Start Camera" to take a photo with your webcam
    • Click "Upload Image" to select an image file
  3. Capture/Select image and click the "Analyze" button
  4. 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

API Endpoints

POST /analyze

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"
}

POST /collectAlternatives

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.

Scripts

# Development mode (with auto-reload)
npm run dev

# Production mode
npm start

Project Structure

β”œβ”€β”€ 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

How It Works

  1. Frontend captures or uploads an image and converts it to base64
  2. Image is sent to the backend as JSON
  3. Backend extracts the base64 data and sends it to Gemini 2.5 Flash API with a custom prompt
  4. Gemini analyzes the product and returns structured JSON data
  5. Response is parsed and displayed with percentage bar visualization
  6. Optional enrichment: Alternative eco-sustainable options are are sent to /collectAlternatives endpoint
  7. SerpAPI searches Google Shopping for current pricing and store links
  8. User sees live prices, retailer information, and direct shopping links for each alternative

Environment Variables

Variable Description Example
PORT Server port 3000
GEMINI_API_KEY Google Gemini API key AIzaSy...
SERPAPI_KEY SerpAPI key for shopping data 1234567890...

.env Template

# 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_here

Get your API keys from:

Browser Support

  • Chrome/Chromium (recommended)
  • Firefox
  • Safari
  • Edge

Note: Camera access requires HTTPS in production or localhost in development

License

This project is licensed under the ISC License - see the LICENSE file for details.

Troubleshooting

"Camera not working"

  • Ensure you're using HTTPS (production) or localhost (development)
  • Check browser camera permissions

"GEMINI_API_KEY not set"

  • Create a .env file in the root directory
  • Add your API key: GEMINI_API_KEY=your_key_here

"SERPAPI_KEY not set"

  • Create a .env file 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

Future Enhancements

  • 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

Support

For issues, questions, or suggestions, please open an issue on the repository.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors