Muhammad KaifKarachi, Pakistan
Muhammad Kaif

Back to all projects

AI Lead Automation

A Python service that reads every contact-form lead, scores it, answers the visitor and alerts me with a drafted reply.

For
For this portfolio's own contact form.
Built with
Python, FastAPI, Pydantic, Gemini API, MongoDB, pytest
Proof
Built and tested with pytest. Not deployed yet.
Live
In progress
Code
Part of this portfolio's private repository
AI Lead Automation demo scoring an urgent bug-fix enquiry, step by step

The problem

Enquiries come in English, Urdu and Roman Urdu, mixed with spam. Each one had to be read, judged and answered by hand, so a serious client could wait hours for a first reply.

What I built

  • A FastAPI service with Pydantic models. Gemini returns JSON that is checked against the same schema.
  • A lead score from 0 to 100 with reasons, plus category, urgency, language and budget.
  • Plain Python rules decide what happens. The model informs, it never acts.
  • An instant reply to the visitor in their own language through Gmail SMTP. Links, emails and phone numbers are stripped from AI-written text.
  • An alert to me with the summary, score and a drafted answer.
  • Every lead saved to MongoDB.
  • A dry-run demo of the same pipeline, where nothing is sent or saved.

How it fits together

  1. Contact formNext.js /api/contact
  2. FastAPI serviceinternal, called by the site
  3. Geminityped analysis, checked by Pydantic
  4. Python rulesdecide: hot, normal or spam
  5. ActGmail reply, alert, MongoDB

Hard parts

The model informs, rules decide

Gemini only produces data. Tested Python rules choose the action, so a bad model answer can't send a bad email.

Fails safe

If the AI or the whole service is down, the lead still reaches my inbox as a plain email. Spam never gets an auto-reply.

Free-tier limits

When one Gemini model is busy or out of quota, the next model in the list is tried.

Results

Works locally with a pytest suite (AI, email and database are faked in tests). Going live is planned as a separate phase.

Stack

Python, FastAPI, Pydantic, Gemini API, Gmail SMTP, MongoDB, pytest, Next.js

Screens