|
--- |
|
title: Mixtral Trait‑Controlled Chatbot |
|
emoji: 🎭 |
|
colorFrom: pink |
|
colorTo: blue |
|
sdk: gradio |
|
sdk_version: 5.44.1 |
|
app_file: app.py |
|
pinned: false |
|
--- |
|
|
|
# Mixtral Trait‑Controlled Chatbot Space |
|
|
|
This Hugging Face Space provides an interactive chat interface based on the |
|
[`mistralai/Mixtral-8x7B-Instruct-v0.1`](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1) |
|
model. It allows users to blend stylistic LoRA adapters (witty, charming, |
|
sarcastic, neutral) by adjusting slider weights and generates a response that |
|
reflects the selected blend. |
|
|
|
## Files |
|
|
|
- **`app.py`** – Main application code using Gradio. It loads the base model, |
|
retrieves the LoRA state dicts from the Hub, blends them according to user |
|
weights and generates a response. |
|
- **`requirements.txt`** – Python dependencies needed by the Space. The |
|
environment will be created automatically when you push the repository to |
|
Hugging Face. |
|
- **`README.md`** – This document, explaining how to set up and use the Space. |
|
|
|
## Setup Instructions |
|
|
|
1. **Train and push your adapters** |
|
|
|
First, train four LoRA adapters (witty, charming, sarcastic, neutral) on |
|
your dataset and push each adapter to the Hugging Face Hub. You can use |
|
the fine‑tuning notebook provided earlier to train and push the adapters. |
|
Each adapter should reside in its own repository, e.g.: |
|
|
|
- `your-username/mixtral-lora-witty` |
|
- `your-username/mixtral-lora-charming` |
|
- `your-username/mixtral-lora-sarcastic` |
|
- `your-username/mixtral-lora-neutral` |
|
|
|
2. **Create a new Space** |
|
|
|
- Go to your Hugging Face profile and create a new Space. |
|
- Choose **Gradio** as the Space SDK. |
|
|
|
3. **Upload the files** |
|
|
|
Clone the new Space repository locally (or use the web interface) and add the |
|
following files from this folder: |
|
|
|
- `app.py` |
|
- `requirements.txt` |
|
- `README.md` |
|
|
|
Commit and push the changes. |
|
|
|
4. **Configure adapter repos** |
|
|
|
In `app.py` locate the `ADAPTER_REPOS` dictionary and replace the |
|
placeholder repository IDs with the actual names of your adapter repos. For |
|
example: |
|
|
|
```python |
|
ADAPTER_REPOS = { |
|
"witty": "myuser/mixtral-lora-witty", |
|
"charming": "myuser/mixtral-lora-charming", |
|
"sarcastic": "myuser/mixtral-lora-sarcastic", |
|
"neutral": "myuser/mixtral-lora-neutral", |
|
} |
|
``` |
|
|
|
You do not need to hard‑code a token for reading from public repos. |
|
|
|
5. **Launch the Space** |
|
|
|
When you push the Space, Hugging Face will install the dependencies and |
|
start the Gradio app. If the Space has GPU hardware, the model will load |
|
faster; otherwise it will run on CPU but may be slower. Once it is |
|
running, you can open the Space in your browser, type a prompt, adjust the |
|
weights and click **Generate** to see the blended output. |
|
|
|
## Tips |
|
|
|
- The LoRA adapters are loaded lazily; the first request for each trait may |
|
take a few seconds. Subsequent requests reuse the cached deltas. |
|
- We normalise the weights so they sum to 1. If all weights are set to zero, |
|
the response defaults to the neutral adapter. |
|
- Feel free to adjust `max_new_tokens` in `generate_response` to change the |
|
length of the output. |
|
|
|
Enjoy experimenting with different combinations of traits! |