Skip to content

prakh0/AI-Chat-Agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AI Communication Assistant (WhatsApp + Gmail)

An end-to-end AI automation system that reads, understands, and replies to messages from:

  • WhatsApp (via webhook API)
  • Gmail (via Gmail API)

Powered by a locally running Qwen LLM, this system generates intelligent, human-like replies without relying on external paid APIs.


Overview

This project demonstrates how to build a real-world AI assistant that integrates with:

  • WhatsApp (via Meta Cloud API + Webhooks)
  • Gmail (via Gmail API + OAuth)
  • Local LLM (Qwen via Hugging Face)

Unlike typical AI apps, this runs fully locally without paid APIs.


KEY Features

  • Real-time WhatsApp auto-replies
  • Automated Gmail responses
  • Multi-user session memory
  • Local LLM inference (Qwen 0.5B)
  • Email cleaning & truncation
  • Secure environment variable handling

Architecture

WhatsApp Flow (Webhook-based)

┌──────────────┐
│ WhatsApp API │
└──────┬───────┘
       │  (Webhook via ngrok)
       ▼
┌──────────────┐
│  FastAPI App │   ← main.py
└──────┬───────┘
       ▼
┌──────────────┐
│  LLM Model   │   ← model.py
└──────────────┘

Gmail Flow (Independent Script)

┌──────────────┐
│  Gmail API   │
└──────┬───────┘
       ▼
┌──────────────┐
│ Gmail Script │   ← gmail.py
└──────┬───────┘
       ▼
┌──────────────┐
│  LLM Model   │   ← model.py
└──────────────┘

Setup Guide

  1. Clone Repo
git clone https://github.com/YOUR_USERNAME/YOUR_REPO.git
cd YOUR_REPO 
  1. Environment Setup
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
  1. Configure Environment Variables

Create .env:

EMAIL=your_email@gmail.com
OAUTH_CREDENTIALS_FILE=Oauth_cred_chatbot_gmail.json
VERIFY_TOKEN=your_verify_token
ACCESS_TOKEN=your_whatsapp_access_token
PHONE_NUMBER_ID=your_phone_number_id

API Setup

  1. WhatsApp (Meta Cloud API) -Create app → Add WhatsApp Get ACCESS_TOKEN, PHONE_NUMBER_ID -Set webhook: https://your-ngrok-url/webhook
  • ngrok
ngrok http 8000
  1. Gmail API Enable Gmail API in Google Cloud Setup OAuth Consent Screen Download credentials JSON

Environment Setup

  • Create a .env file:

    EMAIL=your_email@gmail.com
    OAUTH_CREDENTIALS_FILE=Oauth_cred_chatbot_gmail.json
    VERIFY_TOKEN=your_verify_token
    ACCESS_TOKEN=your_whatsapp_access_token
    PHONE_NUMBER_ID=your_phone_number_id
    

Running the Application

-- Running the App

uvicorn main:app --reload
ngrok http 8000
python gmail.py

Core Components

  • FastAPI webhook server
  • Handles WhatsApp events
  • Routes messages to LLM
  • Fetches unread emails
  • Cleans + truncates content
  • Sends AI-generated replies
  • Loads Qwen LLM
  • Maintains session memory
  • Generates responses using chat templates
File Responsibility
main.py WhatsApp webhook handler
gmail.py Email processing & replies
model.py LLM + session memory

Performance Notes

  • First run loads model into memory (~5–10 sec)
  • CPU inference: ~2–4 sec per response
  • Input size significantly affects latency

Tech Stack

  • FastAPI
  • Qwen 0.5B
  • Flask
  • Gmail API
  • WhatsApp API
  • ngrok

About

FastAPI-based AI communication system integrating WhatsApp webhook and Gmail API with local LLM inference (Qwen)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages