--- 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 ```powershell pip install -r requirements.txt ``` ### 2. Run the App ```powershell python app.py ``` The app will launch at `http://localhost:7860` ### 3. Test Models (Optional) Test individual models with the test script: ```powershell python test_model.py ``` ## 🌐 Deploy to Hugging Face Spaces (Free & Public) See **[README_DEPLOYMENT.md](README_DEPLOYMENT.md)** for complete deployment instructions. **Quick version:** 1. Create a Space at https://huggingface.co/spaces 2. Push your code: ```powershell 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 ``` 3. 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 ```python # Test a specific personality python test_model.py # Select personality when prompted # Chat interactively ``` ### Programmatic Use ```python 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_MODEL` constant - **Adapters**: Add/remove from `ADAPTERS` dictionary ## 📊 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" ```powershell pip install -r requirements.txt ``` ### "Adapter files not found" - Ensure adapter folders are in the same directory as `app.py` - Check folder names match `ADAPTERS` dict in `app.py` ## 🤝 Team Collaboration > **📚 For detailed collaboration instructions, see [COLLABORATION.md](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) 1. Get added as a **collaborator** on the Space (ask the Space owner) 2. Go to the Space: https://huggingface.co/spaces/dianacasti/personality-chatbot 3. Click **"Files"** tab 4. 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.safetensors` - `adapter_config.json` - All tokenizer files - Commit changes 5. Space automatically rebuilds (2-5 minutes) 6. Test the updated personality! #### Method 2: Using Git ```powershell # 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 1. Upload your adapter as a model repo: ```python 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" ) ``` 2. Update `app.py` to use the new model: ```python ADAPTERS = { "🤓 Nerd": "YOUR_USERNAME/nerd-lora-improved", # Changed # ... other adapters } ``` 3. Commit and push the `app.py` change ### Training New/Better Adapters To retrain a personality with more data: 1. Edit the corresponding training script (e.g., `llm_personality_nerd.py`) 2. Increase training examples (50+ recommended instead of 5) 3. Run the training script: `python llm_personality_nerd.py` 4. Upload the new adapter folder using Method 1, 2, or 3 above ### Adding New Personalities 1. Create training data (20-50+ examples recommended) 2. Use a personality script as template (copy `llm_personality_pirate.py`) 3. Train the new adapter 4. Add to `ADAPTERS` dict in `app.py`: ```python 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 } ``` 5. Update personality descriptions in the UI markdown 6. Commit and push changes ## 🤝 Contributing To add a new personality: 1. Create training data (20-50+ examples recommended) 2. Train using a personality script as template 3. Add adapter to `ADAPTERS` in `app.py` 4. Update personality descriptions in the Gradio UI 5. 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](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