Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

HamChat

HamChat β€” Domain-Specific AI Chatbot

Fine-tune a T5 model. Ask it anything. Get domain-aware answers in real-time.

Live Demo HuggingFace GitHub

Python Flask React T5 PyTorch Transformers Deployed


πŸ“Έ Screenshots

🏠 Landing Page

Landing Page - Hero Landing Page - About Section Landing Page - Sample Questions Landing Page - Footer

πŸ’¬ Chat Interface

Chat Interface - Welcome Chat Interface - Healthcare Query Chat Interface - Finance Query Chat Interface - Suggestions

πŸ”· How It Works

 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚  User Query  β”‚ ──▢ β”‚   Custom Rule Check  β”‚ ──▢ β”‚  Domain Keyword Check β”‚
 β”‚  (typed text)β”‚     β”‚  (identity/greetings)β”‚     β”‚  (healthcare/finance) β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                              β”‚
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β–Ό
 β”‚  React UI    β”‚ ◀── β”‚   Flask REST API     β”‚ ◀── β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚  HamChat     β”‚     β”‚   JSON Response      β”‚     β”‚  Fine-tuned T5 Model  β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚  Beam Search (n=5)    β”‚
                                                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

Feature Description
πŸ€– Fine-tuned T5 T5-small fine-tuned on 3,000 Healthcare & Finance Q&A pairs
πŸ’Š Healthcare Domain Appointments, medications, flu symptoms, vaccine side effects
πŸ’³ Finance Domain Account balance, loans, credit cards, interest rates
🧠 Custom Rules Layer Identity, greetings and creator questions handled before the model runs
🚫 Smart Fallback Out-of-scope questions get a helpful redirect instead of wrong answers
πŸ’¬ Persistent Chat History Conversation stays intact when navigating back to the home page
🎨 Two-Page UI Professional landing page + dedicated chat interface
⚑ Suggested Questions Clickable chips so users always know what to ask
πŸ”„ Reset Chat One-click clear to start a fresh conversation
πŸ“± Fully Responsive Works cleanly on desktop, tablet, and mobile screens

πŸ—οΈ Tech Stack

Layer Technology Purpose
Frontend React 18 + CSS UI Dashboard
Backend Flask + Python 3.10 REST API Server
ML Model T5-Small (Hugging Face) Text Generation
Training Hugging Face Trainer API Fine-Tuning Pipeline
Framework PyTorch Deep Learning Backend
Tokenizer T5Tokenizer (SentencePiece) Text Preprocessing
Frontend Host Vercel Auto-deploy from GitHub
Backend Host Hugging Face Spaces (Docker) Flask API Hosting
Model Weights Hugging Face Hub Model Storage & Download

πŸš€ Getting Started

Prerequisites

  • Python 3.9 or higher
  • Node.js 18 or higher
  • pip and npm

βš™οΈ Backend Setup

# 1. Clone the repository
git clone https://github.com/hamza0426/Domain-Specific-Chatbot.git
cd Domain-Specific-Chatbot/backend

# 2. Install Python dependencies
pip install flask flask-cors transformers torch sentencepiece

# 3. Start the backend server
python app.py

βœ… Backend live at http://localhost:5000 πŸ“‘ Health check at http://localhost:5000/health


πŸ–₯️ Frontend Setup

# 1. Navigate to frontend directory
cd frontend

# 2. Install dependencies
npm install

# 3. Start the development server
npm start

βœ… Frontend live at http://localhost:3000

Note: Make sure the backend is running on port 5000 before starting the frontend.
For the live version, the frontend connects to the deployed backend on Hugging Face Spaces automatically.


πŸ“‘ API Endpoints

Method Endpoint Description
GET / API info and available endpoints
POST /chat Send a query β€” returns model response + source tag
GET /health Check if the model is loaded and API is alive
GET /suggestions Get sample questions grouped by domain

Example Request

curl -X POST https://hamza0426-chatbot-backend.hf.space/chat \
  -H "Content-Type: application/json" \
  -d '{"query": "What are the symptoms of flu?"}'

Example Response

{
  "response": "Flu symptoms include fever, cough, sore throat, runny nose, body aches, and fatigue.",
  "source": "model"
}

🧠 Model Training Details

Parameter Value
Base Model t5-small
Dataset Size 3,000 samples
Domains Healthcare, Finance
Unique Intents 10
Train / Val Split 80% / 20%
Epochs 10
Batch Size 8
Max Length 250 tokens
Warmup Steps 500
Weight Decay 0.01
Final Train Loss ~0.001

πŸ“ Project Structure

Domain-Specific-Chatbot/
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app.py                  # Flask API β€” inference, custom rules, fallback logic
β”‚   β”œβ”€β”€ requirements.txt        # Python dependencies
β”‚   β”œβ”€β”€ Dockerfile              # Docker config for Hugging Face Spaces
β”‚   └── chatbot_model/          # Fine-tuned T5 weights (not in GitHub)
β”‚                               # β†’ Loaded from Hugging Face Hub at runtime
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx             # Router β€” switches between Home and Chat
β”‚   β”‚   β”œβ”€β”€ Home.jsx            # Landing page component
β”‚   β”‚   β”œβ”€β”€ Home.css            # Landing page styles
β”‚   β”‚   β”œβ”€β”€ Chat.jsx            # Chat interface component
β”‚   β”‚   β”œβ”€β”€ Chat.css            # Chat interface styles
β”‚   β”‚   β”œβ”€β”€ index.css           # Global CSS variables and reset
β”‚   β”‚   └── index.js            # React entry point
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   └── index.html
β”‚   └── package.json
β”‚
β”œβ”€β”€ .gitignore
└── README.md

🌐 Deployment Architecture

 GitHub Repo
      β”‚
      β”œβ”€β”€β”€β”€ Vercel ─────────────────▢  Frontend (React 18)
      β”‚     Auto-deploy on push         https://domain-specific-chatbot-hamza.vercel.app
      β”‚
      └──── Hugging Face Spaces ──────▢  Backend (Flask + Docker)
            Manual push                   https://hamza0426-chatbot-backend.hf.space
                  β”‚
                  └── Hugging Face Hub ─▢  T5 Model Weights
                                            Auto-downloaded at container startup

⚠️ Note: Hugging Face free tier may take 30–60 seconds to wake up on first request if idle.
Subsequent requests are instant once the container is warm.


πŸ‘¨β€πŸ’» Author

Muhammad Hamza Owais

Computer Science Graduate β€” passionate developer continuously learning AI, automation, and new technologies. Completed Bachelor's in Computer Science with a strong focus on building practical, full-stack AI-powered applications. Always eager to explore what's next in the world of machine learning and software engineering.

GitHub LinkedIn


Made with ❀️ by Hamza β€” Domain-Specific AI Chatbot

visitors

About

This is a domain specific chatbot made using python and fine-tuning the model

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages