Skip to content
abdulhayykhanPublic

About

An AI-powered service orchestrator and interactive mobile assistant built with FastAPI and Flet for the AI Seekho 2026 AntiGravity Hackathon.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Ustaad-AI πŸ› οΈπŸ€–

Download APK Built for Python Gemini


What Is This?

Ustaad-AI is an AI-powered service worker discovery platform built for Karachi's informal economy. Users describe their problem in natural language β€” Roman Urdu, English, or Urdu β€” and the system finds, ranks, and books the best available local service worker automatically.

The platform runs a 3-agent orchestration pipeline (Intent Parser β†’ Matchmaker β†’ Pricer) backed by a real SQLite database of 500 seeded Karachi service providers. Every agent decision is streamed live to the frontend via Server-Sent Events (SSE) so judges and users can verify the reasoning in real time.


Features ✨

  • Roman Urdu / Urdu / English NLP β€” Gemini parses noisy, multilingual, informal requests into structured intent (service type, location, urgency, time).
  • 3-Agent Pipeline β€” Intent Parser, Matchmaker, and Pricer run sequentially with structured JSON outputs validated by Pydantic schemas.
  • 6-Factor Matching Algorithm β€” Providers ranked by: Travel Time (30%), Rating (20%), Reliability (20%), Price (15%), Cancellation Rate (15%).
  • Real Geolocation β€” Google Maps Geocoding + Distance Matrix API for actual driving distance and travel time, not mock values.
  • Dynamic Pricing β€” Urgency multiplier (1.5Γ— if high) + distance fee (50 PKR/km) on top of provider's base rate.
  • Live Agent Traces β€” SSE endpoint streams raw orchestration logs to expandable debug view in the UI.
  • Voice Simulator β€” Inline voice-to-text simulation without blocking the UI thread.
  • WhatsApp + Maps Deep Links β€” One-tap contact and navigation directly from the result card.
  • Dark Mode β€” Full light/dark theme toggle on the Flet frontend.
  • Android APK β€” Built and released via GitHub Actions CI/CD (Flet flet build apk).
  • 429 Fallback Handling β€” All 3 agents have mock fallbacks if Gemini quota is exhausted mid-demo.

Architecture πŸ›οΈ

User Input (Roman Urdu / English / Urdu)
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         FastAPI Backend (Uvicorn)        β”‚
β”‚                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚     UstaadOrchestrator           β”‚   β”‚
β”‚  β”‚                                  β”‚   β”‚
β”‚  β”‚  1. Intent Parser Agent          β”‚   β”‚
β”‚  β”‚     └─ Gemini 2.0 Flash (JSON)   β”‚   β”‚
β”‚  β”‚                                  β”‚   β”‚
β”‚  β”‚  2. Matchmaker Agent             β”‚   β”‚
β”‚  β”‚     β”œβ”€ Google Maps Geocoding     β”‚   β”‚
β”‚  β”‚     β”œβ”€ SQLite DB Query           β”‚   β”‚
β”‚  β”‚     β”œβ”€ Distance Matrix API       β”‚   β”‚
β”‚  β”‚     └─ Gemini 2.0 Flash (Rank)   β”‚   β”‚
β”‚  β”‚                                  β”‚   β”‚
β”‚  β”‚  3. Pricer Agent                 β”‚   β”‚
β”‚  β”‚     └─ Gemini 2.0 Flash (JSON)   β”‚   β”‚
β”‚  β”‚                                  β”‚   β”‚
β”‚  β”‚  SSE Trace Queue (asyncio)       β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                   β”‚
        β–Ό                   β–Ό
  POST /api/request    GET /api/agent-traces
        β”‚                   β”‚
        β–Ό                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         Flet Frontend (Mobile UI)        β”‚
β”‚  - Chat interface                        β”‚
β”‚  - Multi-stage loading animation         β”‚
β”‚  - Expandable SSE debug trace window     β”‚
β”‚  - WhatsApp + Maps deep links            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Layer Technology
Frontend Flet >=0.85.0, <0.91.0
Backend FastAPI + Uvicorn
AI Core Google Gemini 2.0 Flash (google-genai)
Database SQLite via SQLAlchemy
Geolocation Google Maps API (googlemaps)
Deployment Cloud Run (backend), GitHub Actions (APK)

Getting Started πŸš€

Prerequisites

  • Python 3.11
  • A Google Gemini API Key β€” get one here
  • A Google Maps API Key with Geocoding + Distance Matrix enabled β€” get one here

1. Clone the Repository

git clone https://github.com/abdulhayykhan/Ustaad-AI.git
cd Ustaad-AI

2. Create Environment File

cp .env.example .env

Edit .env:

GEMINI_API_KEY=your_gemini_api_key_here
GOOGLE_MAPS_API_KEY=your_google_maps_api_key_here
DATABASE_URL=sqlite:///./ustaad.db
CORS_ALLOW_ORIGINS=http://localhost:8550,http://127.0.0.1:8550
USTAAD_API_URL=http://localhost:8000

3. Install Dependencies

pip install -r requirements.txt

Note: The package google-genai is required (not google-generativeai). The requirements.txt includes the correct package.

4. Seed the Database

Populate 500 mock Karachi service providers into the local SQLite DB:

python -m backend.seed

Expected output:

Starting database seeding...
Successfully seeded 500 providers to the database.

5. Run the Application

Open two terminal sessions from the project root:

Terminal 1 β€” FastAPI Backend:

uvicorn backend.main:app --reload

Backend runs on http://localhost:8000.

Terminal 2 β€” Flet Frontend:

python -m frontend.main

API Endpoints

Method Endpoint Description
POST /api/request Submit natural language service request. Triggers full 3-agent pipeline.
GET /api/agent-traces SSE stream of live agent reasoning logs.

Sample Request:

curl -X POST http://localhost:8000/api/request \
  -H "Content-Type: application/json" \
  -d '{"text": "Malir Halt mein kal subah AC mechanic chahiye, urgent hai"}'

Sample Prompts

Mujhe kal subah Malir Halt mein AC technician chahiye, AC bilkul cooling nahi kar raha.

Yar Shah Faisal Number 3 mein urgent electrician chahiye, main board se dhuan nikal raha hai!

Sea View apartments ke paas kisi Generator Mechanic ka contact milega? Kal dopahar mein service karwani hai.

Ϊ―Ω„Ψ΄Ω† Ψ§Ω‚Ψ¨Ψ§Ω„ Ψ¨Ω„Ψ§Ϊ© 13D Ω…ΫŒΪΊ ΩˆΨ§Ψ΄Ω†Ϊ― Ω…Ψ΄ΫŒΩ† Ϊ©Ψ§ ΩΉΫŒΪ©Ω†ΫŒΨ΄Ω† Ϊ†Ψ§ΫΫŒΫ’Ϋ” ΩΎΨ§Ω†ΫŒ Ω„ΫŒΪ© ہو رہا ہے۔

Need a plumber tomorrow morning at DHA Phase 6 Khayaban-e-Shahbaz. Kitchen sink completely clogged.

Matching Algorithm

The Matchmaker Agent scores each candidate provider using this weighted formula:

Factor Weight Source
Travel Time 30% Google Maps Distance Matrix
Rating 20% Provider DB (rating field, 0–5)
Reliability Score 20% Provider DB (reliability_score, 0–100)
Base Rate (Price) 15% Provider DB (base_rate_pkr)
Cancellation Rate 15% Provider DB (cancellation_rate, 0–1)

Lower travel time, higher rating, higher reliability, lower price, and lower cancellation rate = higher score.


Dynamic Pricing Formula

Total = Base Rate
      + (Base Rate Γ— 0.5)  [if urgency = "high"]
      + (Distance in km Γ— 50 PKR)

Example: Base 800 PKR + Urgency 400 PKR + Distance (3.84 km Γ— 50) 192 PKR = 1,392 PKR


Demo Flow 🎀

  1. Ensure backend is running (uvicorn backend.main:app --reload).
  2. Launch Flet UI (python -m frontend.main).
  3. Toggle Dark Mode using the top-right icon.
  4. Click the Microphone button β€” watch the simulated voice input populate.
  5. Hit Send β€” observe the multi-stage loading animation:
    • πŸ€” Ustaad-AI soch raha hai...
    • πŸ” Aas paas ustaad dhoond raha hai...
    • πŸ’° Bhau taal tay kar raha hai...
    • βœ… Booking final kar raha hai...
  6. Expand "View AI Agent Reasoning" to see live SSE traces from all 3 agents.
  7. View the result card: provider name, distance, pricing breakdown.
  8. Tap "Message Ustaad on WhatsApp" and πŸ“ Distance links.

Project Structure

Ustaad-AI/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ agents.py        # UstaadOrchestrator + 3 sub-agents
β”‚   β”œβ”€β”€ database.py      # SQLAlchemy engine + session config
β”‚   β”œβ”€β”€ main.py          # FastAPI app, routes, SSE endpoint
β”‚   β”œβ”€β”€ models.py        # Provider + Booking ORM models
β”‚   β”œβ”€β”€ seed.py          # 500-provider Karachi DB seeder
β”‚   └── tools.py         # Google Maps geocoding + distance tools
β”œβ”€β”€ frontend/
β”‚   └── main.py          # Flet mobile UI
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── build-apk.yml  # GitHub Actions APK builder
β”œβ”€β”€ .env.example
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ requirements.txt
└── sample_prompts.txt

Deployment

Backend (Cloud Run)

docker build -t ustaad-ai .
docker run -p 8080:8080 --env-file .env ustaad-ai

Live backend: https://ustaad-ai-620054685556.europe-west1.run.app

Android APK (GitHub Actions)

Push to main branch β€” the workflow in .github/workflows/build-apk.yml automatically builds and uploads the APK artifact. Download from the Releases page.


πŸ“„ License

This project is open-source and available for educational and commercial use under the MIT License.


Made with ❀️ by Abdul Hayy Khan

About

An AI-powered service orchestrator and interactive mobile assistant built with FastAPI and Flet for the AI Seekho 2026 AntiGravity Hackathon.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages