Skip to content

1stsimplifycode/Bharat-Trust-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ BharatTrust AI

Agentic AI Marketplace Intelligence Platform for Bharat

Seven specialist agents, a live orchestrator you can watch think, and an explainable Decision Engine β€” over 500 sellers, 3,000 listings, 5,000 reviews of realistic marketplace data with planted fraud rings the agents genuinely catch.

Python FastAPI Frontend License CI

Orchestrator theatre β€” agents dispatched live, reasoning streamed, decision fused

Why this isn't a dashboard

The UI doesn't poll a finished answer β€” it subscribes to a Server-Sent Events stream and watches the Orchestrator dispatch each agent, narrate its real computation phases, return its computed score, and hand everything to the Decision Engine for a fused, explainable verdict:

customer intent ──► Orchestrator ══ SSE ══► browser
                        β”‚                   (graph lights up, console types,
                        β–Ό                    agent cards fill in live)
   Seller Monitoring β†’ Authenticity β†’ Fraud β†’ Review Intelligence
        β†’ Return Prediction β†’ Price Intelligence β†’ Logistics
                        β”‚
                        β–Ό
        Decision Engine β†’ RECOMMEND / RECOMMEND WITH CAUTION / SUPPRESS
                          + six-signal breakdown of WHY

A second stream (/api/events/stream) powers the Admin ops room: fraud rings, counterfeit listings and return-risk interventions surface as the agents flag them, plotting onto a live risk map of India.

Admin ops room Seller studio

The agents (all real computation, zero mocks)

Agent Technique Output
🚨 Fraud Detection Isolation Forest + GST/phone/IP identity graph (pure-Python robust z-score fallback when compiled DLLs are unavailable) risk 0–100 + evidence
πŸ›‘οΈ Seller Monitoring weighted behavioural scoring (cancellations, delays, complaints, volatility) trust 0–100 + reasons
🏷️ Authenticity metadata + price-vs-MRP coherence for premium brands (OCR hook ready) % authentic + counterfeit prob
πŸ’¬ Review Intelligence Jaccard shingle near-duplicate clustering + spam heuristics % genuine + flagged reviews
πŸ“¦ Return Prediction interpretable logistic model over category/seller/price features probability + intervention
πŸ’Έ Price Intelligence category quantiles (p25/median/p75) + elasticity recommended price
🚚 Logistics haversine routing across a 5-hub network vs central baseline warehouse, ETA, β‚Ή savings
πŸ—£οΈ Support intent routing + DB-backed actions in 11 Indian languages grounded replies
βš–οΈ Trust Engine weighted fusion of six signals overall score + band

The proof it's real: the seed plants a 3-seller ring sharing one phone number and IP, plus premium-brand listings at 26–33% of MRP. The agents are never told who's bad β€” they find them (ring flagged at 84–96 risk via the identity graph; counterfeits at 44% authenticity via price coherence). The CI suite asserts exactly this on every push, on both the full-ML and pure-Python backends.

Quick start (local β€” zero external setup)

Windows: double-click setup.bat, then run.bat β†’ opens http://localhost:8000

macOS / Linux:

./setup.sh && ./run.sh        # dashboard at http://localhost:8000, API docs at /docs

Manual:

cd backend
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
python -m app.seed            # 500 sellers / 3,000 products / planted anomalies
uvicorn app.main:app --port 8000

Demo flow that lands hardest: click the Adidas pick with the red dot (planted counterfeit) and watch the Authenticity agent catch it live, then open Admin Ops to see the fraud ring surface in the event stream.

Deploy

Vercel (one click)

npm i -g vercel && vercel        # from the repo root β€” that's it

or import the GitHub repo at vercel.com/new β€” no configuration needed. The repo is Vercel-native:

  • public/ β†’ static frontend, served from the edge
  • api/index.py β†’ the FastAPI app as a serverless function (vercel.json rewrites /api/*, /docs, /health to it)
  • data/bharattrust.seed.db β†’ pre-seeded snapshot copied to /tmp on cold start (serverless filesystems are read-only)
  • root requirements.txt is deliberately slim β€” no scikit-learn/scipy β€” so the bundle stays small; the fraud agent auto-degrades to its pure-Python backend with identical interfaces (CI tests this exact path)

Streaming note: SSE pacing is guaranteed on local/Render/Railway runs. Some Vercel plans buffer Python responses; if so, frames arrive together at stream end and the UI still renders everything β€” just less theatrically. For judged demos, run locally or on Render.

Render / Railway (long-lived server, guaranteed SSE)

render.yaml blueprint and backend/Procfile are included:

web: uvicorn app.main:app --host 0.0.0.0 --port $PORT

Supabase / Postgres

Set one env var β€” the schema creates itself on startup:

DATABASE_URL=postgresql+psycopg://user:pass@host:5432/postgres

Key API endpoints

Method Path Description
GET /api/orchestrate/picks interesting listings (incl. planted counterfeits)
GET /api/orchestrate/stream?product_id= SSE β€” live agent-by-agent evaluation
GET /api/events/stream SSE β€” live marketplace ops feed
GET /api/analytics/overview KPIs + marketplace health
GET /api/fraud/scan?min_risk=50 fraud scan with evidence
GET /api/sellers/{id}/trust full orchestrated trust evaluation
POST /api/returns/predict pre-shipment return probability
POST /api/price/recommend optimal price recommendation
POST /api/logistics/optimize warehouse + route + savings
POST /api/support/ask multilingual support agent

Interactive docs at /docs.

Repository layout

β”œβ”€β”€ api/index.py            Vercel serverless entrypoint
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ agents/         the nine agents + trust engine + orchestrator
β”‚   β”‚   β”œβ”€β”€ orchestration/  SSE frame generators (live.py, events.py)
β”‚   β”‚   β”œβ”€β”€ routers/        REST (api.py) + streaming (stream.py)
β”‚   β”‚   β”œβ”€β”€ models.py Β· seed.py Β· main.py Β· database.py
β”‚   └── requirements.txt    full stack (Isolation Forest) for local/Render
β”œβ”€β”€ public/index.html       the entire frontend β€” zero JS dependencies
β”œβ”€β”€ data/bharattrust.seed.db   pre-seeded snapshot for serverless deploys
β”œβ”€β”€ tests/test_smoke.py     proves planted anomalies are genuinely caught
β”œβ”€β”€ .github/workflows/ci.yml   two jobs: full-ML and pure-Python paths
β”œβ”€β”€ vercel.json Β· render.yaml Β· setup/run scripts

Honesty of scope

Every score is computed at request time from the database β€” but these are algorithmic agents (statistics, one ML model, graph analysis, heuristics), not LLM agents. The console's reasoning lines are honest narrations of each agent's real computation phases, paced for legibility; no language model "thinks" in the loop. That mirrors how production marketplace-integrity systems actually work. Documented hooks for the natural next milestones: Mistral-generated decision rationales, OCR-backed packaging verification (ocr_text param wired), real translation services, production auth.

Troubleshooting

Windows: DLL load failed … An Application Control policy has blocked this file β€” Smart App Control blocks scipy's unsigned DLLs. Handled automatically: the fraud agent detects the blocked import and switches to its pure-Python backend (same interface, same planted-ring detection). No need to touch Windows security.

ERR_CONNECTION_REFUSED β€” the server didn't start; scroll the run.bat console up for the actual Python error.

License

MIT β€” see LICENSE.

About

BharatTrust AI is an agentic AI platform built for Indian ecommerce, deploying seven autonomous AI agents to detect counterfeit products, seller fraud, high return risk, and logistics failures in real time. The system replaces slow, rule-based moderation with a self-regulating marketplace intelligence layer that shares memory across agents

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages