Spaces:
Build error
Build error
File size: 5,649 Bytes
e400111 c487b8d e400111 c487b8d e400111 c487b8d e400111 c487b8d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
---
title: 6.S041 Staff Chatbot
emoji: π
colorFrom: blue
colorTo: red
sdk: gradio
sdk_version: 5.23.3
python_version: "3.10"
app_file: app.py
pinned: false
secrets:
- HF_TOKEN
---
# Boston Public School Selection Chatbot
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.
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!
Note: We encourage you to use AI tools (like Cursor or LLMs) to help you on this assignment. Learn how to leverage these tools.
## Setup
1. Make a virtual environment and install the required dependencies:
```bash
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
2. Make a HuggingFace account and make an access token:
- Visit [Hugging Face](https://huggingface.co)
- Make an account if you don't already have one
- Click on your profile, then "Access Tokens" and make a new token
- Make a .env file with `HF_TOKEN=<insert your token here>`
- Now, log in to Hugging Face in the terminal as well:
```bash
huggingface-cli login
```
3. Choose a base model:
- In config.py, set the BASE_MODEL variable to your base model of choice from HuggingFace.
- Keep in mind it's better to have a small, lightweight model if you plan on finetuning.
## Repository Organization
```
6.s041-chatbot/
βββ app.py # Gradio web interface - implement the chat function
βββ requirements.txt # Python dependencies
βββ chatbot_development.ipynb # Notebook for developing and testing your chatbot
βββ .env # Add this file yourself for storing your HF_TOKEN
βββ config.py # Holds variables for the models from HuggingFace you will use
βββ chatbot_conversation_example.txt # Example conversation we might want to have with this chatbot
βββ src/
βββ chat.py # SchoolChatbot class (implement this)
```
### Key Files:
- **app.py**: Creates the web interface using Gradio. You only need to implement the `chat` function that generates responses.
- **chat.py**: Contains the `SchoolChatbot` class where you'll implement:
- `format_prompt`: Format user input into proper prompts
- `get_response`: Generate responses using the model
- **config.py**: Contains the `BASE_MODEL` and `MY_MODEL` variables, which are names of models on HuggingFace. Update the `MY_MODEL` variable if you create a new model and upload it to the HuggingFace Hub.
- **chatbot_development.ipynb**: Jupyter notebook for:
- Experimenting with the chatbot
- Trying different approaches
- Testing responses before deployment
### What You Need to Implement:
1. In `chat.py`:
- Complete the `SchoolChatbot` class methods
- Design how the chatbot formats prompts
- Implement response generation
2. In `app.py`:
- Implement the `chat` function to work with Gradio
- The rest of the file is already set up
3. Use `chatbot_development.ipynb` to:
- Develop and test your implementation
- Try different approaches
- Verify everything works before deployment
4. After you update the code, you can run the chatbot locally:
```bash
python app.py
```
## Deploying to Hugging Face
To deploy your chatbot as a free web interface using Hugging Face Spaces:
1. Create a Hugging Face Space:
- Go to [Hugging Face Spaces](https://huggingface.co/spaces)
- Click "New Space"
- Choose a name for your space (e.g., "boston-school-chatbot")
- Select "Gradio" as the SDK
- Choose "CPU" as the hardware (free tier)
- Make it "Public" so others can use your chatbot
2. Prepare your files:
Your repository should already have all needed files:
```
6.so41-midterm/
βββ README.md # Description of your chatbot
βββ app.py # Your Gradio interface
βββ requirements.txt # Already set up with needed dependencies
βββ src/ # Your implementation files
```
3. Push your code to the Space:
```bash
git init
git add .
git commit -m "Initial commit"
git remote add origin https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
git push -u origin main
```
4. Add your HF_TOKEN to the space as a secret.
- Go to Files.
- Go to Settings.
- Under secrets, add HF_TOKEN.
5. Important Free Tier Considerations:
- Use free tier model (already configured in model.py)
- Free CPU spaces have 2GB RAM limit
- The interface might queue requests when multiple users access it. Sometimes there will be 503 errors.
6. After Deployment:
- Your chatbot will be available at: `https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME`
- Anyone can use it through their web browser
- You can update the deployment anytime by pushing changes:
```bash
git add .
git commit -m "Update chatbot"
git push
```
7. Troubleshooting:
- Check the Space's logs if the chatbot isn't working
- Verify the chatbot works locally before deploying
- 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.
Your chatbot should now be accessible to anyone through their web browser!
|