Spaces:
Sleeping
Sleeping
metadata
title: AI Chatbot Site
emoji: π€
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
π€ Zephyr-7B Chatbot fΓΌr Hugging Face Spaces
Ein vollstΓ€ndiges React-Frontend mit Python-Backend fΓΌr KI-Inferenz auf Hugging Face Spaces. Mit integriertem Plugin-System fΓΌr einfache Erweiterbarkeit.
π― Features
- Zephyr-7B-Beta Modell - Schnell, optimiert, auf VRAM-Limited Spaces
- React + Vite Frontend - Modernes, responsives UI
- Gradio Backend - Einfaches Deployment auf HF Spaces
- Plugin-System - Einfach neue JS-Dateien in
/pluginspacken und sie werden automatisch geladen - Live Streaming - Token-by-Token Responses (optional ausbaubar)
- Mehrsprachig - DE/EN ready
π Quick Start
Lokal testen
- Requirements installieren:
pip install -r requirements.txt
- Backend starten:
python app.py
Das Backend lΓ€uft dann auf http://localhost:7860
- React Frontend (neuer Terminal):
npm install
npm run dev
Frontend lΓ€uft auf http://localhost:5173
π¦ Build fΓΌr HF Spaces
- React Build:
npm run build
Erzeugt dist/ Ordner
- Hochladen zu HF Spaces:
# Space erstellen auf huggingface.co/spaces
# Dann:
git clone https://huggingface.co/spaces/USERNAME/SPACE-NAME
cd SPACE-NAME
# Dateien kopieren:
cp app.py .
cp requirements.txt .
cp -r plugins/ .
cp -r dist/ . # (optional, wenn du static files servieren willst)
- Commit & Push:
git add .
git commit -m "Initial commit"
git push
Die Spaces wird automatisch deployt!
π Projektstruktur
AI_Chatbot_Site/
βββ app.py # Gradio Backend (HF Spaces Einstiegspunkt)
βββ requirements.txt # Python Dependencies
βββ package.json # Node Dependencies
βββ vite.config.js # Vite Konfiguration
β
βββ src/
β βββ main.jsx # React Entry Point
β βββ App.jsx # Main App Component
β βββ App.css # App Styles
β βββ index.css # Global Styles
β β
β βββ components/
β β βββ ChatBox.jsx # Chat UI Component
β β βββ ChatBox.css
β β βββ PluginLoader.jsx # Plugin System
β β βββ plugins/ # Plugins Ordner
β β
β βββ utils/
β βββ api.js # API Client
β βββ pluginManager.js # Plugin Management
β
βββ public/
β βββ index.html
β
βββ plugins/
βββ example-logger.js # Example Plugin
π Plugin-System
Ein neues Plugin erstellen
Erstelle eine neue Datei in plugins/myplugin.js:
// plugins/myplugin.js
export function onPluginInit(context) {
context.log('My plugin initialized!')
}
export function onMessageSent(context, { message, systemPrompt }) {
context.log(`User sent: ${message}`)
// Hier kannst du:
// - Analytics tracken
// - Daten speichern
// - API calls machen
// - Etc.
}
export function onResponseReceived(context, { content, stats }) {
context.log(`Response: ${content.substring(0, 50)}...`)
context.log(`Stats: ${JSON.stringify(stats)}`)
}
Das Plugin wird automatisch geladen wenn die App startet!
Plugin Hooks
| Hook | Wann | Parameter |
|---|---|---|
onPluginInit |
Plugin wird geladen | context |
onMessageSent |
Benutzer sendet Nachricht | context, { message, systemPrompt } |
onResponseReceived |
Response vom Model | context, { content, stats } |
Plugin Context API
context.log(msg) // Konsolenlog mit Plugin-Name
context.warn(msg) // Warning
context.error(msg) // Error
βοΈ Konfiguration
Backend (app.py)
MODEL_NAME = "HuggingFaceH4/zephyr-7b-beta" # Modell wechseln
MAX_TOKENS = 512 # Max Output lΓ€nge
TEMPERATURE = 0.7 # KreativitΓ€t (0-2)
TOP_P = 0.9 # Nucleus sampling
Frontend Einstellungen
Im UI kannst du direkt:
- System Prompt anpassen
- Temperatur & Top-P live Γ€ndern
- Antwortzeit und Token-Count sehen
π Performance Optimierungen
FΓΌr Hugging Face Spaces (limitierte VRAM):
- Model Quantization (optional):
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(
MODEL_NAME,
load_in_8bit=True, # 8-bit quantization
device_map="auto",
)
- Kleineres Modell:
MODEL_NAME = "HuggingFaceH4/zephyr-7b-alpha" # Schneller
# oder
MODEL_NAME = "mistralai/Mistral-7B-v0.1" # Alternative
- Caching:
# Model wird gecacht nach erstem Load
π¨ Styling
- CSS Variables in
src/index.cssfΓΌr einfache Anpassung - Responsive Design (Mobile, Tablet, Desktop)
- Dunkel/Hell Mode Support (buildbar)
π Security
- Backend validiert alle Inputs
- CORS ist fΓΌr HF Spaces automatisch configured
- Sensitive data (API Keys) sollten in
.envgehen (nicht committed)
π Troubleshooting
"Module not found" bei Plugins
Stelle sicher:
- Datei ist im
/pluginsOrdner - Exports sind korrekt:
export function onPluginInit(context) { }
Backend startet nicht
# Teste wenn Python funktioniert:
python -c "import torch; print(torch.cuda.is_available())"
# Stelle sicher transformers installiert:
pip install -r requirements.txt --upgrade
React startet nicht
rm -rf node_modules package-lock.json
npm install
npm run dev
π Lizenz
MIT - Du kannst das frei nutzen, modifizieren und deployen!
π€ Contributing
Feel free to add more plugins, components, or optimizations!
π NΓ€chste Schritte
- Streaming Responses (token-by-token)
- Dark Mode Toggle
- Chat History speichern
- Export Chats als PDF
- Multi-Model Support (einfach zu Model-Select erweitern)
- Voice Input (Whisper Integration)
- Analytics Dashboard
Happy Coding! π