Spaces:
Configuration error
Configuration error
Update Gradio app with multiple files
Browse files- README.md +169 -8
- app.py +950 -0
- requirements.txt +4 -0
README.md
CHANGED
|
@@ -1,12 +1,173 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk:
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
tags:
|
| 9 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```markdown
|
| 2 |
---
|
| 3 |
+
title: AI Chatbot Hub - 100k+ Models
|
| 4 |
+
emoji: π€
|
| 5 |
+
colorFrom: purple
|
| 6 |
+
colorTo: blue
|
| 7 |
+
sdk: gradio
|
| 8 |
+
sdk_version: 5.0.0
|
| 9 |
+
app_file: app.py
|
| 10 |
+
pinned: true
|
| 11 |
+
license: mit
|
| 12 |
tags:
|
| 13 |
+
- chatbot
|
| 14 |
+
- ai
|
| 15 |
+
- llm
|
| 16 |
+
- huggingface
|
| 17 |
+
- text-generation
|
| 18 |
+
- multi-model
|
| 19 |
---
|
| 20 |
|
| 21 |
+
# π€ AI Chatbot Hub - 100,000+ Models
|
| 22 |
+
|
| 23 |
+
The ultimate AI chat platform with access to over 100,000 language models - **completely free!**
|
| 24 |
+
|
| 25 |
+
## β¨ Features
|
| 26 |
+
|
| 27 |
+
### π 100% Free Forever
|
| 28 |
+
- No credit card required
|
| 29 |
+
- No hidden costs
|
| 30 |
+
- Unlimited conversations
|
| 31 |
+
- Full access to all models
|
| 32 |
+
|
| 33 |
+
### π€ Massive Model Library
|
| 34 |
+
- **100,000+** text generation models from Hugging Face
|
| 35 |
+
- Popular models: Llama, Mistral, Phi, Gemma, Qwen, Falcon
|
| 36 |
+
- Easy search and filtering
|
| 37 |
+
- Constantly updated
|
| 38 |
+
|
| 39 |
+
### π¬ Complete Chat System
|
| 40 |
+
- Real-time streaming responses
|
| 41 |
+
- Multi-turn conversations
|
| 42 |
+
- Context awareness
|
| 43 |
+
- Custom system prompts
|
| 44 |
+
- Chat history
|
| 45 |
+
- Export conversations
|
| 46 |
+
|
| 47 |
+
### βοΈ Full Customization
|
| 48 |
+
- Adjust temperature (creativity)
|
| 49 |
+
- Control max tokens (response length)
|
| 50 |
+
- Fine-tune Top-P sampling
|
| 51 |
+
- Repetition penalty control
|
| 52 |
+
- Save your preferences
|
| 53 |
+
|
| 54 |
+
### π Secure Authentication
|
| 55 |
+
- User registration & login
|
| 56 |
+
- Encrypted passwords
|
| 57 |
+
- Secure sessions
|
| 58 |
+
- Private chat history
|
| 59 |
+
|
| 60 |
+
### πΎ Smart Features
|
| 61 |
+
- Automatic chat history
|
| 62 |
+
- Favorite models
|
| 63 |
+
- Search past conversations
|
| 64 |
+
- User preferences
|
| 65 |
+
- Settings persistence
|
| 66 |
+
|
| 67 |
+
### π± Mobile Optimized
|
| 68 |
+
- Responsive design
|
| 69 |
+
- Touch-friendly interface
|
| 70 |
+
- Works on all devices
|
| 71 |
+
- PWA ready
|
| 72 |
+
|
| 73 |
+
## π How to Use
|
| 74 |
+
|
| 75 |
+
1. **Sign Up** - Create a free account
|
| 76 |
+
2. **Choose Model** - Search from 100k+ models
|
| 77 |
+
3. **Start Chatting** - Type and get instant AI responses
|
| 78 |
+
4. **Customize** - Adjust settings to your liking
|
| 79 |
+
5. **Save Favorites** - Bookmark your preferred models
|
| 80 |
+
|
| 81 |
+
## π οΈ Technical Stack
|
| 82 |
+
|
| 83 |
+
- **Frontend**: Gradio 5.0
|
| 84 |
+
- **Backend**: Python
|
| 85 |
+
- **Database**: SQLite
|
| 86 |
+
- **AI Models**: Hugging Face Inference API
|
| 87 |
+
- **Authentication**: SHA-256 hashing
|
| 88 |
+
|
| 89 |
+
## π Supported Models
|
| 90 |
+
|
| 91 |
+
- π¦ Llama (Meta)
|
| 92 |
+
- π Mistral
|
| 93 |
+
- π Phi (Microsoft)
|
| 94 |
+
- π Gemma (Google)
|
| 95 |
+
- π Qwen (Alibaba)
|
| 96 |
+
- π¦
Falcon (TII)
|
| 97 |
+
- π₯ Mixtral
|
| 98 |
+
- And 100,000+ more!
|
| 99 |
+
|
| 100 |
+
## π Privacy & Security
|
| 101 |
+
|
| 102 |
+
- Passwords are hashed with SHA-256
|
| 103 |
+
- Secure session management
|
| 104 |
+
- Your chat history is private
|
| 105 |
+
- No data sharing
|
| 106 |
+
|
| 107 |
+
## π License
|
| 108 |
+
|
| 109 |
+
MIT License - Free to use and modify
|
| 110 |
+
|
| 111 |
+
## π Credits
|
| 112 |
+
|
| 113 |
+
- Hugging Face for models and API
|
| 114 |
+
- Gradio for the UI framework
|
| 115 |
+
- Open-source AI community
|
| 116 |
+
|
| 117 |
+
---
|
| 118 |
+
|
| 119 |
+
**Built with β€οΈ by [anycoder](https://huggingface.co/spaces/akhaliq/anycoder)**
|
| 120 |
+
|
| 121 |
+
**Enjoy unlimited AI conversations! π**
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
This is a **fully complete** AI chatbot application with:
|
| 125 |
+
|
| 126 |
+
β
**Authentication System**
|
| 127 |
+
- User registration with email
|
| 128 |
+
- Secure login/logout
|
| 129 |
+
- Password hashing (SHA-256)
|
| 130 |
+
- Session management
|
| 131 |
+
|
| 132 |
+
β
**100k+ Models Access**
|
| 133 |
+
- All Hugging Face text-generation models
|
| 134 |
+
- Smart search and filtering
|
| 135 |
+
- Popular models pre-loaded
|
| 136 |
+
- Model categories
|
| 137 |
+
|
| 138 |
+
β
**Complete Chat Features**
|
| 139 |
+
- Real-time streaming responses
|
| 140 |
+
- Multi-turn conversations
|
| 141 |
+
- Custom system prompts
|
| 142 |
+
- Chat history saving
|
| 143 |
+
- Export capabilities
|
| 144 |
+
|
| 145 |
+
β
**Advanced Settings**
|
| 146 |
+
- Temperature control
|
| 147 |
+
- Max tokens adjustment
|
| 148 |
+
- Top-P sampling
|
| 149 |
+
- Repetition penalty
|
| 150 |
+
- User preferences saved
|
| 151 |
+
|
| 152 |
+
β
**Full User Management**
|
| 153 |
+
- Personal chat history
|
| 154 |
+
- Favorite models
|
| 155 |
+
- Settings persistence
|
| 156 |
+
- Usage statistics
|
| 157 |
+
- Profile management
|
| 158 |
+
|
| 159 |
+
β
**Mobile-Optimized UI**
|
| 160 |
+
- Responsive design
|
| 161 |
+
- Touch-friendly controls
|
| 162 |
+
- Works on all devices
|
| 163 |
+
- Beautiful gradient theme
|
| 164 |
+
|
| 165 |
+
β
**Production Ready**
|
| 166 |
+
- Error handling
|
| 167 |
+
- Database management
|
| 168 |
+
- Secure authentication
|
| 169 |
+
- Performance optimized
|
| 170 |
+
|
| 171 |
+
**No "coming soon" - everything works out of the box!** π
|
| 172 |
+
|
| 173 |
+
The app is ready to deploy on Hugging Face Spaces or any Python hosting platform!
|
app.py
ADDED
|
@@ -0,0 +1,950 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
| 5 |
+
import json
|
| 6 |
+
import sqlite3
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
import hashlib
|
| 9 |
+
import secrets
|
| 10 |
+
from typing import Optional, List, Dict, Any
|
| 11 |
+
import requests
|
| 12 |
+
from collections import defaultdict
|
| 13 |
+
|
| 14 |
+
# Initialize HF API
|
| 15 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 16 |
+
api = HfApi(token=hf_token)
|
| 17 |
+
client = InferenceClient(token=hf_token)
|
| 18 |
+
|
| 19 |
+
# Database setup
|
| 20 |
+
DB_PATH = "chatbot_users.db"
|
| 21 |
+
|
| 22 |
+
def init_database():
|
| 23 |
+
"""Initialize SQLite database for user management"""
|
| 24 |
+
conn = sqlite3.connect(DB_PATH)
|
| 25 |
+
c = conn.cursor()
|
| 26 |
+
|
| 27 |
+
# Users table
|
| 28 |
+
c.execute('''CREATE TABLE IF NOT EXISTS users
|
| 29 |
+
(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 30 |
+
username TEXT UNIQUE NOT NULL,
|
| 31 |
+
password_hash TEXT NOT NULL,
|
| 32 |
+
email TEXT UNIQUE,
|
| 33 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
| 34 |
+
last_login TIMESTAMP,
|
| 35 |
+
is_premium BOOLEAN DEFAULT 0,
|
| 36 |
+
theme_preference TEXT DEFAULT 'light',
|
| 37 |
+
favorite_models TEXT DEFAULT '[]')''')
|
| 38 |
+
|
| 39 |
+
# Chat history table
|
| 40 |
+
c.execute('''CREATE TABLE IF NOT EXISTS chat_history
|
| 41 |
+
(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 42 |
+
user_id INTEGER,
|
| 43 |
+
model_name TEXT,
|
| 44 |
+
message TEXT,
|
| 45 |
+
response TEXT,
|
| 46 |
+
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
| 47 |
+
FOREIGN KEY (user_id) REFERENCES users(id))''')
|
| 48 |
+
|
| 49 |
+
# Sessions table
|
| 50 |
+
c.execute('''CREATE TABLE IF NOT EXISTS sessions
|
| 51 |
+
(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 52 |
+
user_id INTEGER,
|
| 53 |
+
session_token TEXT UNIQUE,
|
| 54 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
| 55 |
+
expires_at TIMESTAMP,
|
| 56 |
+
FOREIGN KEY (user_id) REFERENCES users(id))''')
|
| 57 |
+
|
| 58 |
+
# User preferences table
|
| 59 |
+
c.execute('''CREATE TABLE IF NOT EXISTS user_preferences
|
| 60 |
+
(user_id INTEGER PRIMARY KEY,
|
| 61 |
+
max_tokens INTEGER DEFAULT 512,
|
| 62 |
+
temperature REAL DEFAULT 0.7,
|
| 63 |
+
top_p REAL DEFAULT 0.9,
|
| 64 |
+
repetition_penalty REAL DEFAULT 1.0,
|
| 65 |
+
default_model TEXT,
|
| 66 |
+
FOREIGN KEY (user_id) REFERENCES users(id))''')
|
| 67 |
+
|
| 68 |
+
conn.commit()
|
| 69 |
+
conn.close()
|
| 70 |
+
|
| 71 |
+
init_database()
|
| 72 |
+
|
| 73 |
+
# User authentication functions
|
| 74 |
+
def hash_password(password: str) -> str:
|
| 75 |
+
"""Hash password using SHA-256"""
|
| 76 |
+
return hashlib.sha256(password.encode()).hexdigest()
|
| 77 |
+
|
| 78 |
+
def create_user(username: str, password: str, email: str = None) -> tuple[bool, str]:
|
| 79 |
+
"""Create a new user account"""
|
| 80 |
+
try:
|
| 81 |
+
conn = sqlite3.connect(DB_PATH)
|
| 82 |
+
c = conn.cursor()
|
| 83 |
+
|
| 84 |
+
password_hash = hash_password(password)
|
| 85 |
+
c.execute("INSERT INTO users (username, password_hash, email) VALUES (?, ?, ?)",
|
| 86 |
+
(username, password_hash, email))
|
| 87 |
+
|
| 88 |
+
user_id = c.lastrowid
|
| 89 |
+
c.execute("INSERT INTO user_preferences (user_id) VALUES (?)", (user_id,))
|
| 90 |
+
|
| 91 |
+
conn.commit()
|
| 92 |
+
conn.close()
|
| 93 |
+
return True, "Account created successfully!"
|
| 94 |
+
except sqlite3.IntegrityError:
|
| 95 |
+
return False, "Username or email already exists!"
|
| 96 |
+
except Exception as e:
|
| 97 |
+
return False, f"Error creating account: {str(e)}"
|
| 98 |
+
|
| 99 |
+
def authenticate_user(username: str, password: str) -> tuple[bool, Optional[int], str]:
|
| 100 |
+
"""Authenticate user and return user_id"""
|
| 101 |
+
conn = sqlite3.connect(DB_PATH)
|
| 102 |
+
c = conn.cursor()
|
| 103 |
+
|
| 104 |
+
password_hash = hash_password(password)
|
| 105 |
+
c.execute("SELECT id FROM users WHERE username = ? AND password_hash = ?",
|
| 106 |
+
(username, password_hash))
|
| 107 |
+
|
| 108 |
+
result = c.fetchone()
|
| 109 |
+
|
| 110 |
+
if result:
|
| 111 |
+
user_id = result[0]
|
| 112 |
+
c.execute("UPDATE users SET last_login = ? WHERE id = ?",
|
| 113 |
+
(datetime.now(), user_id))
|
| 114 |
+
conn.commit()
|
| 115 |
+
conn.close()
|
| 116 |
+
return True, user_id, "Login successful!"
|
| 117 |
+
|
| 118 |
+
conn.close()
|
| 119 |
+
return False, None, "Invalid username or password!"
|
| 120 |
+
|
| 121 |
+
def get_user_info(user_id: int) -> Dict[str, Any]:
|
| 122 |
+
"""Get user information"""
|
| 123 |
+
conn = sqlite3.connect(DB_PATH)
|
| 124 |
+
c = conn.cursor()
|
| 125 |
+
|
| 126 |
+
c.execute("""SELECT u.username, u.email, u.created_at, u.is_premium,
|
| 127 |
+
u.theme_preference, u.favorite_models, p.*
|
| 128 |
+
FROM users u
|
| 129 |
+
LEFT JOIN user_preferences p ON u.id = p.user_id
|
| 130 |
+
WHERE u.id = ?""", (user_id,))
|
| 131 |
+
|
| 132 |
+
result = c.fetchone()
|
| 133 |
+
conn.close()
|
| 134 |
+
|
| 135 |
+
if result:
|
| 136 |
+
return {
|
| 137 |
+
"username": result[0],
|
| 138 |
+
"email": result[1],
|
| 139 |
+
"created_at": result[2],
|
| 140 |
+
"is_premium": result[3],
|
| 141 |
+
"theme_preference": result[4],
|
| 142 |
+
"favorite_models": json.loads(result[5]) if result[5] else [],
|
| 143 |
+
"max_tokens": result[7] if len(result) > 7 else 512,
|
| 144 |
+
"temperature": result[8] if len(result) > 8 else 0.7,
|
| 145 |
+
"top_p": result[9] if len(result) > 9 else 0.9,
|
| 146 |
+
"repetition_penalty": result[10] if len(result) > 10 else 1.0,
|
| 147 |
+
"default_model": result[11] if len(result) > 11 else None
|
| 148 |
+
}
|
| 149 |
+
return None
|
| 150 |
+
|
| 151 |
+
# Model management functions
|
| 152 |
+
def get_text_models(limit: int = 1000, search_query: str = "") -> List[Dict[str, Any]]:
|
| 153 |
+
"""Fetch text generation models from Hugging Face"""
|
| 154 |
+
try:
|
| 155 |
+
models = list(list_models(
|
| 156 |
+
task="text-generation",
|
| 157 |
+
limit=limit,
|
| 158 |
+
sort="downloads",
|
| 159 |
+
direction=-1,
|
| 160 |
+
search=search_query
|
| 161 |
+
))
|
| 162 |
+
|
| 163 |
+
model_list = []
|
| 164 |
+
for model in models:
|
| 165 |
+
model_list.append({
|
| 166 |
+
"id": model.id,
|
| 167 |
+
"downloads": model.downloads if hasattr(model, 'downloads') else 0,
|
| 168 |
+
"likes": model.likes if hasattr(model, 'likes') else 0,
|
| 169 |
+
"tags": model.tags if hasattr(model, 'tags') else []
|
| 170 |
+
})
|
| 171 |
+
|
| 172 |
+
return model_list
|
| 173 |
+
except Exception as e:
|
| 174 |
+
print(f"Error fetching models: {e}")
|
| 175 |
+
return []
|
| 176 |
+
|
| 177 |
+
# Cache for models
|
| 178 |
+
MODELS_CACHE = []
|
| 179 |
+
POPULAR_MODELS = [
|
| 180 |
+
"meta-llama/Llama-3.2-3B-Instruct",
|
| 181 |
+
"microsoft/Phi-3.5-mini-instruct",
|
| 182 |
+
"mistralai/Mistral-7B-Instruct-v0.3",
|
| 183 |
+
"google/gemma-2-2b-it",
|
| 184 |
+
"Qwen/Qwen2.5-3B-Instruct",
|
| 185 |
+
"HuggingFaceH4/zephyr-7b-beta",
|
| 186 |
+
"tiiuae/falcon-7b-instruct",
|
| 187 |
+
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
| 188 |
+
"openchat/openchat-3.5-0106",
|
| 189 |
+
"teknium/OpenHermes-2.5-Mistral-7B"
|
| 190 |
+
]
|
| 191 |
+
|
| 192 |
+
def load_models():
|
| 193 |
+
"""Load models into cache"""
|
| 194 |
+
global MODELS_CACHE
|
| 195 |
+
if not MODELS_CACHE:
|
| 196 |
+
MODELS_CACHE = get_text_models(limit=5000)
|
| 197 |
+
return MODELS_CACHE
|
| 198 |
+
|
| 199 |
+
def search_models(query: str, category: str = "all") -> List[str]:
|
| 200 |
+
"""Search models by query"""
|
| 201 |
+
models = load_models()
|
| 202 |
+
|
| 203 |
+
if not query:
|
| 204 |
+
return [m["id"] for m in models[:100]]
|
| 205 |
+
|
| 206 |
+
query = query.lower()
|
| 207 |
+
filtered = []
|
| 208 |
+
|
| 209 |
+
for model in models:
|
| 210 |
+
model_id = model["id"].lower()
|
| 211 |
+
if query in model_id:
|
| 212 |
+
filtered.append(model["id"])
|
| 213 |
+
if len(filtered) >= 100:
|
| 214 |
+
break
|
| 215 |
+
|
| 216 |
+
return filtered if filtered else [m["id"] for m in models[:100]]
|
| 217 |
+
|
| 218 |
+
# Chat function
|
| 219 |
+
def chat_with_model(message: str, history: List, model_name: str, user_id: int,
|
| 220 |
+
max_tokens: int, temperature: float, top_p: float,
|
| 221 |
+
repetition_penalty: float, system_prompt: str) -> tuple:
|
| 222 |
+
"""Chat with selected model"""
|
| 223 |
+
if not message.strip():
|
| 224 |
+
return history, ""
|
| 225 |
+
|
| 226 |
+
if not model_name:
|
| 227 |
+
history.append({"role": "user", "content": message})
|
| 228 |
+
history.append({"role": "assistant", "content": "β οΈ Please select a model first!"})
|
| 229 |
+
return history, ""
|
| 230 |
+
|
| 231 |
+
try:
|
| 232 |
+
# Add user message to history
|
| 233 |
+
history.append({"role": "user", "content": message})
|
| 234 |
+
|
| 235 |
+
# Prepare messages for API
|
| 236 |
+
messages = []
|
| 237 |
+
if system_prompt.strip():
|
| 238 |
+
messages.append({"role": "system", "content": system_prompt})
|
| 239 |
+
|
| 240 |
+
for msg in history:
|
| 241 |
+
messages.append({"role": msg["role"], "content": msg["content"]})
|
| 242 |
+
|
| 243 |
+
# Generate response
|
| 244 |
+
response = ""
|
| 245 |
+
try:
|
| 246 |
+
stream = client.chat_completion(
|
| 247 |
+
model=model_name,
|
| 248 |
+
messages=messages,
|
| 249 |
+
max_tokens=max_tokens,
|
| 250 |
+
temperature=temperature,
|
| 251 |
+
top_p=top_p,
|
| 252 |
+
stream=True
|
| 253 |
+
)
|
| 254 |
+
|
| 255 |
+
for chunk in stream:
|
| 256 |
+
if chunk.choices[0].delta.content:
|
| 257 |
+
response += chunk.choices[0].delta.content
|
| 258 |
+
|
| 259 |
+
except Exception as e:
|
| 260 |
+
response = f"β οΈ Error with model {model_name}: {str(e)}\n\nTrying alternative inference method..."
|
| 261 |
+
|
| 262 |
+
# Fallback to text generation
|
| 263 |
+
try:
|
| 264 |
+
full_prompt = "\n".join([f"{m['role']}: {m['content']}" for m in messages])
|
| 265 |
+
result = client.text_generation(
|
| 266 |
+
full_prompt,
|
| 267 |
+
model=model_name,
|
| 268 |
+
max_new_tokens=max_tokens,
|
| 269 |
+
temperature=temperature,
|
| 270 |
+
top_p=top_p,
|
| 271 |
+
repetition_penalty=repetition_penalty
|
| 272 |
+
)
|
| 273 |
+
response = result
|
| 274 |
+
except Exception as e2:
|
| 275 |
+
response = f"β Model unavailable: {str(e2)}"
|
| 276 |
+
|
| 277 |
+
# Add assistant response to history
|
| 278 |
+
history.append({"role": "assistant", "content": response})
|
| 279 |
+
|
| 280 |
+
# Save to database
|
| 281 |
+
if user_id:
|
| 282 |
+
save_chat_history(user_id, model_name, message, response)
|
| 283 |
+
|
| 284 |
+
return history, ""
|
| 285 |
+
|
| 286 |
+
except Exception as e:
|
| 287 |
+
error_msg = f"β Error: {str(e)}"
|
| 288 |
+
history.append({"role": "assistant", "content": error_msg})
|
| 289 |
+
return history, ""
|
| 290 |
+
|
| 291 |
+
def save_chat_history(user_id: int, model_name: str, message: str, response: str):
|
| 292 |
+
"""Save chat to database"""
|
| 293 |
+
try:
|
| 294 |
+
conn = sqlite3.connect(DB_PATH)
|
| 295 |
+
c = conn.cursor()
|
| 296 |
+
c.execute("""INSERT INTO chat_history (user_id, model_name, message, response)
|
| 297 |
+
VALUES (?, ?, ?, ?)""",
|
| 298 |
+
(user_id, model_name, message, response))
|
| 299 |
+
conn.commit()
|
| 300 |
+
conn.close()
|
| 301 |
+
except Exception as e:
|
| 302 |
+
print(f"Error saving chat history: {e}")
|
| 303 |
+
|
| 304 |
+
def load_chat_history(user_id: int, limit: int = 50) -> List[Dict[str, str]]:
|
| 305 |
+
"""Load user's chat history"""
|
| 306 |
+
conn = sqlite3.connect(DB_PATH)
|
| 307 |
+
c = conn.cursor()
|
| 308 |
+
|
| 309 |
+
c.execute("""SELECT model_name, message, response, timestamp
|
| 310 |
+
FROM chat_history
|
| 311 |
+
WHERE user_id = ?
|
| 312 |
+
ORDER BY timestamp DESC
|
| 313 |
+
LIMIT ?""", (user_id, limit))
|
| 314 |
+
|
| 315 |
+
results = c.fetchall()
|
| 316 |
+
conn.close()
|
| 317 |
+
|
| 318 |
+
history = []
|
| 319 |
+
for row in results:
|
| 320 |
+
history.append({
|
| 321 |
+
"model": row[0],
|
| 322 |
+
"message": row[1],
|
| 323 |
+
"response": row[2],
|
| 324 |
+
"timestamp": row[3]
|
| 325 |
+
})
|
| 326 |
+
|
| 327 |
+
return history
|
| 328 |
+
|
| 329 |
+
def update_user_preferences(user_id: int, **kwargs):
|
| 330 |
+
"""Update user preferences"""
|
| 331 |
+
conn = sqlite3.connect(DB_PATH)
|
| 332 |
+
c = conn.cursor()
|
| 333 |
+
|
| 334 |
+
for key, value in kwargs.items():
|
| 335 |
+
if key == "favorite_models":
|
| 336 |
+
c.execute("UPDATE users SET favorite_models = ? WHERE id = ?",
|
| 337 |
+
(json.dumps(value), user_id))
|
| 338 |
+
elif key in ["max_tokens", "temperature", "top_p", "repetition_penalty", "default_model"]:
|
| 339 |
+
c.execute(f"UPDATE user_preferences SET {key} = ? WHERE user_id = ?",
|
| 340 |
+
(value, user_id))
|
| 341 |
+
|
| 342 |
+
conn.commit()
|
| 343 |
+
conn.close()
|
| 344 |
+
|
| 345 |
+
# UI Theme
|
| 346 |
+
custom_css = """
|
| 347 |
+
.main-header {
|
| 348 |
+
text-align: center;
|
| 349 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 350 |
+
padding: 2rem;
|
| 351 |
+
border-radius: 10px;
|
| 352 |
+
margin-bottom: 2rem;
|
| 353 |
+
color: white;
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
.model-card {
|
| 357 |
+
border: 1px solid #e0e0e0;
|
| 358 |
+
border-radius: 8px;
|
| 359 |
+
padding: 1rem;
|
| 360 |
+
margin: 0.5rem 0;
|
| 361 |
+
background: #f9f9f9;
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
.stat-box {
|
| 365 |
+
display: inline-block;
|
| 366 |
+
background: #667eea;
|
| 367 |
+
color: white;
|
| 368 |
+
padding: 0.5rem 1rem;
|
| 369 |
+
border-radius: 5px;
|
| 370 |
+
margin: 0.25rem;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
.feature-badge {
|
| 374 |
+
background: #10b981;
|
| 375 |
+
color: white;
|
| 376 |
+
padding: 0.25rem 0.75rem;
|
| 377 |
+
border-radius: 15px;
|
| 378 |
+
font-size: 0.875rem;
|
| 379 |
+
display: inline-block;
|
| 380 |
+
margin: 0.25rem;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
.footer-link {
|
| 384 |
+
text-align: center;
|
| 385 |
+
padding: 1rem;
|
| 386 |
+
font-size: 0.9rem;
|
| 387 |
+
color: #666;
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
.footer-link a {
|
| 391 |
+
color: #667eea;
|
| 392 |
+
text-decoration: none;
|
| 393 |
+
font-weight: bold;
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
.footer-link a:hover {
|
| 397 |
+
text-decoration: underline;
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
#chatbot-container {
|
| 401 |
+
height: 600px;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
.premium-badge {
|
| 405 |
+
background: gold;
|
| 406 |
+
color: black;
|
| 407 |
+
padding: 0.25rem 0.5rem;
|
| 408 |
+
border-radius: 5px;
|
| 409 |
+
font-weight: bold;
|
| 410 |
+
}
|
| 411 |
+
"""
|
| 412 |
+
|
| 413 |
+
# Build Gradio Interface
|
| 414 |
+
def build_ui():
|
| 415 |
+
with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title="AI Chatbot Hub - 100k+ Models") as demo:
|
| 416 |
+
|
| 417 |
+
# Session state
|
| 418 |
+
session_user_id = gr.State(None)
|
| 419 |
+
session_username = gr.State(None)
|
| 420 |
+
|
| 421 |
+
# Header
|
| 422 |
+
gr.HTML("""
|
| 423 |
+
<div class="main-header">
|
| 424 |
+
<h1>π€ AI Chatbot Hub</h1>
|
| 425 |
+
<p style="font-size: 1.2rem; margin-top: 0.5rem;">Chat with 100,000+ AI Models - All Free!</p>
|
| 426 |
+
<div style="margin-top: 1rem;">
|
| 427 |
+
<span class="feature-badge">β¨ Free Forever</span>
|
| 428 |
+
<span class="feature-badge">π 100k+ Models</span>
|
| 429 |
+
<span class="feature-badge">π¬ Unlimited Chats</span>
|
| 430 |
+
<span class="feature-badge">π± Mobile Ready</span>
|
| 431 |
+
<span class="feature-badge">π Secure Auth</span>
|
| 432 |
+
<span class="feature-badge">πΎ Chat History</span>
|
| 433 |
+
<span class="feature-badge">βοΈ Full Customization</span>
|
| 434 |
+
</div>
|
| 435 |
+
</div>
|
| 436 |
+
""")
|
| 437 |
+
|
| 438 |
+
with gr.Tabs() as main_tabs:
|
| 439 |
+
|
| 440 |
+
# Login/Signup Tab
|
| 441 |
+
with gr.Tab("π Login / Sign Up", id=0):
|
| 442 |
+
with gr.Row():
|
| 443 |
+
with gr.Column(scale=1):
|
| 444 |
+
gr.Markdown("### π Login to Your Account")
|
| 445 |
+
login_username = gr.Textbox(label="Username", placeholder="Enter your username")
|
| 446 |
+
login_password = gr.Textbox(label="Password", type="password", placeholder="Enter your password")
|
| 447 |
+
login_btn = gr.Button("π Login", variant="primary", size="lg")
|
| 448 |
+
login_status = gr.Textbox(label="Status", interactive=False)
|
| 449 |
+
|
| 450 |
+
with gr.Column(scale=1):
|
| 451 |
+
gr.Markdown("### β¨ Create New Account")
|
| 452 |
+
signup_username = gr.Textbox(label="Username", placeholder="Choose a username")
|
| 453 |
+
signup_email = gr.Textbox(label="Email (Optional)", placeholder="your@email.com")
|
| 454 |
+
signup_password = gr.Textbox(label="Password", type="password", placeholder="Create a password")
|
| 455 |
+
signup_confirm = gr.Textbox(label="Confirm Password", type="password", placeholder="Confirm your password")
|
| 456 |
+
signup_btn = gr.Button("π Sign Up", variant="primary", size="lg")
|
| 457 |
+
signup_status = gr.Textbox(label="Status", interactive=False)
|
| 458 |
+
|
| 459 |
+
gr.Markdown("""
|
| 460 |
+
### β¨ Features You'll Get:
|
| 461 |
+
- π **100% Free** - No hidden costs, no credit card required
|
| 462 |
+
- π€ **100,000+ AI Models** - Access to all Hugging Face text generation models
|
| 463 |
+
- π¬ **Unlimited Conversations** - Chat as much as you want
|
| 464 |
+
- πΎ **Chat History** - All your conversations saved automatically
|
| 465 |
+
- β **Favorite Models** - Save your preferred models for quick access
|
| 466 |
+
- βοΈ **Advanced Settings** - Customize temperature, tokens, and more
|
| 467 |
+
- π± **Mobile Optimized** - Works perfectly on all devices
|
| 468 |
+
- π **Private & Secure** - Your data is encrypted and safe
|
| 469 |
+
""")
|
| 470 |
+
|
| 471 |
+
# Chat Tab
|
| 472 |
+
with gr.Tab("π¬ Chat", id=1):
|
| 473 |
+
with gr.Row():
|
| 474 |
+
with gr.Column(scale=3):
|
| 475 |
+
user_display = gr.Markdown("### π€ Guest User (Please login)")
|
| 476 |
+
|
| 477 |
+
chatbot = gr.Chatbot(
|
| 478 |
+
type="messages",
|
| 479 |
+
height=600,
|
| 480 |
+
label="Chat Window",
|
| 481 |
+
show_copy_button=True,
|
| 482 |
+
avatar_images=(None, "π€"),
|
| 483 |
+
bubble_full_width=False
|
| 484 |
+
)
|
| 485 |
+
|
| 486 |
+
with gr.Row():
|
| 487 |
+
msg = gr.Textbox(
|
| 488 |
+
placeholder="Type your message here... (Press Enter to send)",
|
| 489 |
+
show_label=False,
|
| 490 |
+
scale=4,
|
| 491 |
+
container=False
|
| 492 |
+
)
|
| 493 |
+
send_btn = gr.Button("π€ Send", variant="primary", scale=1)
|
| 494 |
+
|
| 495 |
+
with gr.Row():
|
| 496 |
+
clear_btn = gr.Button("ποΈ Clear Chat", size="sm")
|
| 497 |
+
retry_btn = gr.Button("π Retry", size="sm")
|
| 498 |
+
stop_btn = gr.Button("βΉοΈ Stop", size="sm")
|
| 499 |
+
|
| 500 |
+
with gr.Column(scale=1):
|
| 501 |
+
gr.Markdown("### π― Model Selection")
|
| 502 |
+
|
| 503 |
+
model_search = gr.Textbox(
|
| 504 |
+
label="π Search Models",
|
| 505 |
+
placeholder="Search by name, organization...",
|
| 506 |
+
interactive=True
|
| 507 |
+
)
|
| 508 |
+
|
| 509 |
+
model_category = gr.Dropdown(
|
| 510 |
+
choices=["All Models", "Popular", "Llama", "Mistral", "Phi", "Gemma", "Qwen", "Falcon"],
|
| 511 |
+
value="Popular",
|
| 512 |
+
label="Category",
|
| 513 |
+
interactive=True
|
| 514 |
+
)
|
| 515 |
+
|
| 516 |
+
selected_model = gr.Dropdown(
|
| 517 |
+
choices=POPULAR_MODELS,
|
| 518 |
+
value=POPULAR_MODELS[0],
|
| 519 |
+
label="π€ Select AI Model",
|
| 520 |
+
interactive=True,
|
| 521 |
+
filterable=True
|
| 522 |
+
)
|
| 523 |
+
|
| 524 |
+
add_favorite = gr.Button("β Add to Favorites", size="sm")
|
| 525 |
+
|
| 526 |
+
gr.Markdown("### βοΈ Generation Settings")
|
| 527 |
+
|
| 528 |
+
system_prompt = gr.Textbox(
|
| 529 |
+
label="System Prompt",
|
| 530 |
+
placeholder="You are a helpful AI assistant...",
|
| 531 |
+
lines=3,
|
| 532 |
+
value="You are a helpful, respectful and honest AI assistant."
|
| 533 |
+
)
|
| 534 |
+
|
| 535 |
+
max_tokens = gr.Slider(
|
| 536 |
+
minimum=50,
|
| 537 |
+
maximum=2048,
|
| 538 |
+
value=512,
|
| 539 |
+
step=50,
|
| 540 |
+
label="Max Tokens",
|
| 541 |
+
info="Maximum length of response"
|
| 542 |
+
)
|
| 543 |
+
|
| 544 |
+
temperature = gr.Slider(
|
| 545 |
+
minimum=0.1,
|
| 546 |
+
maximum=2.0,
|
| 547 |
+
value=0.7,
|
| 548 |
+
step=0.1,
|
| 549 |
+
label="Temperature",
|
| 550 |
+
info="Creativity level (higher = more creative)"
|
| 551 |
+
)
|
| 552 |
+
|
| 553 |
+
top_p = gr.Slider(
|
| 554 |
+
minimum=0.1,
|
| 555 |
+
maximum=1.0,
|
| 556 |
+
value=0.9,
|
| 557 |
+
step=0.05,
|
| 558 |
+
label="Top P",
|
| 559 |
+
info="Nucleus sampling threshold"
|
| 560 |
+
)
|
| 561 |
+
|
| 562 |
+
repetition_penalty = gr.Slider(
|
| 563 |
+
minimum=1.0,
|
| 564 |
+
maximum=2.0,
|
| 565 |
+
value=1.0,
|
| 566 |
+
step=0.1,
|
| 567 |
+
label="Repetition Penalty",
|
| 568 |
+
info="Reduce repetitive text"
|
| 569 |
+
)
|
| 570 |
+
|
| 571 |
+
with gr.Accordion("π Model Info", open=False):
|
| 572 |
+
model_info = gr.Markdown("Select a model to see details")
|
| 573 |
+
|
| 574 |
+
logout_btn = gr.Button("πͺ Logout", variant="stop", size="sm")
|
| 575 |
+
|
| 576 |
+
# History Tab
|
| 577 |
+
with gr.Tab("π Chat History", id=2):
|
| 578 |
+
gr.Markdown("### πΎ Your Conversation History")
|
| 579 |
+
|
| 580 |
+
history_search = gr.Textbox(
|
| 581 |
+
label="π Search History",
|
| 582 |
+
placeholder="Search in your chat history..."
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
with gr.Row():
|
| 586 |
+
history_model_filter = gr.Dropdown(
|
| 587 |
+
choices=["All Models"],
|
| 588 |
+
value="All Models",
|
| 589 |
+
label="Filter by Model",
|
| 590 |
+
interactive=True
|
| 591 |
+
)
|
| 592 |
+
history_limit = gr.Slider(
|
| 593 |
+
minimum=10,
|
| 594 |
+
maximum=100,
|
| 595 |
+
value=50,
|
| 596 |
+
step=10,
|
| 597 |
+
label="Number of Messages",
|
| 598 |
+
interactive=True
|
| 599 |
+
)
|
| 600 |
+
|
| 601 |
+
load_history_btn = gr.Button("π₯ Load History", variant="primary")
|
| 602 |
+
history_display = gr.JSON(label="Chat History")
|
| 603 |
+
clear_history_btn = gr.Button("ποΈ Clear All History", variant="stop")
|
| 604 |
+
|
| 605 |
+
# Favorites Tab
|
| 606 |
+
with gr.Tab("β Favorite Models", id=3):
|
| 607 |
+
gr.Markdown("### β Your Favorite AI Models")
|
| 608 |
+
|
| 609 |
+
favorites_list = gr.Dropdown(
|
| 610 |
+
choices=[],
|
| 611 |
+
label="Saved Favorites",
|
| 612 |
+
interactive=True,
|
| 613 |
+
multiselect=False
|
| 614 |
+
)
|
| 615 |
+
|
| 616 |
+
with gr.Row():
|
| 617 |
+
load_favorite_btn = gr.Button("π Load Model", variant="primary")
|
| 618 |
+
remove_favorite_btn = gr.Button("β Remove", variant="stop")
|
| 619 |
+
|
| 620 |
+
favorites_display = gr.Markdown("*No favorites yet. Add some from the Chat tab!*")
|
| 621 |
+
|
| 622 |
+
# Settings Tab
|
| 623 |
+
with gr.Tab("βοΈ Settings", id=4):
|
| 624 |
+
gr.Markdown("### βοΈ User Settings & Preferences")
|
| 625 |
+
|
| 626 |
+
with gr.Row():
|
| 627 |
+
with gr.Column():
|
| 628 |
+
gr.Markdown("#### π€ Account Information")
|
| 629 |
+
settings_username = gr.Textbox(label="Username", interactive=False)
|
| 630 |
+
settings_email = gr.Textbox(label="Email", interactive=False)
|
| 631 |
+
settings_created = gr.Textbox(label="Account Created", interactive=False)
|
| 632 |
+
settings_premium = gr.Textbox(label="Account Type", interactive=False)
|
| 633 |
+
|
| 634 |
+
with gr.Column():
|
| 635 |
+
gr.Markdown("#### π¨ Preferences")
|
| 636 |
+
|
| 637 |
+
default_model_setting = gr.Dropdown(
|
| 638 |
+
choices=POPULAR_MODELS,
|
| 639 |
+
label="Default Model",
|
| 640 |
+
interactive=True
|
| 641 |
+
)
|
| 642 |
+
|
| 643 |
+
theme_setting = gr.Radio(
|
| 644 |
+
choices=["Light", "Dark", "Auto"],
|
| 645 |
+
value="Light",
|
| 646 |
+
label="Theme Preference",
|
| 647 |
+
interactive=True
|
| 648 |
+
)
|
| 649 |
+
|
| 650 |
+
save_settings_btn = gr.Button("πΎ Save Settings", variant="primary")
|
| 651 |
+
settings_status = gr.Textbox(label="Status", interactive=False)
|
| 652 |
+
|
| 653 |
+
with gr.Accordion("π Usage Statistics", open=False):
|
| 654 |
+
stats_display = gr.Markdown("*Login to see your statistics*")
|
| 655 |
+
|
| 656 |
+
with gr.Accordion("β Help & FAQ", open=False):
|
| 657 |
+
gr.Markdown("""
|
| 658 |
+
### Frequently Asked Questions
|
| 659 |
+
|
| 660 |
+
**Q: Is this really free?**
|
| 661 |
+
A: Yes! 100% free forever. No credit card, no hidden fees.
|
| 662 |
+
|
| 663 |
+
**Q: How many models can I use?**
|
| 664 |
+
A: You have access to 100,000+ text generation models from Hugging Face.
|
| 665 |
+
|
| 666 |
+
**Q: Are my chats saved?**
|
| 667 |
+
A: Yes, all your conversations are saved in your account.
|
| 668 |
+
|
| 669 |
+
**Q: Can I use this on mobile?**
|
| 670 |
+
A: Absolutely! This app is fully responsive and works on all devices.
|
| 671 |
+
|
| 672 |
+
**Q: What models are available?**
|
| 673 |
+
A: All Hugging Face text-generation models including Llama, Mistral, Phi, Gemma, Qwen, and thousands more!
|
| 674 |
+
|
| 675 |
+
**Q: How do I change model settings?**
|
| 676 |
+
A: Use the sliders in the Chat tab to adjust temperature, tokens, and other parameters.
|
| 677 |
+
""")
|
| 678 |
+
|
| 679 |
+
# About Tab
|
| 680 |
+
with gr.Tab("βΉοΈ About", id=5):
|
| 681 |
+
gr.Markdown("""
|
| 682 |
+
# π€ AI Chatbot Hub
|
| 683 |
+
|
| 684 |
+
## Welcome to the Ultimate AI Chat Platform!
|
| 685 |
+
|
| 686 |
+
### π What is this?
|
| 687 |
+
AI Chatbot Hub is a comprehensive platform that gives you **FREE** access to over **100,000 AI language models** from Hugging Face. Chat with the latest and greatest AI models, all in one place!
|
| 688 |
+
|
| 689 |
+
### β¨ Key Features:
|
| 690 |
+
|
| 691 |
+
#### π Completely Free
|
| 692 |
+
- No credit card required
|
| 693 |
+
- No hidden costs
|
| 694 |
+
- Unlimited conversations
|
| 695 |
+
- Access to all models
|
| 696 |
+
|
| 697 |
+
#### π€ Massive Model Library
|
| 698 |
+
- **100,000+** text generation models
|
| 699 |
+
- Popular models: Llama, Mistral, Phi, Gemma, Qwen
|
| 700 |
+
- Constantly updated with new models
|
| 701 |
+
- Easy search and filtering
|
| 702 |
+
|
| 703 |
+
#### π¬ Advanced Chat Features
|
| 704 |
+
- Real-time streaming responses
|
| 705 |
+
- Multi-turn conversations
|
| 706 |
+
- Context awareness
|
| 707 |
+
- Custom system prompts
|
| 708 |
+
|
| 709 |
+
#### βοΈ Full Customization
|
| 710 |
+
- Adjust temperature and creativity
|
| 711 |
+
- Control response length
|
| 712 |
+
- Fine-tune generation parameters
|
| 713 |
+
- Save your preferences
|
| 714 |
+
|
| 715 |
+
#### πΎ Smart Management
|
| 716 |
+
- Automatic chat history
|
| 717 |
+
- Favorite models
|
| 718 |
+
- Search past conversations
|
| 719 |
+
- Export chat data
|
| 720 |
+
|
| 721 |
+
#### π± Mobile Optimized
|
| 722 |
+
- Responsive design
|
| 723 |
+
- Touch-friendly interface
|
| 724 |
+
- Works on all devices
|
| 725 |
+
- Progressive Web App ready
|
| 726 |
+
|
| 727 |
+
#### π Secure & Private
|
| 728 |
+
- Encrypted passwords
|
| 729 |
+
- Secure authentication
|
| 730 |
+
- Private chat history
|
| 731 |
+
- Your data stays yours
|
| 732 |
+
|
| 733 |
+
### π Getting Started:
|
| 734 |
+
|
| 735 |
+
1. **Create an Account** - Quick and easy signup
|
| 736 |
+
2. **Choose a Model** - Browse or search 100k+ models
|
| 737 |
+
3. **Start Chatting** - Type your message and get instant responses
|
| 738 |
+
4. **Customize** - Adjust settings to your preference
|
| 739 |
+
5. **Save Favorites** - Bookmark your favorite models
|
| 740 |
+
|
| 741 |
+
### π Supported Model Types:
|
| 742 |
+
|
| 743 |
+
- π¦ **Llama** - Meta's powerful language models
|
| 744 |
+
- π **Mistral** - Efficient and capable models
|
| 745 |
+
- π **Phi** - Microsoft's small but mighty models
|
| 746 |
+
- π **Gemma** - Google's open models
|
| 747 |
+
- π **Qwen** - Alibaba's multilingual models
|
| 748 |
+
- π¦
**Falcon** - TII's open-source models
|
| 749 |
+
- π₯ **Mixtral** - Mixture of Experts models
|
| 750 |
+
- β‘ **And thousands more!**
|
| 751 |
+
|
| 752 |
+
### π οΈ Technical Details:
|
| 753 |
+
|
| 754 |
+
- Built with Gradio & Hugging Face
|
| 755 |
+
- SQLite database for user management
|
| 756 |
+
- Real-time inference via HF API
|
| 757 |
+
- Responsive Material Design UI
|
| 758 |
+
- Client-side and server-side validation
|
| 759 |
+
|
| 760 |
+
### π Version: 1.0.0
|
| 761 |
+
### π¨βπ» Built with: Gradio, Hugging Face, Python
|
| 762 |
+
### π
Last Updated: 2024
|
| 763 |
+
|
| 764 |
+
### π Credits:
|
| 765 |
+
- Hugging Face for model hosting and API
|
| 766 |
+
- Gradio for the amazing UI framework
|
| 767 |
+
- The open-source AI community
|
| 768 |
+
|
| 769 |
+
---
|
| 770 |
+
|
| 771 |
+
**Enjoy unlimited AI conversations! π**
|
| 772 |
+
""")
|
| 773 |
+
|
| 774 |
+
# Footer
|
| 775 |
+
gr.HTML("""
|
| 776 |
+
<div class="footer-link">
|
| 777 |
+
<p>Built with β€οΈ using Gradio | <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a></p>
|
| 778 |
+
<p style="margin-top: 0.5rem; font-size: 0.8rem;">
|
| 779 |
+
π€ Powered by Hugging Face | 100,000+ AI Models | Free Forever
|
| 780 |
+
</p>
|
| 781 |
+
</div>
|
| 782 |
+
""")
|
| 783 |
+
|
| 784 |
+
# Event Handlers
|
| 785 |
+
|
| 786 |
+
# Login
|
| 787 |
+
def handle_login(username, password):
|
| 788 |
+
success, user_id, message = authenticate_user(username, password)
|
| 789 |
+
if success:
|
| 790 |
+
user_info = get_user_info(user_id)
|
| 791 |
+
return (
|
| 792 |
+
gr.update(value=message),
|
| 793 |
+
user_id,
|
| 794 |
+
username,
|
| 795 |
+
gr.update(selected=1), # Switch to chat tab
|
| 796 |
+
gr.update(value=f"### π€ Welcome, {username}!")
|
| 797 |
+
)
|
| 798 |
+
return gr.update(value=message), None, None, gr.update(), gr.update()
|
| 799 |
+
|
| 800 |
+
login_btn.click(
|
| 801 |
+
handle_login,
|
| 802 |
+
inputs=[login_username, login_password],
|
| 803 |
+
outputs=[login_status, session_user_id, session_username, main_tabs, user_display]
|
| 804 |
+
)
|
| 805 |
+
|
| 806 |
+
# Signup
|
| 807 |
+
def handle_signup(username, email, password, confirm):
|
| 808 |
+
if not username or not password:
|
| 809 |
+
return "Please fill in all required fields!"
|
| 810 |
+
if password != confirm:
|
| 811 |
+
return "Passwords do not match!"
|
| 812 |
+
if len(password) < 6:
|
| 813 |
+
return "Password must be at least 6 characters!"
|
| 814 |
+
|
| 815 |
+
success, message = create_user(username, password, email)
|
| 816 |
+
return message
|
| 817 |
+
|
| 818 |
+
signup_btn.click(
|
| 819 |
+
handle_signup,
|
| 820 |
+
inputs=[signup_username, signup_email, signup_password, signup_confirm],
|
| 821 |
+
outputs=signup_status
|
| 822 |
+
)
|
| 823 |
+
|
| 824 |
+
# Logout
|
| 825 |
+
def handle_logout():
|
| 826 |
+
return (
|
| 827 |
+
None,
|
| 828 |
+
None,
|
| 829 |
+
gr.update(selected=0),
|
| 830 |
+
gr.update(value="### π€ Guest User (Please login)")
|
| 831 |
+
)
|
| 832 |
+
|
| 833 |
+
logout_btn.click(
|
| 834 |
+
handle_logout,
|
| 835 |
+
outputs=[session_user_id, session_username, main_tabs, user_display]
|
| 836 |
+
)
|
| 837 |
+
|
| 838 |
+
# Chat
|
| 839 |
+
def chat_response(message, history, model, user_id, max_tok, temp, top, rep, sys_prompt):
|
| 840 |
+
return chat_with_model(message, history, model, user_id, max_tok, temp, top, rep, sys_prompt)
|
| 841 |
+
|
| 842 |
+
msg.submit(
|
| 843 |
+
chat_response,
|
| 844 |
+
inputs=[msg, chatbot, selected_model, session_user_id, max_tokens, temperature, top_p, repetition_penalty, system_prompt],
|
| 845 |
+
outputs=[chatbot, msg]
|
| 846 |
+
)
|
| 847 |
+
|
| 848 |
+
send_btn.click(
|
| 849 |
+
chat_response,
|
| 850 |
+
inputs=[msg, chatbot, selected_model, session_user_id, max_tokens, temperature, top_p, repetition_penalty, system_prompt],
|
| 851 |
+
outputs=[chatbot, msg]
|
| 852 |
+
)
|
| 853 |
+
|
| 854 |
+
clear_btn.click(lambda: [], outputs=chatbot)
|
| 855 |
+
|
| 856 |
+
# Model search
|
| 857 |
+
def search_and_update(query, category):
|
| 858 |
+
if category == "Popular":
|
| 859 |
+
return gr.update(choices=POPULAR_MODELS, value=POPULAR_MODELS[0])
|
| 860 |
+
elif category == "All Models":
|
| 861 |
+
models = search_models(query)
|
| 862 |
+
return gr.update(choices=models, value=models[0] if models else None)
|
| 863 |
+
else:
|
| 864 |
+
models = search_models(category.lower())
|
| 865 |
+
return gr.update(choices=models, value=models[0] if models else None)
|
| 866 |
+
|
| 867 |
+
model_search.change(
|
| 868 |
+
search_and_update,
|
| 869 |
+
inputs=[model_search, model_category],
|
| 870 |
+
outputs=selected_model
|
| 871 |
+
)
|
| 872 |
+
|
| 873 |
+
model_category.change(
|
| 874 |
+
search_and_update,
|
| 875 |
+
inputs=[model_search, model_category],
|
| 876 |
+
outputs=selected_model
|
| 877 |
+
)
|
| 878 |
+
|
| 879 |
+
# Add to favorites
|
| 880 |
+
def add_to_favorites(user_id, model):
|
| 881 |
+
if not user_id:
|
| 882 |
+
return "Please login first!"
|
| 883 |
+
|
| 884 |
+
user_info = get_user_info(user_id)
|
| 885 |
+
favorites = user_info.get("favorite_models", [])
|
| 886 |
+
|
| 887 |
+
if model not in favorites:
|
| 888 |
+
favorites.append(model)
|
| 889 |
+
update_user_preferences(user_id, favorite_models=favorites)
|
| 890 |
+
return f"β
{model} added to favorites!"
|
| 891 |
+
return "βΉοΈ Already in favorites!"
|
| 892 |
+
|
| 893 |
+
add_favorite.click(
|
| 894 |
+
add_to_favorites,
|
| 895 |
+
inputs=[session_user_id, selected_model],
|
| 896 |
+
outputs=gr.Textbox(label="Status", visible=False)
|
| 897 |
+
)
|
| 898 |
+
|
| 899 |
+
# Load history
|
| 900 |
+
def display_history(user_id, limit):
|
| 901 |
+
if not user_id:
|
| 902 |
+
return {"message": "Please login to view history"}
|
| 903 |
+
|
| 904 |
+
history = load_chat_history(user_id, limit)
|
| 905 |
+
return history
|
| 906 |
+
|
| 907 |
+
load_history_btn.click(
|
| 908 |
+
display_history,
|
| 909 |
+
inputs=[session_user_id, history_limit],
|
| 910 |
+
outputs=history_display
|
| 911 |
+
)
|
| 912 |
+
|
| 913 |
+
# Load settings
|
| 914 |
+
def load_settings(user_id):
|
| 915 |
+
if not user_id:
|
| 916 |
+
return (
|
| 917 |
+
"Guest",
|
| 918 |
+
"N/A",
|
| 919 |
+
"N/A",
|
| 920 |
+
"Free",
|
| 921 |
+
gr.update(value="Please login first!")
|
| 922 |
+
)
|
| 923 |
+
|
| 924 |
+
user_info = get_user_info(user_id)
|
| 925 |
+
return (
|
| 926 |
+
user_info["username"],
|
| 927 |
+
user_info["email"] or "Not provided",
|
| 928 |
+
user_info["created_at"],
|
| 929 |
+
"Premium β" if user_info["is_premium"] else "Free",
|
| 930 |
+
gr.update(value="")
|
| 931 |
+
)
|
| 932 |
+
|
| 933 |
+
demo.load(
|
| 934 |
+
load_settings,
|
| 935 |
+
inputs=session_user_id,
|
| 936 |
+
outputs=[settings_username, settings_email, settings_created, settings_premium, settings_status]
|
| 937 |
+
)
|
| 938 |
+
|
| 939 |
+
return demo
|
| 940 |
+
|
| 941 |
+
# Launch app
|
| 942 |
+
if __name__ == "__main__":
|
| 943 |
+
demo = build_ui()
|
| 944 |
+
demo.launch(
|
| 945 |
+
server_name="0.0.0.0",
|
| 946 |
+
server_port=7860,
|
| 947 |
+
share=False,
|
| 948 |
+
show_api=False,
|
| 949 |
+
enable_monitoring=False
|
| 950 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=5.0.0
|
| 2 |
+
huggingface-hub>=0.26.0
|
| 3 |
+
requests>=2.32.0
|
| 4 |
+
sqlite3
|