Sarah Bentley
commited on
Commit
Β·
a2f999a
1
Parent(s):
91b6bd5
cleaning up repo
Browse files- .gitignore +2 -1
- README.md +16 -10
- app.py +1 -1
- chatbot_development.ipynb +5 -49
- src/chat.py +1 -2
.gitignore
CHANGED
|
@@ -3,4 +3,5 @@ __pycache__/
|
|
| 3 |
.env
|
| 4 |
*.pyc
|
| 5 |
.ipynb_checkpoints/
|
| 6 |
-
models/
|
|
|
|
|
|
| 3 |
.env
|
| 4 |
*.pyc
|
| 5 |
.ipynb_checkpoints/
|
| 6 |
+
models/
|
| 7 |
+
.gitattributes
|
README.md
CHANGED
|
@@ -14,9 +14,9 @@ secrets:
|
|
| 14 |
|
| 15 |
# Boston Public School Selection Chatbot
|
| 16 |
|
| 17 |
-
This is a skeleton repo you can use to design
|
| 18 |
|
| 19 |
-
The end goal: make the chatbot and upload it to a
|
| 20 |
|
| 21 |
Note: We encourage you to use AI tools (like Cursor or LLMs) to help you on this assignment. Learn how to leverage these tools.
|
| 22 |
|
|
@@ -43,7 +43,7 @@ pip install -r requirements.txt
|
|
| 43 |
- In config.py, set the BASE_MODEL variable to your base model of choice from HuggingFace.
|
| 44 |
- Keep in mind it's better to have a small, lightweight model if you plan on finetuning.
|
| 45 |
|
| 46 |
-
3.
|
| 47 |
```bash
|
| 48 |
python app.py
|
| 49 |
```
|
|
@@ -79,13 +79,18 @@ To deploy your chatbot as a free web interface using Hugging Face Spaces:
|
|
| 79 |
git push -u origin main
|
| 80 |
```
|
| 81 |
|
| 82 |
-
4.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
- Use free tier model (already configured in model.py)
|
| 84 |
- Free CPU spaces have 2GB RAM limit
|
| 85 |
-
-
|
| 86 |
-
- The interface might queue requests when multiple users access it
|
| 87 |
|
| 88 |
-
|
| 89 |
- Your chatbot will be available at: `https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME`
|
| 90 |
- Anyone can use it through their web browser
|
| 91 |
- You can update the deployment anytime by pushing changes:
|
|
@@ -95,11 +100,10 @@ To deploy your chatbot as a free web interface using Hugging Face Spaces:
|
|
| 95 |
git push
|
| 96 |
```
|
| 97 |
|
| 98 |
-
|
| 99 |
- Check the Space's logs if the chatbot isn't working
|
| 100 |
-
- Make sure you're using TinyLlama model
|
| 101 |
- Verify the chatbot works locally before deploying
|
| 102 |
-
- Remember free tier has limited resources
|
| 103 |
|
| 104 |
Your chatbot should now be accessible to anyone through their web browser!
|
| 105 |
|
|
@@ -110,6 +114,8 @@ boston-school-chatbot/
|
|
| 110 |
βββ app.py # Gradio web interface - implement the chat function
|
| 111 |
βββ requirements.txt # Python dependencies
|
| 112 |
βββ chatbot_development.ipynb # Notebook for developing and testing your chatbot
|
|
|
|
|
|
|
| 113 |
βββ chatbot_conversation_example.txt # Example conversation we might want to have with this chatbot
|
| 114 |
βββ src/
|
| 115 |
βββ model.py # Model loading/saving (already implemented)
|
|
|
|
| 14 |
|
| 15 |
# Boston Public School Selection Chatbot
|
| 16 |
|
| 17 |
+
This is a skeleton repo you can use to design your school choice chatbot. Feel free to change it however you'd like! This repo is compatible with CPU (using your own computer) because it uses models on HuggingFace. You can also load models locally if you'd like, but we recommend using smaller ones.
|
| 18 |
|
| 19 |
+
The end goal: make the chatbot and upload it to a Huggingface Space. We have included instructions for using HuggingFace below. [Here's an example](https://huggingface.co/spaces/sbentley/Boston-School-Choice) of a chatbot made by the course staff. Yours should be much better!
|
| 20 |
|
| 21 |
Note: We encourage you to use AI tools (like Cursor or LLMs) to help you on this assignment. Learn how to leverage these tools.
|
| 22 |
|
|
|
|
| 43 |
- In config.py, set the BASE_MODEL variable to your base model of choice from HuggingFace.
|
| 44 |
- Keep in mind it's better to have a small, lightweight model if you plan on finetuning.
|
| 45 |
|
| 46 |
+
3. After you update the code, you can run the chatbot locally:
|
| 47 |
```bash
|
| 48 |
python app.py
|
| 49 |
```
|
|
|
|
| 79 |
git push -u origin main
|
| 80 |
```
|
| 81 |
|
| 82 |
+
4. Add your HF_TOKEN to the space as a secret.
|
| 83 |
+
- Go to Files.
|
| 84 |
+
- Go to Settings.
|
| 85 |
+
- Under secrets, add HF_TOKEN.
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
5. Important Free Tier Considerations:
|
| 89 |
- Use free tier model (already configured in model.py)
|
| 90 |
- Free CPU spaces have 2GB RAM limit
|
| 91 |
+
- The interface might queue requests when multiple users access it. Sometimes there will be 503 errors.
|
|
|
|
| 92 |
|
| 93 |
+
6. After Deployment:
|
| 94 |
- Your chatbot will be available at: `https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME`
|
| 95 |
- Anyone can use it through their web browser
|
| 96 |
- You can update the deployment anytime by pushing changes:
|
|
|
|
| 100 |
git push
|
| 101 |
```
|
| 102 |
|
| 103 |
+
7. Troubleshooting:
|
| 104 |
- Check the Space's logs if the chatbot isn't working
|
|
|
|
| 105 |
- Verify the chatbot works locally before deploying
|
| 106 |
+
- Remember free tier has limited resources. Sometimes if you get a 503 error it means the server is overloaded. Just try again a few seconds later.
|
| 107 |
|
| 108 |
Your chatbot should now be accessible to anyone through their web browser!
|
| 109 |
|
|
|
|
| 114 |
βββ app.py # Gradio web interface - implement the chat function
|
| 115 |
βββ requirements.txt # Python dependencies
|
| 116 |
βββ chatbot_development.ipynb # Notebook for developing and testing your chatbot
|
| 117 |
+
βββ .env # Add this file yourself for storing your HF_TOKEN
|
| 118 |
+
βββ config.py # Holds variables for the models from HuggingFace you will use
|
| 119 |
βββ chatbot_conversation_example.txt # Example conversation we might want to have with this chatbot
|
| 120 |
βββ src/
|
| 121 |
βββ model.py # Model loading/saving (already implemented)
|
app.py
CHANGED
|
@@ -73,7 +73,7 @@ def create_chatbot():
|
|
| 73 |
demo = gr.ChatInterface(
|
| 74 |
chat,
|
| 75 |
title="Boston Public School Selection Assistant",
|
| 76 |
-
description="Ask me anything about Boston public schools!",
|
| 77 |
examples=[
|
| 78 |
"I live in Jamaica Plain and want to send my child to kindergarten. What schools are available?"
|
| 79 |
]
|
|
|
|
| 73 |
demo = gr.ChatInterface(
|
| 74 |
chat,
|
| 75 |
title="Boston Public School Selection Assistant",
|
| 76 |
+
description="Ask me anything about Boston public schools! Since I am a free tier chatbot, I may give a 503 error when I'm busy. If that happens, please try again in a few minutes.",
|
| 77 |
examples=[
|
| 78 |
"I live in Jamaica Plain and want to send my child to kindergarten. What schools are available?"
|
| 79 |
]
|
chatbot_development.ipynb
CHANGED
|
@@ -32,24 +32,9 @@
|
|
| 32 |
},
|
| 33 |
{
|
| 34 |
"cell_type": "code",
|
| 35 |
-
"execution_count":
|
| 36 |
"metadata": {},
|
| 37 |
-
"outputs": [
|
| 38 |
-
{
|
| 39 |
-
"data": {
|
| 40 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 41 |
-
"model_id": "63c9729c691a473fb7a01af4521af4a2",
|
| 42 |
-
"version_major": 2,
|
| 43 |
-
"version_minor": 0
|
| 44 |
-
},
|
| 45 |
-
"text/plain": [
|
| 46 |
-
"VBox(children=(HTML(value='<center> <img\\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.svβ¦"
|
| 47 |
-
]
|
| 48 |
-
},
|
| 49 |
-
"metadata": {},
|
| 50 |
-
"output_type": "display_data"
|
| 51 |
-
}
|
| 52 |
-
],
|
| 53 |
"source": [
|
| 54 |
"\"\"\"\n",
|
| 55 |
"TODO: Add your Hugging Face token\n",
|
|
@@ -84,44 +69,15 @@
|
|
| 84 |
},
|
| 85 |
{
|
| 86 |
"cell_type": "code",
|
| 87 |
-
"execution_count":
|
| 88 |
"metadata": {},
|
| 89 |
-
"outputs": [
|
| 90 |
-
{
|
| 91 |
-
"name": "stdout",
|
| 92 |
-
"output_type": "stream",
|
| 93 |
-
"text": [
|
| 94 |
-
"\n",
|
| 95 |
-
"Question: I live in Jamaica Plain and want to send my child to a school that offers Spanish programs. What schools are available?\n",
|
| 96 |
-
"Response: Sure! Here are some options for your area:\n",
|
| 97 |
-
" 1) The Academy of the Holy Angels (AHAs): They offer classes in both English and Spanish, as well as various extracurricular activities like music and dance programs.\n",
|
| 98 |
-
" 2) New England Preparatory School: They have a Spanish Immersion Program which allows students to learn language skills while also studying traditional subjects such as math, science, and history.\n",
|
| 99 |
-
"\n",
|
| 100 |
-
"\n",
|
| 101 |
-
"7. Testimonials or success stories from previous clients\n",
|
| 102 |
-
"\n",
|
| 103 |
-
"- Client #1: \"I highly recommend you to anyone looking for an effective way to find the best schools in their area.\"\n",
|
| 104 |
-
"- Customer #5: \"You were able to quickly identify several excellent schools for our son after we had been struggling with finding the right fit. We are very grateful!\"\n",
|
| 105 |
-
"\n",
|
| 106 |
-
"8. Feedback survey\n",
|
| 107 |
-
"\n",
|
| 108 |
-
"Here's a sample feedback survey that can be used to gather customer feedback on your service:\n",
|
| 109 |
-
"\n",
|
| 110 |
-
"Please rate your overall experience using our website/app by selecting one of the following categories:\n",
|
| 111 |
-
"- Excellent / Very Good\n",
|
| 112 |
-
"- Good\n",
|
| 113 |
-
" - Adequate\n",
|
| 114 |
-
"- Poor / Terrible\n",
|
| 115 |
-
" Please let us know what could have improved this experience:\n"
|
| 116 |
-
]
|
| 117 |
-
}
|
| 118 |
-
],
|
| 119 |
"source": [
|
| 120 |
"\"\"\"\n",
|
| 121 |
"Test out generating some responses from the chatbot.\n",
|
| 122 |
"Inference time\n",
|
| 123 |
"\"\"\"\n",
|
| 124 |
-
"test_question = \"I live in Jamaica Plain and want to send my child to a school that offers Spanish
|
| 125 |
"\n",
|
| 126 |
"print(f\"\\nQuestion: {test_question}\")\n",
|
| 127 |
"response = chatbot.get_response(test_question)\n",
|
|
|
|
| 32 |
},
|
| 33 |
{
|
| 34 |
"cell_type": "code",
|
| 35 |
+
"execution_count": null,
|
| 36 |
"metadata": {},
|
| 37 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
"source": [
|
| 39 |
"\"\"\"\n",
|
| 40 |
"TODO: Add your Hugging Face token\n",
|
|
|
|
| 69 |
},
|
| 70 |
{
|
| 71 |
"cell_type": "code",
|
| 72 |
+
"execution_count": null,
|
| 73 |
"metadata": {},
|
| 74 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
"source": [
|
| 76 |
"\"\"\"\n",
|
| 77 |
"Test out generating some responses from the chatbot.\n",
|
| 78 |
"Inference time\n",
|
| 79 |
"\"\"\"\n",
|
| 80 |
+
"test_question = \"I live in Jamaica Plain and want to send my child to a school that offers Spanish classes. What schools are available?\"\n",
|
| 81 |
"\n",
|
| 82 |
"print(f\"\\nQuestion: {test_question}\")\n",
|
| 83 |
"response = chatbot.get_response(test_question)\n",
|
src/chat.py
CHANGED
|
@@ -78,10 +78,9 @@ class SchoolChatbot:
|
|
| 78 |
print("Generating response...")
|
| 79 |
response = self.client.text_generation(
|
| 80 |
prompt,
|
| 81 |
-
max_new_tokens=
|
| 82 |
temperature=0.7,
|
| 83 |
top_p=0.95,
|
| 84 |
-
repetition_penalty=1.2,
|
| 85 |
do_sample=True,
|
| 86 |
return_full_text=False
|
| 87 |
)
|
|
|
|
| 78 |
print("Generating response...")
|
| 79 |
response = self.client.text_generation(
|
| 80 |
prompt,
|
| 81 |
+
max_new_tokens=300,
|
| 82 |
temperature=0.7,
|
| 83 |
top_p=0.95,
|
|
|
|
| 84 |
do_sample=True,
|
| 85 |
return_full_text=False
|
| 86 |
)
|