Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
datasets:
|
| 4 |
+
- tatsu-lab/alpaca
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
metrics:
|
| 8 |
+
- perplexity
|
| 9 |
+
base_model:
|
| 10 |
+
- distilbert/distilgpt2
|
| 11 |
+
pipeline_tag: text-generation
|
| 12 |
+
library_name: transformers
|
| 13 |
+
tags:
|
| 14 |
+
- chatbot
|
| 15 |
+
- instruction-tuning
|
| 16 |
+
- distilgpt2
|
| 17 |
+
- alpaca
|
| 18 |
+
- transformers
|
| 19 |
+
- fine-tuned
|
| 20 |
+
- offline
|
| 21 |
+
- flask
|
| 22 |
+
---
|
| 23 |
+
# π§ My Fine-Tuned Local Chatbot
|
| 24 |
+
|
| 25 |
+
A locally hosted AI chatbot powered by a fine-tuned **DistilGPT2** model using Hugging Face Transformers. This chatbot is trained on the **Stanford Alpaca Instruction Dataset**, enabling it to follow instructions and provide helpful responses β all without relying on internet access.
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## π Features
|
| 30 |
+
|
| 31 |
+
- π **Fully local** β no internet required after setup
|
| 32 |
+
- π§ **Fine-tuned on Stanford Alpaca-style instructions**
|
| 33 |
+
- β‘ **Fast inference** with CUDA or CPU fallback
|
| 34 |
+
- π **Flask API** with simple HTML/CSS/JavaScript frontend
|
| 35 |
+
- π¨ **Customizable prompts** and response formatting
|
| 36 |
+
- π§Ύ **Chat history** saved using SQLite
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## π Project Structure
|
| 41 |
+
|
| 42 |
+
```
|
| 43 |
+
βββ app.py # Flask API backend
|
| 44 |
+
βββ train.py # Script for fine-tuning the model
|
| 45 |
+
βββ chatbot_model/
|
| 46 |
+
β βββ trained_model_* # Your fine-tuned model directory
|
| 47 |
+
βββ static/
|
| 48 |
+
β βββ styles.css # Frontend styles
|
| 49 |
+
β βββ script.js
|
| 50 |
+
βββ templates/
|
| 51 |
+
β βββ index.html # Web UI
|
| 52 |
+
βββ requirements.txt
|
| 53 |
+
βββ README.md # You are here!
|
| 54 |
+
βββ download.py
|
| 55 |
+
βββ preprocess.py
|
| 56 |
+
βββ int_db.py
|
| 57 |
+
βββ chat_history.db # Saves history of chats
|
| 58 |
+
βββ processed_dataset.csv
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
---
|
| 62 |
+
|
| 63 |
+
## π‘ Sample Prompt
|
| 64 |
+
|
| 65 |
+
> **Human**: What is the capital of France?
|
| 66 |
+
> **Assistant**: The capital of France is Paris.
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
## ποΈββοΈ Training
|
| 71 |
+
```
|
| 72 |
+
python train.py
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
This will:
|
| 76 |
+
|
| 77 |
+
Download the Stanford Alpaca dataset
|
| 78 |
+
|
| 79 |
+
Fine-tune distilgpt2
|
| 80 |
+
|
| 81 |
+
Save it inside:
|
| 82 |
+
chatbot_model/trained_model_YYYYMMDD_HHMMSS/
|
| 83 |
+
|
| 84 |
+
---
|
| 85 |
+
|
| 86 |
+
## π₯οΈ Run the App
|
| 87 |
+
```
|
| 88 |
+
python app.py
|
| 89 |
+
```
|
| 90 |
+
Then visit: http://localhost:5005
|
| 91 |
+
|
| 92 |
+
---
|
| 93 |
+
|
| 94 |
+
## β FAQ
|
| 95 |
+
Q: Does this work offline?
|
| 96 |
+
β
Yes! Once the model is fine-tuned, no internet is needed.
|
| 97 |
+
|
| 98 |
+
Q: Can I run it on CPU?
|
| 99 |
+
β
Yes, but it will be slower. A CUDA GPU is recommended for faster responses.
|
| 100 |
+
|
| 101 |
+
Q: Can I replace the model?
|
| 102 |
+
β
Yes! You can fine-tune any Hugging Face-compatible model by modifying train.py.
|
| 103 |
+
|
| 104 |
+
---
|
| 105 |
+
|
| 106 |
+
## π οΈ Tech Stack
|
| 107 |
+
- Flask β Web server backend
|
| 108 |
+
- Transformers β Hugging Face inference
|
| 109 |
+
- PyTorch β Deep learning engine
|
| 110 |
+
- HTML/CSS/JavaScript β Frontend
|
| 111 |
+
- Stanford Alpaca Dataset
|
| 112 |
+
- SQLite β For saving chat history
|
| 113 |
+
- Python
|
| 114 |
+
|
| 115 |
+
---
|
| 116 |
+
|
| 117 |
+
## π License
|
| 118 |
+
MIT License β Free to use, modify, and share.
|
| 119 |
+
|
| 120 |
+
---
|
| 121 |
+
|
| 122 |
+
## π©βπ» Author
|
| 123 |
+
Jasleen Kaur Matharoo
|
| 124 |
+
π§ [email protected]
|
| 125 |
+
π GitHub @Jasleen-05
|