ββββββββββββββββ βββββββββββββββββββββββ ββββββββββββββββββββββββ
β 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) β
ββββββββββββββββββββββββ
| 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 |
| 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 |
- Python 3.9 or higher
- Node.js 18 or higher
- pip and npm
# 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
# 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.
| 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 |
curl -X POST https://hamza0426-chatbot-backend.hf.space/chat \
-H "Content-Type: application/json" \
-d '{"query": "What are the symptoms of flu?"}'{
"response": "Flu symptoms include fever, cough, sore throat, runny nose, body aches, and fatigue.",
"source": "model"
}| 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 |
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
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.
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.
Made with β€οΈ by Hamza β Domain-Specific AI Chatbot