Spaces:
Paused
Paused
Commit
·
83a2411
1
Parent(s):
04f4e13
Auto-commit: app_complete.py updated
Browse files- app_complete.py +317 -220
app_complete.py
CHANGED
|
@@ -13,106 +13,192 @@ CLOUDFLARE_CONFIG = {
|
|
| 13 |
"d1_database_id": os.getenv("CLOUDFLARE_D1_DATABASE_ID", ""),
|
| 14 |
"r2_bucket_name": os.getenv("CLOUDFLARE_R2_BUCKET_NAME", ""),
|
| 15 |
"kv_namespace_id": os.getenv("CLOUDFLARE_KV_NAMESPACE_ID", ""),
|
| 16 |
-
"durable_objects_id": os.getenv("CLOUDFLARE_DURABLE_OBJECTS_ID", "")
|
| 17 |
}
|
| 18 |
|
| 19 |
# AI Model Categories with 200+ models
|
| 20 |
AI_MODELS = {
|
| 21 |
"Text Generation": {
|
| 22 |
"Qwen Models": [
|
| 23 |
-
"Qwen/Qwen2.5-72B-Instruct",
|
| 24 |
-
"Qwen/Qwen2.5-
|
| 25 |
-
"Qwen/Qwen2.5-
|
| 26 |
-
"Qwen/Qwen2-7B-Instruct",
|
| 27 |
-
"Qwen/
|
| 28 |
-
"Qwen/
|
| 29 |
-
"Qwen/
|
| 30 |
-
"Qwen/Qwen2
|
| 31 |
-
"Qwen/Qwen2
|
| 32 |
-
"Qwen/Qwen2
|
| 33 |
-
"Qwen/Qwen2-
|
| 34 |
-
"Qwen/Qwen2-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
],
|
| 36 |
"DeepSeek Models": [
|
| 37 |
-
"deepseek-ai/deepseek-llm-67b-chat",
|
| 38 |
-
"deepseek-ai/deepseek-
|
| 39 |
-
"deepseek-ai/deepseek-coder-
|
| 40 |
-
"deepseek-ai/
|
| 41 |
-
"deepseek-ai/deepseek-
|
| 42 |
-
"deepseek-ai/deepseek-
|
| 43 |
-
"deepseek-ai/DeepSeek-
|
| 44 |
-
"deepseek-ai/DeepSeek-
|
| 45 |
-
"deepseek-ai/
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
},
|
| 48 |
"Image Processing": {
|
| 49 |
"Image Generation": [
|
| 50 |
-
"black-forest-labs/FLUX.1-dev",
|
| 51 |
-
"
|
| 52 |
-
"
|
| 53 |
-
"
|
| 54 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
],
|
| 56 |
"Image Editing": [
|
| 57 |
-
"timbrooks/instruct-pix2pix",
|
| 58 |
-
"
|
| 59 |
-
"
|
| 60 |
-
"
|
| 61 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
],
|
| 63 |
"Face Processing": [
|
| 64 |
-
"InsightFace/inswapper_128.onnx",
|
| 65 |
-
"
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
},
|
| 68 |
"Audio Processing": {
|
| 69 |
"Text-to-Speech": [
|
| 70 |
-
"microsoft/speecht5_tts",
|
| 71 |
-
"
|
| 72 |
-
"
|
| 73 |
-
"
|
| 74 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
],
|
| 76 |
"Speech-to-Text": [
|
| 77 |
-
"openai/whisper-large-v3",
|
| 78 |
-
"openai/whisper-
|
| 79 |
-
"
|
| 80 |
-
"
|
| 81 |
-
"
|
| 82 |
-
"
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
},
|
| 85 |
"Multimodal AI": {
|
| 86 |
"Vision-Language": [
|
| 87 |
-
"microsoft/DialoGPT-large",
|
| 88 |
-
"microsoft/
|
| 89 |
-
"
|
| 90 |
-
"
|
| 91 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
],
|
| 93 |
"Talking Avatars": [
|
| 94 |
-
"microsoft/SpeechT5-TTS-Avatar",
|
| 95 |
-
"
|
| 96 |
-
"
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
},
|
| 99 |
"Arabic-English Models": [
|
| 100 |
-
"aubmindlab/bert-base-arabertv2",
|
| 101 |
-
"
|
| 102 |
-
"
|
| 103 |
-
"
|
| 104 |
-
"
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
}
|
| 107 |
|
|
|
|
| 108 |
def init_database():
|
| 109 |
"""Initialize SQLite database for authentication"""
|
| 110 |
db_path = Path("openmanus.db")
|
| 111 |
conn = sqlite3.connect(db_path)
|
| 112 |
cursor = conn.cursor()
|
| 113 |
-
|
| 114 |
# Create users table
|
| 115 |
-
cursor.execute(
|
|
|
|
| 116 |
CREATE TABLE IF NOT EXISTS users (
|
| 117 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 118 |
mobile_number TEXT UNIQUE NOT NULL,
|
|
@@ -122,10 +208,12 @@ def init_database():
|
|
| 122 |
last_login TIMESTAMP,
|
| 123 |
is_active BOOLEAN DEFAULT 1
|
| 124 |
)
|
| 125 |
-
"""
|
| 126 |
-
|
|
|
|
| 127 |
# Create sessions table
|
| 128 |
-
cursor.execute(
|
|
|
|
| 129 |
CREATE TABLE IF NOT EXISTS sessions (
|
| 130 |
id TEXT PRIMARY KEY,
|
| 131 |
user_id INTEGER NOT NULL,
|
|
@@ -135,10 +223,12 @@ def init_database():
|
|
| 135 |
user_agent TEXT,
|
| 136 |
FOREIGN KEY (user_id) REFERENCES users (id)
|
| 137 |
)
|
| 138 |
-
"""
|
| 139 |
-
|
|
|
|
| 140 |
# Create model usage table
|
| 141 |
-
cursor.execute(
|
|
|
|
| 142 |
CREATE TABLE IF NOT EXISTS model_usage (
|
| 143 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 144 |
user_id INTEGER,
|
|
@@ -150,228 +240,236 @@ def init_database():
|
|
| 150 |
processing_time REAL,
|
| 151 |
FOREIGN KEY (user_id) REFERENCES users (id)
|
| 152 |
)
|
| 153 |
-
"""
|
| 154 |
-
|
|
|
|
| 155 |
conn.commit()
|
| 156 |
conn.close()
|
| 157 |
return True
|
| 158 |
|
|
|
|
| 159 |
def hash_password(password):
|
| 160 |
"""Hash password using SHA-256"""
|
| 161 |
return hashlib.sha256(password.encode()).hexdigest()
|
| 162 |
|
|
|
|
| 163 |
def signup_user(mobile, name, password, confirm_password):
|
| 164 |
"""User registration with mobile number"""
|
| 165 |
if not all([mobile, name, password, confirm_password]):
|
| 166 |
return "❌ Please fill in all fields"
|
| 167 |
-
|
| 168 |
if password != confirm_password:
|
| 169 |
return "❌ Passwords do not match"
|
| 170 |
-
|
| 171 |
if len(password) < 6:
|
| 172 |
return "❌ Password must be at least 6 characters"
|
| 173 |
-
|
| 174 |
# Validate mobile number
|
| 175 |
if not mobile.replace("+", "").replace("-", "").replace(" ", "").isdigit():
|
| 176 |
return "❌ Please enter a valid mobile number"
|
| 177 |
-
|
| 178 |
try:
|
| 179 |
conn = sqlite3.connect("openmanus.db")
|
| 180 |
cursor = conn.cursor()
|
| 181 |
-
|
| 182 |
# Check if mobile number already exists
|
| 183 |
cursor.execute("SELECT id FROM users WHERE mobile_number = ?", (mobile,))
|
| 184 |
if cursor.fetchone():
|
| 185 |
conn.close()
|
| 186 |
return "❌ Mobile number already registered"
|
| 187 |
-
|
| 188 |
# Create new user
|
| 189 |
password_hash = hash_password(password)
|
| 190 |
-
cursor.execute(
|
|
|
|
| 191 |
INSERT INTO users (mobile_number, full_name, password_hash)
|
| 192 |
VALUES (?, ?, ?)
|
| 193 |
-
""",
|
| 194 |
-
|
|
|
|
|
|
|
| 195 |
conn.commit()
|
| 196 |
conn.close()
|
| 197 |
-
|
| 198 |
return f"✅ Account created successfully for {name}! Welcome to OpenManus Platform."
|
| 199 |
-
|
| 200 |
except Exception as e:
|
| 201 |
return f"❌ Registration failed: {str(e)}"
|
| 202 |
|
|
|
|
| 203 |
def login_user(mobile, password):
|
| 204 |
"""User authentication"""
|
| 205 |
if not mobile or not password:
|
| 206 |
return "❌ Please provide mobile number and password"
|
| 207 |
-
|
| 208 |
try:
|
| 209 |
conn = sqlite3.connect("openmanus.db")
|
| 210 |
cursor = conn.cursor()
|
| 211 |
-
|
| 212 |
# Verify credentials
|
| 213 |
password_hash = hash_password(password)
|
| 214 |
-
cursor.execute(
|
| 215 |
-
|
|
|
|
| 216 |
WHERE mobile_number = ? AND password_hash = ? AND is_active = 1
|
| 217 |
-
""",
|
| 218 |
-
|
|
|
|
|
|
|
| 219 |
user = cursor.fetchone()
|
| 220 |
if user:
|
| 221 |
# Update last login
|
| 222 |
-
cursor.execute(
|
|
|
|
| 223 |
UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE id = ?
|
| 224 |
-
""",
|
|
|
|
|
|
|
| 225 |
conn.commit()
|
| 226 |
conn.close()
|
| 227 |
-
|
| 228 |
return f"✅ Welcome back, {user[1]}! Login successful."
|
| 229 |
else:
|
| 230 |
conn.close()
|
| 231 |
return "❌ Invalid mobile number or password"
|
| 232 |
-
|
| 233 |
except Exception as e:
|
| 234 |
return f"❌ Login failed: {str(e)}"
|
| 235 |
|
|
|
|
| 236 |
def use_ai_model(model_name, input_text, user_session="guest"):
|
| 237 |
"""Simulate AI model usage"""
|
| 238 |
if not input_text.strip():
|
| 239 |
return "Please enter some text for the AI model to process."
|
| 240 |
-
|
| 241 |
# Simulate model processing
|
| 242 |
response_templates = {
|
| 243 |
"text": f"🧠 {model_name} processed: '{input_text}'\n\n✨ AI Response: This is a simulated response from the {model_name} model. In production, this would connect to the actual model API.",
|
| 244 |
"image": f"🖼️ {model_name} would generate/edit an image based on: '{input_text}'\n\n📸 Output: Image processing complete (simulated)",
|
| 245 |
"audio": f"🎵 {model_name} audio processing for: '{input_text}'\n\n🔊 Output: Audio generated/processed (simulated)",
|
| 246 |
-
"multimodal": f"🤖 {model_name} multimodal processing: '{input_text}'\n\n🎯 Output: Combined AI analysis complete (simulated)"
|
| 247 |
}
|
| 248 |
-
|
| 249 |
# Determine response type based on model
|
| 250 |
-
if any(
|
|
|
|
|
|
|
|
|
|
| 251 |
response_type = "image"
|
| 252 |
-
elif any(
|
| 253 |
-
|
|
|
|
|
|
|
|
|
|
| 254 |
elif any(x in model_name.lower() for x in ["vl", "blip", "vision", "talking"]):
|
| 255 |
response_type = "multimodal"
|
| 256 |
else:
|
| 257 |
response_type = "text"
|
| 258 |
-
|
| 259 |
return response_templates[response_type]
|
| 260 |
|
|
|
|
| 261 |
def get_cloudflare_status():
|
| 262 |
"""Get Cloudflare services status"""
|
| 263 |
services = []
|
| 264 |
-
|
| 265 |
if CLOUDFLARE_CONFIG["d1_database_id"]:
|
| 266 |
services.append("✅ D1 Database Connected")
|
| 267 |
else:
|
| 268 |
services.append("⚙️ D1 Database (Configure CLOUDFLARE_D1_DATABASE_ID)")
|
| 269 |
-
|
| 270 |
if CLOUDFLARE_CONFIG["r2_bucket_name"]:
|
| 271 |
-
services.append("✅ R2 Storage Connected")
|
| 272 |
else:
|
| 273 |
services.append("⚙️ R2 Storage (Configure CLOUDFLARE_R2_BUCKET_NAME)")
|
| 274 |
-
|
| 275 |
if CLOUDFLARE_CONFIG["kv_namespace_id"]:
|
| 276 |
services.append("✅ KV Cache Connected")
|
| 277 |
else:
|
| 278 |
services.append("⚙️ KV Cache (Configure CLOUDFLARE_KV_NAMESPACE_ID)")
|
| 279 |
-
|
| 280 |
if CLOUDFLARE_CONFIG["durable_objects_id"]:
|
| 281 |
services.append("✅ Durable Objects Connected")
|
| 282 |
else:
|
| 283 |
services.append("⚙️ Durable Objects (Configure CLOUDFLARE_DURABLE_OBJECTS_ID)")
|
| 284 |
-
|
| 285 |
return "\n".join(services)
|
| 286 |
|
|
|
|
| 287 |
# Initialize database
|
| 288 |
init_database()
|
| 289 |
|
| 290 |
# Create Gradio interface
|
| 291 |
with gr.Blocks(
|
| 292 |
-
title="OpenManus - Complete AI Platform",
|
| 293 |
theme=gr.themes.Soft(),
|
| 294 |
css="""
|
| 295 |
.container { max-width: 1400px; margin: 0 auto; }
|
| 296 |
.header { text-align: center; padding: 25px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 15px; margin-bottom: 25px; }
|
| 297 |
.section { background: white; padding: 25px; border-radius: 15px; margin: 15px 0; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
|
| 298 |
-
"""
|
| 299 |
) as app:
|
| 300 |
-
|
| 301 |
# Header
|
| 302 |
-
gr.HTML(
|
|
|
|
| 303 |
<div class="header">
|
| 304 |
<h1>🤖 OpenManus - Complete AI Platform</h1>
|
| 305 |
<p><strong>Mobile Authentication + 200+ AI Models + Cloudflare Services</strong></p>
|
| 306 |
<p>🧠 Qwen & DeepSeek | 🖼️ Image Processing | 🎵 TTS/STT | 👤 Face Swap | 🌍 Arabic-English | ☁️ Cloud Integration</p>
|
| 307 |
</div>
|
| 308 |
-
"""
|
| 309 |
-
|
|
|
|
| 310 |
with gr.Row():
|
| 311 |
# Authentication Section
|
| 312 |
with gr.Column(scale=1, elem_classes="section"):
|
| 313 |
gr.Markdown("## 🔐 Authentication System")
|
| 314 |
-
|
| 315 |
with gr.Tab("Sign Up"):
|
| 316 |
gr.Markdown("### Create New Account")
|
| 317 |
signup_mobile = gr.Textbox(
|
| 318 |
-
label="Mobile Number",
|
| 319 |
placeholder="+1234567890",
|
| 320 |
-
info="Enter your mobile number with country code"
|
| 321 |
)
|
| 322 |
signup_name = gr.Textbox(
|
| 323 |
-
label="Full Name",
|
| 324 |
-
placeholder="Your full name"
|
| 325 |
)
|
| 326 |
signup_password = gr.Textbox(
|
| 327 |
-
label="Password",
|
| 328 |
-
type="password",
|
| 329 |
-
info="Minimum 6 characters"
|
| 330 |
-
)
|
| 331 |
-
signup_confirm = gr.Textbox(
|
| 332 |
-
label="Confirm Password",
|
| 333 |
-
type="password"
|
| 334 |
)
|
|
|
|
| 335 |
signup_btn = gr.Button("Create Account", variant="primary")
|
| 336 |
signup_result = gr.Textbox(
|
| 337 |
-
label="Registration Status",
|
| 338 |
-
interactive=False,
|
| 339 |
-
lines=2
|
| 340 |
)
|
| 341 |
-
|
| 342 |
signup_btn.click(
|
| 343 |
signup_user,
|
| 344 |
[signup_mobile, signup_name, signup_password, signup_confirm],
|
| 345 |
-
signup_result
|
| 346 |
)
|
| 347 |
-
|
| 348 |
with gr.Tab("Login"):
|
| 349 |
gr.Markdown("### Access Your Account")
|
| 350 |
login_mobile = gr.Textbox(
|
| 351 |
-
label="Mobile Number",
|
| 352 |
-
placeholder="+1234567890"
|
| 353 |
-
)
|
| 354 |
-
login_password = gr.Textbox(
|
| 355 |
-
label="Password",
|
| 356 |
-
type="password"
|
| 357 |
)
|
|
|
|
| 358 |
login_btn = gr.Button("Login", variant="primary")
|
| 359 |
login_result = gr.Textbox(
|
| 360 |
-
label="Login Status",
|
| 361 |
-
interactive=False,
|
| 362 |
-
lines=2
|
| 363 |
)
|
| 364 |
-
|
| 365 |
login_btn.click(
|
| 366 |
-
login_user,
|
| 367 |
-
[login_mobile, login_password],
|
| 368 |
-
login_result
|
| 369 |
)
|
| 370 |
-
|
| 371 |
-
# AI Models Section
|
| 372 |
with gr.Column(scale=2, elem_classes="section"):
|
| 373 |
gr.Markdown("## 🤖 AI Models Hub (200+ Models)")
|
| 374 |
-
|
| 375 |
with gr.Tab("Text Generation"):
|
| 376 |
with gr.Row():
|
| 377 |
with gr.Column():
|
|
@@ -379,41 +477,43 @@ with gr.Blocks(
|
|
| 379 |
qwen_model = gr.Dropdown(
|
| 380 |
choices=AI_MODELS["Text Generation"]["Qwen Models"],
|
| 381 |
label="Select Qwen Model",
|
| 382 |
-
value="Qwen/Qwen2.5-72B-Instruct"
|
| 383 |
)
|
| 384 |
qwen_input = gr.Textbox(
|
| 385 |
label="Input Text",
|
| 386 |
placeholder="Enter your prompt for Qwen...",
|
| 387 |
-
lines=3
|
| 388 |
)
|
| 389 |
qwen_btn = gr.Button("Generate with Qwen")
|
| 390 |
qwen_output = gr.Textbox(
|
| 391 |
-
label="Qwen Response",
|
| 392 |
-
lines=5,
|
| 393 |
-
interactive=False
|
| 394 |
)
|
| 395 |
-
qwen_btn.click(
|
| 396 |
-
|
|
|
|
|
|
|
| 397 |
with gr.Column():
|
| 398 |
gr.Markdown("### DeepSeek Models (17 models)")
|
| 399 |
deepseek_model = gr.Dropdown(
|
| 400 |
choices=AI_MODELS["Text Generation"]["DeepSeek Models"],
|
| 401 |
-
label="Select DeepSeek Model",
|
| 402 |
-
value="deepseek-ai/deepseek-llm-67b-chat"
|
| 403 |
)
|
| 404 |
deepseek_input = gr.Textbox(
|
| 405 |
label="Input Text",
|
| 406 |
placeholder="Enter your prompt for DeepSeek...",
|
| 407 |
-
lines=3
|
| 408 |
)
|
| 409 |
deepseek_btn = gr.Button("Generate with DeepSeek")
|
| 410 |
deepseek_output = gr.Textbox(
|
| 411 |
-
label="DeepSeek Response",
|
| 412 |
-
lines=5,
|
| 413 |
-
interactive=False
|
| 414 |
)
|
| 415 |
-
deepseek_btn.click(
|
| 416 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
with gr.Tab("Image Processing"):
|
| 418 |
with gr.Row():
|
| 419 |
with gr.Column():
|
|
@@ -421,41 +521,41 @@ with gr.Blocks(
|
|
| 421 |
img_gen_model = gr.Dropdown(
|
| 422 |
choices=AI_MODELS["Image Processing"]["Image Generation"],
|
| 423 |
label="Select Image Model",
|
| 424 |
-
value="black-forest-labs/FLUX.1-dev"
|
| 425 |
)
|
| 426 |
img_prompt = gr.Textbox(
|
| 427 |
label="Image Prompt",
|
| 428 |
placeholder="Describe the image you want to generate...",
|
| 429 |
-
lines=2
|
| 430 |
)
|
| 431 |
img_gen_btn = gr.Button("Generate Image")
|
| 432 |
img_gen_output = gr.Textbox(
|
| 433 |
-
label="Generation Status",
|
| 434 |
-
|
| 435 |
-
|
|
|
|
| 436 |
)
|
| 437 |
-
|
| 438 |
-
|
| 439 |
with gr.Column():
|
| 440 |
gr.Markdown("### Face Processing & Editing")
|
| 441 |
face_model = gr.Dropdown(
|
| 442 |
choices=AI_MODELS["Image Processing"]["Face Processing"],
|
| 443 |
label="Select Face Model",
|
| 444 |
-
value="InsightFace/inswapper_128.onnx"
|
| 445 |
)
|
| 446 |
face_input = gr.Textbox(
|
| 447 |
label="Face Processing Task",
|
| 448 |
placeholder="Describe face swap or enhancement task...",
|
| 449 |
-
lines=2
|
| 450 |
)
|
| 451 |
face_btn = gr.Button("Process Face")
|
| 452 |
face_output = gr.Textbox(
|
| 453 |
-
label="Processing Status",
|
| 454 |
-
|
| 455 |
-
|
|
|
|
| 456 |
)
|
| 457 |
-
|
| 458 |
-
|
| 459 |
with gr.Tab("Audio Processing"):
|
| 460 |
with gr.Row():
|
| 461 |
with gr.Column():
|
|
@@ -463,41 +563,37 @@ with gr.Blocks(
|
|
| 463 |
tts_model = gr.Dropdown(
|
| 464 |
choices=AI_MODELS["Audio Processing"]["Text-to-Speech"],
|
| 465 |
label="Select TTS Model",
|
| 466 |
-
value="microsoft/speecht5_tts"
|
| 467 |
)
|
| 468 |
tts_text = gr.Textbox(
|
| 469 |
label="Text to Speak",
|
| 470 |
placeholder="Enter text to convert to speech...",
|
| 471 |
-
lines=3
|
| 472 |
)
|
| 473 |
tts_btn = gr.Button("Generate Speech")
|
| 474 |
tts_output = gr.Textbox(
|
| 475 |
-
label="TTS Status",
|
| 476 |
-
lines=4,
|
| 477 |
-
interactive=False
|
| 478 |
)
|
| 479 |
tts_btn.click(use_ai_model, [tts_model, tts_text], tts_output)
|
| 480 |
-
|
| 481 |
with gr.Column():
|
| 482 |
gr.Markdown("### Speech-to-Text (15 models)")
|
| 483 |
stt_model = gr.Dropdown(
|
| 484 |
choices=AI_MODELS["Audio Processing"]["Speech-to-Text"],
|
| 485 |
label="Select STT Model",
|
| 486 |
-
value="openai/whisper-large-v3"
|
| 487 |
)
|
| 488 |
stt_input = gr.Textbox(
|
| 489 |
label="Audio Description",
|
| 490 |
placeholder="Describe audio file to transcribe...",
|
| 491 |
-
lines=3
|
| 492 |
)
|
| 493 |
stt_btn = gr.Button("Transcribe Audio")
|
| 494 |
stt_output = gr.Textbox(
|
| 495 |
-
label="STT Status",
|
| 496 |
-
lines=4,
|
| 497 |
-
interactive=False
|
| 498 |
)
|
| 499 |
stt_btn.click(use_ai_model, [stt_model, stt_input], stt_output)
|
| 500 |
-
|
| 501 |
with gr.Tab("Multimodal & Avatars"):
|
| 502 |
with gr.Row():
|
| 503 |
with gr.Column():
|
|
@@ -505,66 +601,64 @@ with gr.Blocks(
|
|
| 505 |
vl_model = gr.Dropdown(
|
| 506 |
choices=AI_MODELS["Multimodal AI"]["Vision-Language"],
|
| 507 |
label="Select VL Model",
|
| 508 |
-
value="liuhaotian/llava-v1.6-34b"
|
| 509 |
)
|
| 510 |
vl_input = gr.Textbox(
|
| 511 |
label="Vision-Language Task",
|
| 512 |
placeholder="Describe image analysis or VQA task...",
|
| 513 |
-
lines=3
|
| 514 |
)
|
| 515 |
vl_btn = gr.Button("Process with VL Model")
|
| 516 |
vl_output = gr.Textbox(
|
| 517 |
-
label="VL Response",
|
| 518 |
-
lines=4,
|
| 519 |
-
interactive=False
|
| 520 |
)
|
| 521 |
vl_btn.click(use_ai_model, [vl_model, vl_input], vl_output)
|
| 522 |
-
|
| 523 |
with gr.Column():
|
| 524 |
gr.Markdown("### Talking Avatars")
|
| 525 |
avatar_model = gr.Dropdown(
|
| 526 |
choices=AI_MODELS["Multimodal AI"]["Talking Avatars"],
|
| 527 |
label="Select Avatar Model",
|
| 528 |
-
value="Wav2Lip-HD"
|
| 529 |
)
|
| 530 |
avatar_input = gr.Textbox(
|
| 531 |
label="Avatar Generation Task",
|
| 532 |
placeholder="Describe talking avatar or lip-sync task...",
|
| 533 |
-
lines=3
|
| 534 |
)
|
| 535 |
avatar_btn = gr.Button("Generate Avatar")
|
| 536 |
avatar_output = gr.Textbox(
|
| 537 |
-
label="Avatar Status",
|
| 538 |
-
|
| 539 |
-
|
|
|
|
| 540 |
)
|
| 541 |
-
|
| 542 |
-
|
| 543 |
with gr.Tab("Arabic-English"):
|
| 544 |
gr.Markdown("### Arabic-English Interactive Models (12 models)")
|
| 545 |
arabic_model = gr.Dropdown(
|
| 546 |
choices=AI_MODELS["Arabic-English Models"],
|
| 547 |
label="Select Arabic-English Model",
|
| 548 |
-
value="aubmindlab/bert-base-arabertv2"
|
| 549 |
)
|
| 550 |
arabic_input = gr.Textbox(
|
| 551 |
label="Text (Arabic or English)",
|
| 552 |
placeholder="أدخل النص باللغة العربية أو الإنجليزية / Enter text in Arabic or English...",
|
| 553 |
-
lines=4
|
| 554 |
)
|
| 555 |
arabic_btn = gr.Button("Process Arabic-English")
|
| 556 |
arabic_output = gr.Textbox(
|
| 557 |
-
label="Processing Result",
|
| 558 |
-
|
| 559 |
-
|
|
|
|
| 560 |
)
|
| 561 |
-
|
| 562 |
-
|
| 563 |
# Services Status Section
|
| 564 |
with gr.Row():
|
| 565 |
with gr.Column(elem_classes="section"):
|
| 566 |
gr.Markdown("## ☁️ Cloudflare Services Integration")
|
| 567 |
-
|
| 568 |
with gr.Row():
|
| 569 |
with gr.Column():
|
| 570 |
gr.Markdown("### Services Status")
|
|
@@ -572,32 +666,34 @@ with gr.Blocks(
|
|
| 572 |
label="Cloudflare Services",
|
| 573 |
value=get_cloudflare_status(),
|
| 574 |
lines=6,
|
| 575 |
-
interactive=False
|
| 576 |
)
|
| 577 |
refresh_btn = gr.Button("Refresh Status")
|
| 578 |
refresh_btn.click(
|
| 579 |
-
lambda: get_cloudflare_status(),
|
| 580 |
-
outputs=services_status
|
| 581 |
)
|
| 582 |
-
|
| 583 |
with gr.Column():
|
| 584 |
gr.Markdown("### Configuration")
|
| 585 |
-
gr.HTML(
|
|
|
|
| 586 |
<div style="background: #f0f8ff; padding: 15px; border-radius: 10px;">
|
| 587 |
<h4>Environment Variables:</h4>
|
| 588 |
<ul>
|
| 589 |
<li><code>CLOUDFLARE_API_TOKEN</code> - API authentication</li>
|
| 590 |
-
<li><code>CLOUDFLARE_ACCOUNT_ID</code> - Account identifier</li>
|
| 591 |
<li><code>CLOUDFLARE_D1_DATABASE_ID</code> - D1 database</li>
|
| 592 |
<li><code>CLOUDFLARE_R2_BUCKET_NAME</code> - R2 storage</li>
|
| 593 |
<li><code>CLOUDFLARE_KV_NAMESPACE_ID</code> - KV cache</li>
|
| 594 |
<li><code>CLOUDFLARE_DURABLE_OBJECTS_ID</code> - Durable objects</li>
|
| 595 |
</ul>
|
| 596 |
</div>
|
| 597 |
-
"""
|
| 598 |
-
|
|
|
|
| 599 |
# Footer Status
|
| 600 |
-
gr.HTML(
|
|
|
|
| 601 |
<div style="background: linear-gradient(45deg, #f0f8ff 0%, #e6f3ff 100%); padding: 20px; border-radius: 15px; margin-top: 25px; text-align: center;">
|
| 602 |
<h3>📊 Platform Status</h3>
|
| 603 |
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin: 15px 0;">
|
|
@@ -612,7 +708,8 @@ with gr.Blocks(
|
|
| 612 |
</div>
|
| 613 |
<p><em>Complete AI Platform successfully deployed on HuggingFace Spaces with Docker!</em></p>
|
| 614 |
</div>
|
| 615 |
-
"""
|
|
|
|
| 616 |
|
| 617 |
if __name__ == "__main__":
|
| 618 |
-
app.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 13 |
"d1_database_id": os.getenv("CLOUDFLARE_D1_DATABASE_ID", ""),
|
| 14 |
"r2_bucket_name": os.getenv("CLOUDFLARE_R2_BUCKET_NAME", ""),
|
| 15 |
"kv_namespace_id": os.getenv("CLOUDFLARE_KV_NAMESPACE_ID", ""),
|
| 16 |
+
"durable_objects_id": os.getenv("CLOUDFLARE_DURABLE_OBJECTS_ID", ""),
|
| 17 |
}
|
| 18 |
|
| 19 |
# AI Model Categories with 200+ models
|
| 20 |
AI_MODELS = {
|
| 21 |
"Text Generation": {
|
| 22 |
"Qwen Models": [
|
| 23 |
+
"Qwen/Qwen2.5-72B-Instruct",
|
| 24 |
+
"Qwen/Qwen2.5-32B-Instruct",
|
| 25 |
+
"Qwen/Qwen2.5-14B-Instruct",
|
| 26 |
+
"Qwen/Qwen2.5-7B-Instruct",
|
| 27 |
+
"Qwen/Qwen2.5-3B-Instruct",
|
| 28 |
+
"Qwen/Qwen2.5-1.5B-Instruct",
|
| 29 |
+
"Qwen/Qwen2.5-0.5B-Instruct",
|
| 30 |
+
"Qwen/Qwen2-72B-Instruct",
|
| 31 |
+
"Qwen/Qwen2-57B-A14B-Instruct",
|
| 32 |
+
"Qwen/Qwen2-7B-Instruct",
|
| 33 |
+
"Qwen/Qwen2-1.5B-Instruct",
|
| 34 |
+
"Qwen/Qwen2-0.5B-Instruct",
|
| 35 |
+
"Qwen/Qwen1.5-110B-Chat",
|
| 36 |
+
"Qwen/Qwen1.5-72B-Chat",
|
| 37 |
+
"Qwen/Qwen1.5-32B-Chat",
|
| 38 |
+
"Qwen/Qwen1.5-14B-Chat",
|
| 39 |
+
"Qwen/Qwen1.5-7B-Chat",
|
| 40 |
+
"Qwen/Qwen1.5-4B-Chat",
|
| 41 |
+
"Qwen/Qwen1.5-1.8B-Chat",
|
| 42 |
+
"Qwen/Qwen1.5-0.5B-Chat",
|
| 43 |
+
"Qwen/CodeQwen1.5-7B-Chat",
|
| 44 |
+
"Qwen/Qwen2.5-Math-72B-Instruct",
|
| 45 |
+
"Qwen/Qwen2.5-Math-7B-Instruct",
|
| 46 |
+
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 47 |
+
"Qwen/Qwen2.5-Coder-14B-Instruct",
|
| 48 |
+
"Qwen/Qwen2.5-Coder-7B-Instruct",
|
| 49 |
+
"Qwen/Qwen2.5-Coder-3B-Instruct",
|
| 50 |
+
"Qwen/Qwen2.5-Coder-1.5B-Instruct",
|
| 51 |
+
"Qwen/Qwen2.5-Coder-0.5B-Instruct",
|
| 52 |
+
"Qwen/QwQ-32B-Preview",
|
| 53 |
+
"Qwen/Qwen2-VL-72B-Instruct",
|
| 54 |
+
"Qwen/Qwen2-VL-7B-Instruct",
|
| 55 |
+
"Qwen/Qwen2-VL-2B-Instruct",
|
| 56 |
+
"Qwen/Qwen2-Audio-7B-Instruct",
|
| 57 |
+
"Qwen/Qwen-Agent-Chat",
|
| 58 |
+
"Qwen/Qwen-VL-Chat",
|
| 59 |
],
|
| 60 |
"DeepSeek Models": [
|
| 61 |
+
"deepseek-ai/deepseek-llm-67b-chat",
|
| 62 |
+
"deepseek-ai/deepseek-llm-7b-chat",
|
| 63 |
+
"deepseek-ai/deepseek-coder-33b-instruct",
|
| 64 |
+
"deepseek-ai/deepseek-coder-7b-instruct",
|
| 65 |
+
"deepseek-ai/deepseek-coder-6.7b-instruct",
|
| 66 |
+
"deepseek-ai/deepseek-coder-1.3b-instruct",
|
| 67 |
+
"deepseek-ai/DeepSeek-V2-Chat",
|
| 68 |
+
"deepseek-ai/DeepSeek-V2-Lite-Chat",
|
| 69 |
+
"deepseek-ai/deepseek-math-7b-instruct",
|
| 70 |
+
"deepseek-ai/deepseek-moe-16b-chat",
|
| 71 |
+
"deepseek-ai/deepseek-vl-7b-chat",
|
| 72 |
+
"deepseek-ai/deepseek-vl-1.3b-chat",
|
| 73 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
| 74 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-14B",
|
| 75 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-7B",
|
| 76 |
+
"deepseek-ai/DeepSeek-R1-Distill-Llama-8B",
|
| 77 |
+
"deepseek-ai/DeepSeek-Reasoner-R1",
|
| 78 |
+
],
|
| 79 |
},
|
| 80 |
"Image Processing": {
|
| 81 |
"Image Generation": [
|
| 82 |
+
"black-forest-labs/FLUX.1-dev",
|
| 83 |
+
"black-forest-labs/FLUX.1-schnell",
|
| 84 |
+
"black-forest-labs/FLUX.1-pro",
|
| 85 |
+
"runwayml/stable-diffusion-v1-5",
|
| 86 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
| 87 |
+
"stabilityai/stable-diffusion-3-medium-diffusers",
|
| 88 |
+
"stabilityai/sd-turbo",
|
| 89 |
+
"kandinsky-community/kandinsky-2-2-decoder",
|
| 90 |
+
"playgroundai/playground-v2.5-1024px-aesthetic",
|
| 91 |
+
"midjourney/midjourney-v6",
|
| 92 |
],
|
| 93 |
"Image Editing": [
|
| 94 |
+
"timbrooks/instruct-pix2pix",
|
| 95 |
+
"runwayml/stable-diffusion-inpainting",
|
| 96 |
+
"stabilityai/stable-diffusion-xl-refiner-1.0",
|
| 97 |
+
"lllyasviel/control_v11p_sd15_inpaint",
|
| 98 |
+
"SG161222/RealVisXL_V4.0",
|
| 99 |
+
"ByteDance/SDXL-Lightning",
|
| 100 |
+
"segmind/SSD-1B",
|
| 101 |
+
"segmind/Segmind-Vega",
|
| 102 |
+
"playgroundai/playground-v2-1024px-aesthetic",
|
| 103 |
+
"stabilityai/stable-cascade",
|
| 104 |
],
|
| 105 |
"Face Processing": [
|
| 106 |
+
"InsightFace/inswapper_128.onnx",
|
| 107 |
+
"deepinsight/insightface",
|
| 108 |
+
"TencentARC/GFPGAN",
|
| 109 |
+
"sczhou/CodeFormer",
|
| 110 |
+
"xinntao/Real-ESRGAN",
|
| 111 |
+
"ESRGAN/ESRGAN",
|
| 112 |
+
],
|
| 113 |
},
|
| 114 |
"Audio Processing": {
|
| 115 |
"Text-to-Speech": [
|
| 116 |
+
"microsoft/speecht5_tts",
|
| 117 |
+
"facebook/mms-tts-eng",
|
| 118 |
+
"facebook/mms-tts-ara",
|
| 119 |
+
"coqui/XTTS-v2",
|
| 120 |
+
"suno/bark",
|
| 121 |
+
"parler-tts/parler-tts-large-v1",
|
| 122 |
+
"microsoft/DisTTS",
|
| 123 |
+
"facebook/fastspeech2-en-ljspeech",
|
| 124 |
+
"espnet/kan-bayashi_ljspeech_vits",
|
| 125 |
+
"facebook/tts_transformer-en-ljspeech",
|
| 126 |
+
"microsoft/SpeechT5",
|
| 127 |
+
"Voicemod/fastspeech2-en-male1",
|
| 128 |
+
"facebook/mms-tts-spa",
|
| 129 |
+
"facebook/mms-tts-fra",
|
| 130 |
+
"facebook/mms-tts-deu",
|
| 131 |
],
|
| 132 |
"Speech-to-Text": [
|
| 133 |
+
"openai/whisper-large-v3",
|
| 134 |
+
"openai/whisper-large-v2",
|
| 135 |
+
"openai/whisper-medium",
|
| 136 |
+
"openai/whisper-small",
|
| 137 |
+
"openai/whisper-base",
|
| 138 |
+
"openai/whisper-tiny",
|
| 139 |
+
"facebook/wav2vec2-large-960h",
|
| 140 |
+
"facebook/wav2vec2-base-960h",
|
| 141 |
+
"microsoft/unispeech-sat-large",
|
| 142 |
+
"nvidia/stt_en_conformer_ctc_large",
|
| 143 |
+
"speechbrain/asr-wav2vec2-commonvoice-en",
|
| 144 |
+
"facebook/mms-1b-all",
|
| 145 |
+
"facebook/seamless-m4t-v2-large",
|
| 146 |
+
"distil-whisper/distil-large-v3",
|
| 147 |
+
"distil-whisper/distil-medium.en",
|
| 148 |
+
],
|
| 149 |
},
|
| 150 |
"Multimodal AI": {
|
| 151 |
"Vision-Language": [
|
| 152 |
+
"microsoft/DialoGPT-large",
|
| 153 |
+
"microsoft/blip-image-captioning-large",
|
| 154 |
+
"microsoft/blip2-opt-6.7b",
|
| 155 |
+
"microsoft/blip2-flan-t5-xl",
|
| 156 |
+
"salesforce/blip-vqa-capfilt-large",
|
| 157 |
+
"dandelin/vilt-b32-finetuned-vqa",
|
| 158 |
+
"google/pix2struct-ai2d-base",
|
| 159 |
+
"microsoft/git-large-coco",
|
| 160 |
+
"microsoft/git-base-vqa",
|
| 161 |
+
"liuhaotian/llava-v1.6-34b",
|
| 162 |
+
"liuhaotian/llava-v1.6-vicuna-7b",
|
| 163 |
],
|
| 164 |
"Talking Avatars": [
|
| 165 |
+
"microsoft/SpeechT5-TTS-Avatar",
|
| 166 |
+
"Wav2Lip-HD",
|
| 167 |
+
"First-Order-Model",
|
| 168 |
+
"LipSync-Expert",
|
| 169 |
+
"DeepFaceLive",
|
| 170 |
+
"FaceSwapper-Live",
|
| 171 |
+
"RealTime-FaceRig",
|
| 172 |
+
"AI-Avatar-Generator",
|
| 173 |
+
"TalkingHead-3D",
|
| 174 |
+
],
|
| 175 |
},
|
| 176 |
"Arabic-English Models": [
|
| 177 |
+
"aubmindlab/bert-base-arabertv2",
|
| 178 |
+
"aubmindlab/aragpt2-base",
|
| 179 |
+
"aubmindlab/aragpt2-medium",
|
| 180 |
+
"CAMeL-Lab/bert-base-arabic-camelbert-mix",
|
| 181 |
+
"asafaya/bert-base-arabic",
|
| 182 |
+
"UBC-NLP/MARBERT",
|
| 183 |
+
"UBC-NLP/ARBERTv2",
|
| 184 |
+
"facebook/nllb-200-3.3B",
|
| 185 |
+
"facebook/m2m100_1.2B",
|
| 186 |
+
"Helsinki-NLP/opus-mt-ar-en",
|
| 187 |
+
"Helsinki-NLP/opus-mt-en-ar",
|
| 188 |
+
"microsoft/DialoGPT-medium-arabic",
|
| 189 |
+
],
|
| 190 |
}
|
| 191 |
|
| 192 |
+
|
| 193 |
def init_database():
|
| 194 |
"""Initialize SQLite database for authentication"""
|
| 195 |
db_path = Path("openmanus.db")
|
| 196 |
conn = sqlite3.connect(db_path)
|
| 197 |
cursor = conn.cursor()
|
| 198 |
+
|
| 199 |
# Create users table
|
| 200 |
+
cursor.execute(
|
| 201 |
+
"""
|
| 202 |
CREATE TABLE IF NOT EXISTS users (
|
| 203 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 204 |
mobile_number TEXT UNIQUE NOT NULL,
|
|
|
|
| 208 |
last_login TIMESTAMP,
|
| 209 |
is_active BOOLEAN DEFAULT 1
|
| 210 |
)
|
| 211 |
+
"""
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
# Create sessions table
|
| 215 |
+
cursor.execute(
|
| 216 |
+
"""
|
| 217 |
CREATE TABLE IF NOT EXISTS sessions (
|
| 218 |
id TEXT PRIMARY KEY,
|
| 219 |
user_id INTEGER NOT NULL,
|
|
|
|
| 223 |
user_agent TEXT,
|
| 224 |
FOREIGN KEY (user_id) REFERENCES users (id)
|
| 225 |
)
|
| 226 |
+
"""
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
# Create model usage table
|
| 230 |
+
cursor.execute(
|
| 231 |
+
"""
|
| 232 |
CREATE TABLE IF NOT EXISTS model_usage (
|
| 233 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 234 |
user_id INTEGER,
|
|
|
|
| 240 |
processing_time REAL,
|
| 241 |
FOREIGN KEY (user_id) REFERENCES users (id)
|
| 242 |
)
|
| 243 |
+
"""
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
conn.commit()
|
| 247 |
conn.close()
|
| 248 |
return True
|
| 249 |
|
| 250 |
+
|
| 251 |
def hash_password(password):
|
| 252 |
"""Hash password using SHA-256"""
|
| 253 |
return hashlib.sha256(password.encode()).hexdigest()
|
| 254 |
|
| 255 |
+
|
| 256 |
def signup_user(mobile, name, password, confirm_password):
|
| 257 |
"""User registration with mobile number"""
|
| 258 |
if not all([mobile, name, password, confirm_password]):
|
| 259 |
return "❌ Please fill in all fields"
|
| 260 |
+
|
| 261 |
if password != confirm_password:
|
| 262 |
return "❌ Passwords do not match"
|
| 263 |
+
|
| 264 |
if len(password) < 6:
|
| 265 |
return "❌ Password must be at least 6 characters"
|
| 266 |
+
|
| 267 |
# Validate mobile number
|
| 268 |
if not mobile.replace("+", "").replace("-", "").replace(" ", "").isdigit():
|
| 269 |
return "❌ Please enter a valid mobile number"
|
| 270 |
+
|
| 271 |
try:
|
| 272 |
conn = sqlite3.connect("openmanus.db")
|
| 273 |
cursor = conn.cursor()
|
| 274 |
+
|
| 275 |
# Check if mobile number already exists
|
| 276 |
cursor.execute("SELECT id FROM users WHERE mobile_number = ?", (mobile,))
|
| 277 |
if cursor.fetchone():
|
| 278 |
conn.close()
|
| 279 |
return "❌ Mobile number already registered"
|
| 280 |
+
|
| 281 |
# Create new user
|
| 282 |
password_hash = hash_password(password)
|
| 283 |
+
cursor.execute(
|
| 284 |
+
"""
|
| 285 |
INSERT INTO users (mobile_number, full_name, password_hash)
|
| 286 |
VALUES (?, ?, ?)
|
| 287 |
+
""",
|
| 288 |
+
(mobile, name, password_hash),
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
conn.commit()
|
| 292 |
conn.close()
|
| 293 |
+
|
| 294 |
return f"✅ Account created successfully for {name}! Welcome to OpenManus Platform."
|
| 295 |
+
|
| 296 |
except Exception as e:
|
| 297 |
return f"❌ Registration failed: {str(e)}"
|
| 298 |
|
| 299 |
+
|
| 300 |
def login_user(mobile, password):
|
| 301 |
"""User authentication"""
|
| 302 |
if not mobile or not password:
|
| 303 |
return "❌ Please provide mobile number and password"
|
| 304 |
+
|
| 305 |
try:
|
| 306 |
conn = sqlite3.connect("openmanus.db")
|
| 307 |
cursor = conn.cursor()
|
| 308 |
+
|
| 309 |
# Verify credentials
|
| 310 |
password_hash = hash_password(password)
|
| 311 |
+
cursor.execute(
|
| 312 |
+
"""
|
| 313 |
+
SELECT id, full_name FROM users
|
| 314 |
WHERE mobile_number = ? AND password_hash = ? AND is_active = 1
|
| 315 |
+
""",
|
| 316 |
+
(mobile, password_hash),
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
user = cursor.fetchone()
|
| 320 |
if user:
|
| 321 |
# Update last login
|
| 322 |
+
cursor.execute(
|
| 323 |
+
"""
|
| 324 |
UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE id = ?
|
| 325 |
+
""",
|
| 326 |
+
(user[0],),
|
| 327 |
+
)
|
| 328 |
conn.commit()
|
| 329 |
conn.close()
|
| 330 |
+
|
| 331 |
return f"✅ Welcome back, {user[1]}! Login successful."
|
| 332 |
else:
|
| 333 |
conn.close()
|
| 334 |
return "❌ Invalid mobile number or password"
|
| 335 |
+
|
| 336 |
except Exception as e:
|
| 337 |
return f"❌ Login failed: {str(e)}"
|
| 338 |
|
| 339 |
+
|
| 340 |
def use_ai_model(model_name, input_text, user_session="guest"):
|
| 341 |
"""Simulate AI model usage"""
|
| 342 |
if not input_text.strip():
|
| 343 |
return "Please enter some text for the AI model to process."
|
| 344 |
+
|
| 345 |
# Simulate model processing
|
| 346 |
response_templates = {
|
| 347 |
"text": f"🧠 {model_name} processed: '{input_text}'\n\n✨ AI Response: This is a simulated response from the {model_name} model. In production, this would connect to the actual model API.",
|
| 348 |
"image": f"🖼️ {model_name} would generate/edit an image based on: '{input_text}'\n\n📸 Output: Image processing complete (simulated)",
|
| 349 |
"audio": f"🎵 {model_name} audio processing for: '{input_text}'\n\n🔊 Output: Audio generated/processed (simulated)",
|
| 350 |
+
"multimodal": f"🤖 {model_name} multimodal processing: '{input_text}'\n\n🎯 Output: Combined AI analysis complete (simulated)",
|
| 351 |
}
|
| 352 |
+
|
| 353 |
# Determine response type based on model
|
| 354 |
+
if any(
|
| 355 |
+
x in model_name.lower()
|
| 356 |
+
for x in ["image", "flux", "diffusion", "face", "avatar"]
|
| 357 |
+
):
|
| 358 |
response_type = "image"
|
| 359 |
+
elif any(
|
| 360 |
+
x in model_name.lower()
|
| 361 |
+
for x in ["tts", "speech", "audio", "whisper", "wav2vec"]
|
| 362 |
+
):
|
| 363 |
+
response_type = "audio"
|
| 364 |
elif any(x in model_name.lower() for x in ["vl", "blip", "vision", "talking"]):
|
| 365 |
response_type = "multimodal"
|
| 366 |
else:
|
| 367 |
response_type = "text"
|
| 368 |
+
|
| 369 |
return response_templates[response_type]
|
| 370 |
|
| 371 |
+
|
| 372 |
def get_cloudflare_status():
|
| 373 |
"""Get Cloudflare services status"""
|
| 374 |
services = []
|
| 375 |
+
|
| 376 |
if CLOUDFLARE_CONFIG["d1_database_id"]:
|
| 377 |
services.append("✅ D1 Database Connected")
|
| 378 |
else:
|
| 379 |
services.append("⚙️ D1 Database (Configure CLOUDFLARE_D1_DATABASE_ID)")
|
| 380 |
+
|
| 381 |
if CLOUDFLARE_CONFIG["r2_bucket_name"]:
|
| 382 |
+
services.append("✅ R2 Storage Connected")
|
| 383 |
else:
|
| 384 |
services.append("⚙️ R2 Storage (Configure CLOUDFLARE_R2_BUCKET_NAME)")
|
| 385 |
+
|
| 386 |
if CLOUDFLARE_CONFIG["kv_namespace_id"]:
|
| 387 |
services.append("✅ KV Cache Connected")
|
| 388 |
else:
|
| 389 |
services.append("⚙️ KV Cache (Configure CLOUDFLARE_KV_NAMESPACE_ID)")
|
| 390 |
+
|
| 391 |
if CLOUDFLARE_CONFIG["durable_objects_id"]:
|
| 392 |
services.append("✅ Durable Objects Connected")
|
| 393 |
else:
|
| 394 |
services.append("⚙️ Durable Objects (Configure CLOUDFLARE_DURABLE_OBJECTS_ID)")
|
| 395 |
+
|
| 396 |
return "\n".join(services)
|
| 397 |
|
| 398 |
+
|
| 399 |
# Initialize database
|
| 400 |
init_database()
|
| 401 |
|
| 402 |
# Create Gradio interface
|
| 403 |
with gr.Blocks(
|
| 404 |
+
title="OpenManus - Complete AI Platform",
|
| 405 |
theme=gr.themes.Soft(),
|
| 406 |
css="""
|
| 407 |
.container { max-width: 1400px; margin: 0 auto; }
|
| 408 |
.header { text-align: center; padding: 25px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 15px; margin-bottom: 25px; }
|
| 409 |
.section { background: white; padding: 25px; border-radius: 15px; margin: 15px 0; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
|
| 410 |
+
""",
|
| 411 |
) as app:
|
| 412 |
+
|
| 413 |
# Header
|
| 414 |
+
gr.HTML(
|
| 415 |
+
"""
|
| 416 |
<div class="header">
|
| 417 |
<h1>🤖 OpenManus - Complete AI Platform</h1>
|
| 418 |
<p><strong>Mobile Authentication + 200+ AI Models + Cloudflare Services</strong></p>
|
| 419 |
<p>🧠 Qwen & DeepSeek | 🖼️ Image Processing | 🎵 TTS/STT | 👤 Face Swap | 🌍 Arabic-English | ☁️ Cloud Integration</p>
|
| 420 |
</div>
|
| 421 |
+
"""
|
| 422 |
+
)
|
| 423 |
+
|
| 424 |
with gr.Row():
|
| 425 |
# Authentication Section
|
| 426 |
with gr.Column(scale=1, elem_classes="section"):
|
| 427 |
gr.Markdown("## 🔐 Authentication System")
|
| 428 |
+
|
| 429 |
with gr.Tab("Sign Up"):
|
| 430 |
gr.Markdown("### Create New Account")
|
| 431 |
signup_mobile = gr.Textbox(
|
| 432 |
+
label="Mobile Number",
|
| 433 |
placeholder="+1234567890",
|
| 434 |
+
info="Enter your mobile number with country code",
|
| 435 |
)
|
| 436 |
signup_name = gr.Textbox(
|
| 437 |
+
label="Full Name", placeholder="Your full name"
|
|
|
|
| 438 |
)
|
| 439 |
signup_password = gr.Textbox(
|
| 440 |
+
label="Password", type="password", info="Minimum 6 characters"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
)
|
| 442 |
+
signup_confirm = gr.Textbox(label="Confirm Password", type="password")
|
| 443 |
signup_btn = gr.Button("Create Account", variant="primary")
|
| 444 |
signup_result = gr.Textbox(
|
| 445 |
+
label="Registration Status", interactive=False, lines=2
|
|
|
|
|
|
|
| 446 |
)
|
| 447 |
+
|
| 448 |
signup_btn.click(
|
| 449 |
signup_user,
|
| 450 |
[signup_mobile, signup_name, signup_password, signup_confirm],
|
| 451 |
+
signup_result,
|
| 452 |
)
|
| 453 |
+
|
| 454 |
with gr.Tab("Login"):
|
| 455 |
gr.Markdown("### Access Your Account")
|
| 456 |
login_mobile = gr.Textbox(
|
| 457 |
+
label="Mobile Number", placeholder="+1234567890"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
)
|
| 459 |
+
login_password = gr.Textbox(label="Password", type="password")
|
| 460 |
login_btn = gr.Button("Login", variant="primary")
|
| 461 |
login_result = gr.Textbox(
|
| 462 |
+
label="Login Status", interactive=False, lines=2
|
|
|
|
|
|
|
| 463 |
)
|
| 464 |
+
|
| 465 |
login_btn.click(
|
| 466 |
+
login_user, [login_mobile, login_password], login_result
|
|
|
|
|
|
|
| 467 |
)
|
| 468 |
+
|
| 469 |
+
# AI Models Section
|
| 470 |
with gr.Column(scale=2, elem_classes="section"):
|
| 471 |
gr.Markdown("## 🤖 AI Models Hub (200+ Models)")
|
| 472 |
+
|
| 473 |
with gr.Tab("Text Generation"):
|
| 474 |
with gr.Row():
|
| 475 |
with gr.Column():
|
|
|
|
| 477 |
qwen_model = gr.Dropdown(
|
| 478 |
choices=AI_MODELS["Text Generation"]["Qwen Models"],
|
| 479 |
label="Select Qwen Model",
|
| 480 |
+
value="Qwen/Qwen2.5-72B-Instruct",
|
| 481 |
)
|
| 482 |
qwen_input = gr.Textbox(
|
| 483 |
label="Input Text",
|
| 484 |
placeholder="Enter your prompt for Qwen...",
|
| 485 |
+
lines=3,
|
| 486 |
)
|
| 487 |
qwen_btn = gr.Button("Generate with Qwen")
|
| 488 |
qwen_output = gr.Textbox(
|
| 489 |
+
label="Qwen Response", lines=5, interactive=False
|
|
|
|
|
|
|
| 490 |
)
|
| 491 |
+
qwen_btn.click(
|
| 492 |
+
use_ai_model, [qwen_model, qwen_input], qwen_output
|
| 493 |
+
)
|
| 494 |
+
|
| 495 |
with gr.Column():
|
| 496 |
gr.Markdown("### DeepSeek Models (17 models)")
|
| 497 |
deepseek_model = gr.Dropdown(
|
| 498 |
choices=AI_MODELS["Text Generation"]["DeepSeek Models"],
|
| 499 |
+
label="Select DeepSeek Model",
|
| 500 |
+
value="deepseek-ai/deepseek-llm-67b-chat",
|
| 501 |
)
|
| 502 |
deepseek_input = gr.Textbox(
|
| 503 |
label="Input Text",
|
| 504 |
placeholder="Enter your prompt for DeepSeek...",
|
| 505 |
+
lines=3,
|
| 506 |
)
|
| 507 |
deepseek_btn = gr.Button("Generate with DeepSeek")
|
| 508 |
deepseek_output = gr.Textbox(
|
| 509 |
+
label="DeepSeek Response", lines=5, interactive=False
|
|
|
|
|
|
|
| 510 |
)
|
| 511 |
+
deepseek_btn.click(
|
| 512 |
+
use_ai_model,
|
| 513 |
+
[deepseek_model, deepseek_input],
|
| 514 |
+
deepseek_output,
|
| 515 |
+
)
|
| 516 |
+
|
| 517 |
with gr.Tab("Image Processing"):
|
| 518 |
with gr.Row():
|
| 519 |
with gr.Column():
|
|
|
|
| 521 |
img_gen_model = gr.Dropdown(
|
| 522 |
choices=AI_MODELS["Image Processing"]["Image Generation"],
|
| 523 |
label="Select Image Model",
|
| 524 |
+
value="black-forest-labs/FLUX.1-dev",
|
| 525 |
)
|
| 526 |
img_prompt = gr.Textbox(
|
| 527 |
label="Image Prompt",
|
| 528 |
placeholder="Describe the image you want to generate...",
|
| 529 |
+
lines=2,
|
| 530 |
)
|
| 531 |
img_gen_btn = gr.Button("Generate Image")
|
| 532 |
img_gen_output = gr.Textbox(
|
| 533 |
+
label="Generation Status", lines=4, interactive=False
|
| 534 |
+
)
|
| 535 |
+
img_gen_btn.click(
|
| 536 |
+
use_ai_model, [img_gen_model, img_prompt], img_gen_output
|
| 537 |
)
|
| 538 |
+
|
|
|
|
| 539 |
with gr.Column():
|
| 540 |
gr.Markdown("### Face Processing & Editing")
|
| 541 |
face_model = gr.Dropdown(
|
| 542 |
choices=AI_MODELS["Image Processing"]["Face Processing"],
|
| 543 |
label="Select Face Model",
|
| 544 |
+
value="InsightFace/inswapper_128.onnx",
|
| 545 |
)
|
| 546 |
face_input = gr.Textbox(
|
| 547 |
label="Face Processing Task",
|
| 548 |
placeholder="Describe face swap or enhancement task...",
|
| 549 |
+
lines=2,
|
| 550 |
)
|
| 551 |
face_btn = gr.Button("Process Face")
|
| 552 |
face_output = gr.Textbox(
|
| 553 |
+
label="Processing Status", lines=4, interactive=False
|
| 554 |
+
)
|
| 555 |
+
face_btn.click(
|
| 556 |
+
use_ai_model, [face_model, face_input], face_output
|
| 557 |
)
|
| 558 |
+
|
|
|
|
| 559 |
with gr.Tab("Audio Processing"):
|
| 560 |
with gr.Row():
|
| 561 |
with gr.Column():
|
|
|
|
| 563 |
tts_model = gr.Dropdown(
|
| 564 |
choices=AI_MODELS["Audio Processing"]["Text-to-Speech"],
|
| 565 |
label="Select TTS Model",
|
| 566 |
+
value="microsoft/speecht5_tts",
|
| 567 |
)
|
| 568 |
tts_text = gr.Textbox(
|
| 569 |
label="Text to Speak",
|
| 570 |
placeholder="Enter text to convert to speech...",
|
| 571 |
+
lines=3,
|
| 572 |
)
|
| 573 |
tts_btn = gr.Button("Generate Speech")
|
| 574 |
tts_output = gr.Textbox(
|
| 575 |
+
label="TTS Status", lines=4, interactive=False
|
|
|
|
|
|
|
| 576 |
)
|
| 577 |
tts_btn.click(use_ai_model, [tts_model, tts_text], tts_output)
|
| 578 |
+
|
| 579 |
with gr.Column():
|
| 580 |
gr.Markdown("### Speech-to-Text (15 models)")
|
| 581 |
stt_model = gr.Dropdown(
|
| 582 |
choices=AI_MODELS["Audio Processing"]["Speech-to-Text"],
|
| 583 |
label="Select STT Model",
|
| 584 |
+
value="openai/whisper-large-v3",
|
| 585 |
)
|
| 586 |
stt_input = gr.Textbox(
|
| 587 |
label="Audio Description",
|
| 588 |
placeholder="Describe audio file to transcribe...",
|
| 589 |
+
lines=3,
|
| 590 |
)
|
| 591 |
stt_btn = gr.Button("Transcribe Audio")
|
| 592 |
stt_output = gr.Textbox(
|
| 593 |
+
label="STT Status", lines=4, interactive=False
|
|
|
|
|
|
|
| 594 |
)
|
| 595 |
stt_btn.click(use_ai_model, [stt_model, stt_input], stt_output)
|
| 596 |
+
|
| 597 |
with gr.Tab("Multimodal & Avatars"):
|
| 598 |
with gr.Row():
|
| 599 |
with gr.Column():
|
|
|
|
| 601 |
vl_model = gr.Dropdown(
|
| 602 |
choices=AI_MODELS["Multimodal AI"]["Vision-Language"],
|
| 603 |
label="Select VL Model",
|
| 604 |
+
value="liuhaotian/llava-v1.6-34b",
|
| 605 |
)
|
| 606 |
vl_input = gr.Textbox(
|
| 607 |
label="Vision-Language Task",
|
| 608 |
placeholder="Describe image analysis or VQA task...",
|
| 609 |
+
lines=3,
|
| 610 |
)
|
| 611 |
vl_btn = gr.Button("Process with VL Model")
|
| 612 |
vl_output = gr.Textbox(
|
| 613 |
+
label="VL Response", lines=4, interactive=False
|
|
|
|
|
|
|
| 614 |
)
|
| 615 |
vl_btn.click(use_ai_model, [vl_model, vl_input], vl_output)
|
| 616 |
+
|
| 617 |
with gr.Column():
|
| 618 |
gr.Markdown("### Talking Avatars")
|
| 619 |
avatar_model = gr.Dropdown(
|
| 620 |
choices=AI_MODELS["Multimodal AI"]["Talking Avatars"],
|
| 621 |
label="Select Avatar Model",
|
| 622 |
+
value="Wav2Lip-HD",
|
| 623 |
)
|
| 624 |
avatar_input = gr.Textbox(
|
| 625 |
label="Avatar Generation Task",
|
| 626 |
placeholder="Describe talking avatar or lip-sync task...",
|
| 627 |
+
lines=3,
|
| 628 |
)
|
| 629 |
avatar_btn = gr.Button("Generate Avatar")
|
| 630 |
avatar_output = gr.Textbox(
|
| 631 |
+
label="Avatar Status", lines=4, interactive=False
|
| 632 |
+
)
|
| 633 |
+
avatar_btn.click(
|
| 634 |
+
use_ai_model, [avatar_model, avatar_input], avatar_output
|
| 635 |
)
|
| 636 |
+
|
|
|
|
| 637 |
with gr.Tab("Arabic-English"):
|
| 638 |
gr.Markdown("### Arabic-English Interactive Models (12 models)")
|
| 639 |
arabic_model = gr.Dropdown(
|
| 640 |
choices=AI_MODELS["Arabic-English Models"],
|
| 641 |
label="Select Arabic-English Model",
|
| 642 |
+
value="aubmindlab/bert-base-arabertv2",
|
| 643 |
)
|
| 644 |
arabic_input = gr.Textbox(
|
| 645 |
label="Text (Arabic or English)",
|
| 646 |
placeholder="أدخل النص باللغة العربية أو الإنجليزية / Enter text in Arabic or English...",
|
| 647 |
+
lines=4,
|
| 648 |
)
|
| 649 |
arabic_btn = gr.Button("Process Arabic-English")
|
| 650 |
arabic_output = gr.Textbox(
|
| 651 |
+
label="Processing Result", lines=6, interactive=False
|
| 652 |
+
)
|
| 653 |
+
arabic_btn.click(
|
| 654 |
+
use_ai_model, [arabic_model, arabic_input], arabic_output
|
| 655 |
)
|
| 656 |
+
|
|
|
|
| 657 |
# Services Status Section
|
| 658 |
with gr.Row():
|
| 659 |
with gr.Column(elem_classes="section"):
|
| 660 |
gr.Markdown("## ☁️ Cloudflare Services Integration")
|
| 661 |
+
|
| 662 |
with gr.Row():
|
| 663 |
with gr.Column():
|
| 664 |
gr.Markdown("### Services Status")
|
|
|
|
| 666 |
label="Cloudflare Services",
|
| 667 |
value=get_cloudflare_status(),
|
| 668 |
lines=6,
|
| 669 |
+
interactive=False,
|
| 670 |
)
|
| 671 |
refresh_btn = gr.Button("Refresh Status")
|
| 672 |
refresh_btn.click(
|
| 673 |
+
lambda: get_cloudflare_status(), outputs=services_status
|
|
|
|
| 674 |
)
|
| 675 |
+
|
| 676 |
with gr.Column():
|
| 677 |
gr.Markdown("### Configuration")
|
| 678 |
+
gr.HTML(
|
| 679 |
+
"""
|
| 680 |
<div style="background: #f0f8ff; padding: 15px; border-radius: 10px;">
|
| 681 |
<h4>Environment Variables:</h4>
|
| 682 |
<ul>
|
| 683 |
<li><code>CLOUDFLARE_API_TOKEN</code> - API authentication</li>
|
| 684 |
+
<li><code>CLOUDFLARE_ACCOUNT_ID</code> - Account identifier</li>
|
| 685 |
<li><code>CLOUDFLARE_D1_DATABASE_ID</code> - D1 database</li>
|
| 686 |
<li><code>CLOUDFLARE_R2_BUCKET_NAME</code> - R2 storage</li>
|
| 687 |
<li><code>CLOUDFLARE_KV_NAMESPACE_ID</code> - KV cache</li>
|
| 688 |
<li><code>CLOUDFLARE_DURABLE_OBJECTS_ID</code> - Durable objects</li>
|
| 689 |
</ul>
|
| 690 |
</div>
|
| 691 |
+
"""
|
| 692 |
+
)
|
| 693 |
+
|
| 694 |
# Footer Status
|
| 695 |
+
gr.HTML(
|
| 696 |
+
"""
|
| 697 |
<div style="background: linear-gradient(45deg, #f0f8ff 0%, #e6f3ff 100%); padding: 20px; border-radius: 15px; margin-top: 25px; text-align: center;">
|
| 698 |
<h3>📊 Platform Status</h3>
|
| 699 |
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin: 15px 0;">
|
|
|
|
| 708 |
</div>
|
| 709 |
<p><em>Complete AI Platform successfully deployed on HuggingFace Spaces with Docker!</em></p>
|
| 710 |
</div>
|
| 711 |
+
"""
|
| 712 |
+
)
|
| 713 |
|
| 714 |
if __name__ == "__main__":
|
| 715 |
+
app.launch(server_name="0.0.0.0", server_port=7860)
|