Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BeWear - Ethical Fashion Intelligence Platform

A full-stack AI-powered platform that analyzes fashion brands for ethical practices, identifies greenwashing claims, and empowers consumers to make informed fashion choices.

Live brand analysis in seconds. AI-powered. No greenwashing.

Version License Status

What is BeWear?

BeWear provides instant ethical analysis of fashion brands using three methods:

  1. Text Search - Search by brand name (Nike, Zara, H&M, etc.)
  2. Image Upload - Upload a product photo and we'll identify the brand and analyze it
  3. Camera Capture - Snap a photo in-app of any fashion item
  4. Greenwashing Detection - Investigate if a brand is making false ethical claims

Sample Analysis

Input: "Nike"

Output:

{
  "brand_name": "Nike",
  "overall_score": 75.5,
  "rating": "Good",
  "labor_score": 70.0,
  "environmental_score": 80.0,
  "transparency_score": 76.0,
  "supply_chain_score": 75.0,
  "certifications": ["Fair Trade", "GOTS"],
  "analysis": "Nike shows commitment to labor standards with documented policies for fair wages and worker safety. Their environmental efforts focus on sustainable materials and water reduction. However, transparency could be improved in supply chain disclosure..."
}

Key Features

  • Instant Analysis - Get ethical scores within 2-3 seconds
  • 📸 Image Recognition - Identify brands from product photos using Google Lens
  • 🤖 AI-Powered Insights - Claude AI explains ethical practices in natural language
  • 🔍 Greenwashing Detection - Investigates false environmental claims with web search
  • 📊 Comprehensive Scoring - Labor, environmental, transparency, and supply chain metrics
  • 🎯 Autocomplete - Real-time brand search suggestions
  • 📱 Mobile Responsive - Works on phones, tablets, and desktops
  • 🚀 Real-time Updates - Live status streaming for long-running investigations

Technology Stack

Backend

  • Framework: FastAPI + Uvicorn (Python 3.11)
  • Database: Elasticsearch 8.11.1+ (local or cloud)
  • AI: Claude API (Anthropic) - Sonnet 3.5 for analysis, Haiku for quick tasks
  • Search: Tavily API (greenwashing investigation)
  • Vision: Google Lens via SerpAPI (image identification)
  • Streaming: SSE (Server-Sent Events) for real-time updates

Frontend

  • Framework: Vanilla JavaScript (no build step)
  • Styling: Tailwind CSS
  • Icons: Font Awesome 6.5.1
  • Features: Tab-based UI, drag-and-drop upload, camera streaming

DevOps

  • Containerization: Docker & Docker Compose
  • Package Management: uv (Python)
  • Environment: Python venv

Quick Start

1. Prerequisites

  • Docker and Docker Compose
  • Python 3.11+
  • API Keys:
    • ANTHROPIC_API_KEY - Get from Anthropic Console
    • TAVILY_API_KEY - Get from Tavily (for greenwashing detection)
    • SERP_API_KEY (optional) - Get from SerpAPI for image analysis
    • IMGBB_API_KEY (optional) - Get from ImgBB API for image hosting

2. Setup

# Clone the repository
git clone https://github.com/haribary/ethical-source.git
cd ethical-source

# Start Elasticsearch
docker-compose up -d

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
cd backend_fastAPI
pip install -r requirements.txt

# Configure environment
cp .env.example .env
# Edit .env with your API keys

# Ingest sample data
python ingest_data.py

# Start backend server
python main.py
# Server runs on http://localhost:8000

3. Open Frontend

Open frontend/index.html in your browser, or serve it:

cd frontend
python -m http.server 8080
# Open http://localhost:8080 in your browser

API Endpoints

Text Analysis

POST /analyze/text
Content-Type: application/json

{"brand_name": "nike"}

Returns: Brand ethical analysis with scores, certifications, and AI insights

Image Analysis

POST /analyze/image
Content-Type: multipart/form-data

file: <image file>

Returns: Brand analysis + Google Lens identified products

Autocomplete/Search

GET /autocomplete?q=nik&limit=10

Returns: Brand suggestions with ratings

Greenwashing Investigation (Server-Sent Events)

POST /analyze/greenwashing
Content-Type: application/json

{"brand_name": "nike"}

Streams real-time status updates, then returns:

  • Greenwashing risk flag (LOW/MEDIUM/HIGH)
  • Summary of findings
  • Top articles with citations
  • Relevance scores

Health Check

GET /health

Architecture Overview

Data Flow - Text Analysis

User Input (Brand Name)
    ↓
Elasticsearch (Fuzzy Search)
    ↓
Brand Data Retrieved
    ↓
Claude AI (Analysis Generation)
    ↓
Formatted Response
    ↓
Frontend Display

Data Flow - Image Analysis

User Upload (Image)
    ↓
Image Validation & Upload to ImgBB
    ↓
Google Lens (Product Identification)
    ↓
Claude Extracts Brand Name
    ↓
Elasticsearch Search
    ↓
Claude Analysis
    ↓
Response with Google Lens Results

Data Flow - Greenwashing Detection

Brand Name
    ↓
Stream Status: "Looking up brand..."
    ↓
Elasticsearch Lookup
    ↓
Stream Status: "Initializing AI agent..."
    ↓
LangGraph Agent Creates 3 Search Queries
    ↓
Stream Status: "Searching news sources..."
    ↓
Tavily Web Search (Top 10 Results)
    ↓
Stream Status: "Analyzing articles..."
    ↓
Claude Analyzes Each Article
    ↓
Stream Status: "Evaluating greenwashing risk..."
    ↓
Rank by Relevance + Flag (LOW/MEDIUM/HIGH)
    ↓
Stream Final Result

Data Model

Elasticsearch Index: ethical_brands

{
  "name": "Nike",
  "official_name": "Nike, Inc.",
  "overall_score": 75.5,
  "labor_rights_score": 70.0,
  "environmental_impact_score": 80.0,
  "transparency_score": 76.0,
  "supply_chain_ethics_score": 75.0,
  "rating_tier": "Good",
  "certifications": ["Fair Trade", "GOTS"],
  "metrics": [
    {
      "metric_id": "labor-001",
      "metric_name": "Fair Wages",
      "category": "labor_rights",
      "score": 70.5,
      "weight": 2.0,
      "description": "Assessment of fair wages practices"
    }
  ]
}

Project Structure

ethical_src/
├── backend_fastAPI/
│   ├── main.py                  # FastAPI application (818 lines)
│   ├── greenwashing_agent.py   # LangGraph-based agent (407 lines)
│   ├── ingest_data.py          # Sample data ingestion
│   ├── requirements.txt        # Python dependencies
│   ├── .env                    # Configuration (create from .env.example)
│   ├── start.sh                # Quick start script
│   ├── README.md               # Backend documentation
│   └── QUICK_START.md          # Quick reference
│
├── frontend/
│   ├── index.html              # Main UI
│   ├── app.js                  # JavaScript logic
│   └── package.json            # Frontend metadata
│
├── docker-compose.yml          # Elasticsearch setup
└── LICENSE                     # MIT License

Development

Backend Development

cd backend_fastAPI
source venv/bin/activate

# Run with auto-reload
python main.py

# Run tests
python test_startup.py

# Example usage
python example_usage.py

Frontend Development

No build step needed. Just edit files and refresh browser:

  • index.html - UI structure and styling
  • app.js - JavaScript logic and API calls

Adding New Brands

Edit backend_fastAPI/ingest_data.py and add brands to the sample data:

brands = [
    {
        "_id": "mybrand-001",
        "name": "MyBrand",
        "official_name": "MyBrand Inc.",
        "overall_score": 85.0,
        # ... other fields
    }
]

Then re-ingest:

python ingest_data.py

Configuration

Environment Variables

Create .env in backend_fastAPI/:

# Required
ANTHROPIC_API_KEY=sk-ant-your-key
TAVILY_API_KEY=your-tavily-key

# Elasticsearch
ELASTICSEARCH_HOST=http://localhost:9200
ELASTICSEARCH_USER=elastic
ELASTICSEARCH_PASSWORD=password

# Optional (for image analysis)
SERP_API_KEY=your-serp-key
IMGBB_API_KEY=your-imgbb-key

CORS Settings

Update CORS allowed origins in backend_fastAPI/main.py:

app.add_middleware(
    CORSMiddleware,
    allow_origins=["http://localhost:3000", "https://yourdomain.com"],
)

Performance

Latency Expectations

  • Text Analysis: ~2-3 seconds
  • Image Analysis: ~8-10 seconds
  • Greenwashing Investigation: ~15-20 seconds

Optimization Tips

  1. Cache popular brands with Redis
  2. Use Claude streaming for faster perceived latency
  3. Parallel process Google Lens + ImgBB uploads
  4. Preload top 100 brands in memory

Security & Deployment

Before Production

  • Restrict CORS to specific domains
  • Implement rate limiting
  • Add file size validation (e.g., 5MB max)
  • Set up HTTPS
  • Enable database authentication
  • Add request logging/monitoring
  • Configure error tracking (Sentry)
  • Implement API key rotation

Docker Deployment

# Build
docker build -t bewear-backend backend_fastAPI/

# Run
docker run -p 8000:8000 \
  -e ANTHROPIC_API_KEY=your-key \
  -e ELASTICSEARCH_HOST=elasticsearch:9200 \
  bewear-backend

Troubleshooting

"Brand not found"

# Check Elasticsearch is running
curl http://localhost:9200

# Verify data is ingested
python backend_fastAPI/ingest_data.py

# Check index exists
curl http://localhost:9200/ethical_brands/_count

"IMGBB_API_KEY not configured"

Image analysis requires ImgBB:

  1. Get free key at https://api.imgbb.com/
  2. Add to .env: IMGBB_API_KEY=your-key

"Google Lens failed"

  1. Verify SERP_API_KEY in .env
  2. Check SerpAPI account has credits
  3. Ensure image is in public format

Module not found

cd backend_fastAPI
source venv/bin/activate
pip install -r requirements.txt

API Response Examples

Text Analysis Response

{
  "brand_name": "Nike",
  "detection_method": "text_input",
  "google_lens_titles": null,
  "analysis": "Nike scores 75.5/100 on our ethical scale. Strengths: They have documented labor standards and are transitioning to sustainable materials. Weaknesses: Supply chain transparency needs improvement, and worker wages remain below living wage in some regions.",
  "overall_score": 75.5,
  "rating": "Good",
  "labor_score": 70.0,
  "environmental_score": 80.0,
  "transparency_score": 76.0,
  "supply_chain_score": 75.0,
  "certifications": ["Fair Trade", "GOTS"],
  "analyzed_at": "2025-01-15T10:30:00Z"
}

Greenwashing Response

{
  "flagged": true,
  "flag_level": "MEDIUM",
  "summary": "Found evidence of selective environmental claims without full context on labor practices",
  "total_articles_found": 23,
  "articles": [
    {
      "title": "Brand's 'Eco-Friendly' Claims Draw Scrutiny",
      "url": "https://example.com/article",
      "published_date": "2024-12-15",
      "greenwashing_type": "selective_transparency",
      "evidence": "Claims 100% renewable materials but doesn't disclose water usage",
      "why_matters": "Consumers misled about full environmental impact",
      "relevance_score": 0.95
    }
  ]
}

Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Recent Updates

  • Fixed JSON parsing in greenwashing agent
  • Improved top 10 results consistency
  • Added real-time status updates via Server-Sent Events
  • Enhanced UI with live progress indicators
  • Single Elasticsearch index for simplified architecture

See CHANGES_SUMMARY.md for details.

Future Roadmap

Phase 1 (Quick Wins)

  • Brand comparison endpoint
  • Redis caching for popular brands
  • Analytics dashboard

Phase 2 (Enhanced UX)

  • User accounts and saved searches
  • User reviews and ratings
  • Alternative brand recommendations

Phase 3 (Advanced)

  • ML-based similar brand detection
  • Sustainability predictions
  • Real-time brand score updates

Support & Documentation

License

MIT License - see LICENSE file for details

Data Attribution

Ethical ratings based on data from:

  • Good On You: Independent ethical fashion ratings
  • Tavily: Web search for greenwashing investigations
  • Google Lens: Product identification
  • Claude AI: Analysis and recommendations

Author

Created by


Make ethical fashion choices. One brand at a time.

For questions, feedback, or partnership opportunities, open an issue or contact the maintainer.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages