--- license: apache-2.0 datasets: - tatsu-lab/alpaca language: - en base_model: - distilbert/distilgpt2 pipeline_tag: text-generation library_name: transformers tags: - chatbot - instruction-tuning - distilgpt2 - alpaca - transformers - fine-tuned - offline - flask --- # ๐Ÿง  My Fine-Tuned Local Chatbot 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. --- ## ๐Ÿš€ Features - ๐Ÿ”’ **Fully local** โ€“ no internet required after setup - ๐Ÿง  **Fine-tuned on Stanford Alpaca-style instructions** - โšก **Fast inference** with CUDA or CPU fallback - ๐ŸŒ **Flask API** with simple HTML/CSS/JavaScript frontend - ๐ŸŽจ **Customizable prompts** and response formatting - ๐Ÿงพ **Chat history** saved using SQLite - Dataset Used: [Stanford Alpaca](https://github.com/tatsu-lab/stanford_alpaca) --- ## ๐Ÿ“‚ Project Structure ``` โ”œโ”€โ”€ app.py # Flask API backend โ”œโ”€โ”€ train.py # Script for fine-tuning the model โ”œโ”€โ”€ chatbot_model/ โ”‚ โ””โ”€โ”€ trained_model_* # Your fine-tuned model directory โ”œโ”€โ”€ static/ โ”‚ โ”œโ”€โ”€ styles.css # Frontend styles โ”‚ โ””โ”€โ”€ script.js โ”œโ”€โ”€ templates/ โ”‚ โ””โ”€โ”€ index.html # Web UI โ”œโ”€โ”€ requirements.txt โ”œโ”€โ”€ README.md # You are here! โ”œโ”€โ”€ download.py โ”œโ”€โ”€ preprocess.py โ”œโ”€โ”€ int_db.py โ”œโ”€โ”€ chat_history.db # Saves history of chats โ””โ”€โ”€ processed_dataset.csv ``` --- ## Demo ![image/png](https://cdn-uploads.huggingface.co/production/uploads/686acf52adf0f81a9ece24c7/vqXOBxgQKlMwSMEiatZlK.png) --- ## ๐Ÿ’ก Sample Prompt > **Human**: What is the capital of France? > **Assistant**: The capital of France is Paris. --- ## ๐Ÿ‹๏ธโ€โ™€๏ธ Training ``` python train.py ``` This will: Download the Stanford Alpaca dataset Fine-tune distilgpt2 Save it inside: chatbot_model/trained_model_YYYYMMDD_HHMMSS/ --- ## ๐Ÿ–ฅ๏ธ Run the App ``` python app.py ``` Then visit: http://localhost:5005 --- ## โ“ FAQ Q: Does this work offline? โœ… Yes! Once the model is fine-tuned, no internet is needed. Q: Can I run it on CPU? โœ… Yes, but it will be slower. A CUDA GPU is recommended for faster responses. Q: Can I replace the model? โœ… Yes! You can fine-tune any Hugging Face-compatible model by modifying train.py. --- ## ๐Ÿ› ๏ธ Tech Stack - Flask โ€“ Web server backend - Transformers โ€“ Hugging Face inference - PyTorch โ€“ Deep learning engine - HTML/CSS/JavaScript โ€“ Frontend - Stanford Alpaca Dataset - SQLite โ€“ For saving chat history - Python --- ## ๐Ÿ“œ License MIT License โ€“ Free to use, modify, and share. --- ## ๐Ÿ‘ฉโ€๐Ÿ’ป Author Jasleen Kaur Matharoo ๐Ÿ“ง jasleen.matharoo@s.amity.edu ๐ŸŒ GitHub @Jasleen-05