File size: 3,242 Bytes
6c4ed83
 
 
 
 
 
9aa0000
6c4ed83
 
 
 
8be2014
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9aa0000
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
---
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!