Spaces:
Sleeping
title: Multi-Personality Chatbot
emoji: π
colorFrom: purple
colorTo: pink
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: mit
π Multi-Personality Chatbot
An interactive web application featuring multiple AI personalities powered by LoRA adapters fine-tuned on Qwen2-0.5B-Instruct.
π Features
- 4 Unique Personalities: Brainrot, Pirate, Yoda, and Nerd
- Interactive Web Interface: Clean Gradio-based chat UI
- Real-time Personality Switching: Change personalities on the fly
- Customizable Generation: Adjust temperature and response length
- Free Public Deployment: Deployable to Hugging Face Spaces
π Quick Start (Local Testing)
1. Install Dependencies
pip install -r requirements.txt
2. Run the App
python app.py
The app will launch at http://localhost:7860
3. Test Models (Optional)
Test individual models with the test script:
python test_model.py
π Deploy to Hugging Face Spaces (Free & Public)
See README_DEPLOYMENT.md for complete deployment instructions.
Quick version:
- Create a Space at https://huggingface.co/spaces
- Push your code:
git init git lfs install git lfs track "*.safetensors" git add . git commit -m "Initial commit" git remote add space https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME git push space main - Your app will be live at:
https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space
π Project Structure
llm-project/
βββ app.py # Main Gradio web application
βββ test_model.py # CLI testing script
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ README_DEPLOYMENT.md # Deployment guide
βββ llm_personality_brainrot.py # Training script (brainrot)
βββ llm_personality_pirate.py # Training script (pirate)
βββ llm_personality_yoda.py # Training script (yoda)
βββ llm_personality_nerd.py # Training script (nerd)
βββ qwen-brainrot-lora-stage1-final/ # LoRA adapter (brainrot)
βββ pirate-lora-adapter/ # LoRA adapter (pirate)
βββ yoda-lora-adapter/ # LoRA adapter (yoda)
βββ nerd-lora-adapter/ # LoRA adapter (nerd)
π Personality Descriptions
- π§ Brainrot: Speaks in internet slang and Gen-Z language
- π΄ββ οΈ Pirate: Talks like a swashbuckling pirate, arr matey!
- π§ Yoda: Wise Jedi master who speaks in reverse order
- π€ Nerd: Intellectual who loves facts, science, and technical details
π οΈ Technical Details
- Base Model: Qwen/Qwen2-0.5B-Instruct (500M parameters)
- Fine-tuning Method: LoRA (Low-Rank Adaptation)
- Framework: Hugging Face Transformers + PEFT
- UI: Gradio 4.x
- Training: Each personality trained on 5-250 examples
LoRA Configuration
- Rank (r): 16
- Alpha: 32
- Dropout: 0.05-0.1
- Target modules: q_proj, k_proj, v_proj, o_proj
π Usage Examples
Local Testing
# Test a specific personality
python test_model.py
# Select personality when prompted
# Chat interactively
Programmatic Use
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
# Load model
tokenizer = AutoTokenizer.from_pretrained("pirate-lora-adapter")
base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2-0.5B-Instruct")
model = PeftModel.from_pretrained(base_model, "pirate-lora-adapter")
# Generate
prompt = "<|im_start|>user\nHello!<|im_end|>\n<|im_start|>assistant\n"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_length=100)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
π§ Configuration
Edit app.py to customize:
- Temperature: Controls randomness (0.1 = focused, 2.0 = creative)
- Max Tokens: Response length limit
- Base Model: Change
BASE_MODELconstant - Adapters: Add/remove from
ADAPTERSdictionary
π Performance
- CPU: ~2-5 seconds per response (usable but slow)
- GPU (T4): ~0.5-1 seconds per response (recommended)
- Memory: ~2GB RAM (CPU) or ~4GB VRAM (GPU)
π Troubleshooting
"CUDA out of memory"
- Switch to CPU: Edit
app.py, change device to "cpu" - Or use smaller batch size
"Module not found"
pip install -r requirements.txt
"Adapter files not found"
- Ensure adapter folders are in the same directory as
app.py - Check folder names match
ADAPTERSdict inapp.py
π€ Team Collaboration
π For detailed collaboration instructions, see COLLABORATION.md
For Team Members: Updating Adapters After Deployment
Once the app is deployed to Hugging Face Spaces, team members can collaborate in several ways:
Method 1: Direct Upload on Hugging Face (Easiest)
- Get added as a collaborator on the Space (ask the Space owner)
- Go to the Space: https://huggingface.co/spaces/dianacasti/personality-chatbot
- Click "Files" tab
- To replace an adapter:
- Delete the old adapter folder (e.g.,
nerd-lora-adapter) - Click "Add file" β "Upload files"
- Upload your new adapter folder with all files:
adapter_model.safetensorsadapter_config.json- All tokenizer files
- Commit changes
- Delete the old adapter folder (e.g.,
- Space automatically rebuilds (2-5 minutes)
- Test the updated personality!
Method 2: Using Git
# Clone the Space
git clone https://huggingface.co/spaces/dianacasti/personality-chatbot
cd personality-chatbot
# Replace adapter folders with your newly trained versions
# Copy your improved: nerd-lora-adapter, yoda-lora-adapter, etc.
# Commit and push
git add .
git commit -m "Updated adapters with improved training (50+ examples)"
git push
Method 3: Upload Adapters to Hugging Face Model Hub
Upload your adapter as a model repo:
from huggingface_hub import HfApi api = HfApi() api.upload_folder( folder_path="nerd-lora-adapter", repo_id="YOUR_USERNAME/nerd-lora-improved", repo_type="model" )Update
app.pyto use the new model:ADAPTERS = { "π€ Nerd": "YOUR_USERNAME/nerd-lora-improved", # Changed # ... other adapters }Commit and push the
app.pychange
Training New/Better Adapters
To retrain a personality with more data:
- Edit the corresponding training script (e.g.,
llm_personality_nerd.py) - Increase training examples (50+ recommended instead of 5)
- Run the training script:
python llm_personality_nerd.py - Upload the new adapter folder using Method 1, 2, or 3 above
Adding New Personalities
- Create training data (20-50+ examples recommended)
- Use a personality script as template (copy
llm_personality_pirate.py) - Train the new adapter
- Add to
ADAPTERSdict inapp.py:ADAPTERS = { "π§ Brainrot": "qwen-brainrot-lora-stage1-final", "π΄ββ οΈ Pirate": "pirate-lora-adapter", "π§ Yoda": "yoda-lora-adapter", "π€ Nerd": "nerd-lora-adapter", "π€ YourNew": "yournew-lora-adapter", # Add this } - Update personality descriptions in the UI markdown
- Commit and push changes
π€ Contributing
To add a new personality:
- Create training data (20-50+ examples recommended)
- Train using a personality script as template
- Add adapter to
ADAPTERSinapp.py - Update personality descriptions in the Gradio UI
- Upload adapter folder and push changes
π License
MIT License - Feel free to use and modify!
π Acknowledgments
- Base Model: Qwen2-0.5B-Instruct by Alibaba Cloud
- Framework: Hugging Face Transformers & PEFT
- UI: Gradio by Gradio Team
- Training Dataset (Brainrot): GoofyLM/Brainrot-xK-large
π Support
For deployment help, see README_DEPLOYMENT.md
For issues, check:
- Adapter folder structure is correct
- All dependencies installed
- Model files present in adapter folders
Built with β€οΈ using Qwen2, LoRA, and Gradio