Speedofmastery commited on
Commit
f8401c2
Β·
1 Parent(s): 7dc043d

Remove all minimal versions - keep only complete platform

Browse files
Files changed (5) hide show
  1. app_clean.py +0 -84
  2. app_minimal.py +0 -153
  3. app_production.py +0 -528
  4. app_simple.py +0 -326
  5. app_ultra_minimal.py +0 -42
app_clean.py DELETED
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- OpenManus - HuggingFace Spaces Compatible Version
4
- """
5
-
6
- import gradio as gr
7
-
8
-
9
- def main():
10
- """Main application"""
11
-
12
- def signup(mobile, name, password, confirm):
13
- if not all([mobile, name, password, confirm]):
14
- return "Please fill all fields"
15
- if password != confirm:
16
- return "Passwords don't match"
17
- return f"Account created for {name}!"
18
-
19
- def login(mobile, password):
20
- if not mobile or not password:
21
- return "Please enter mobile and password"
22
- return "Login successful!"
23
-
24
- def chat(message, history):
25
- if not message:
26
- return history, ""
27
- response = f"OpenManus AI: I received '{message}'. I have 200+ models ready!"
28
- history.append((message, response))
29
- return history, ""
30
-
31
- with gr.Blocks(title="OpenManus") as app:
32
-
33
- gr.HTML(
34
- """
35
- <div style="text-align: center; padding: 20px; background: #667eea; color: white; border-radius: 10px;">
36
- <h1>πŸ€– OpenManus - Complete AI Platform</h1>
37
- <p>Mobile Authentication + 200+ AI Models</p>
38
- </div>
39
- """
40
- )
41
-
42
- with gr.Row():
43
- with gr.Column():
44
- gr.Markdown("## Authentication")
45
-
46
- with gr.Tab("Sign Up"):
47
- s_mobile = gr.Textbox(label="Mobile")
48
- s_name = gr.Textbox(label="Name")
49
- s_pass = gr.Textbox(label="Password", type="password")
50
- s_confirm = gr.Textbox(label="Confirm", type="password")
51
- s_btn = gr.Button("Sign Up")
52
- s_result = gr.Textbox(label="Result")
53
- s_btn.click(signup, [s_mobile, s_name, s_pass, s_confirm], s_result)
54
-
55
- with gr.Tab("Login"):
56
- l_mobile = gr.Textbox(label="Mobile")
57
- l_pass = gr.Textbox(label="Password", type="password")
58
- l_btn = gr.Button("Login")
59
- l_result = gr.Textbox(label="Result")
60
- l_btn.click(login, [l_mobile, l_pass], l_result)
61
-
62
- with gr.Column():
63
- gr.Markdown("## AI Chat")
64
-
65
- chatbot = gr.Chatbot(height=400)
66
- msg = gr.Textbox(label="Message")
67
- send = gr.Button("Send")
68
-
69
- send.click(chat, [msg, chatbot], [chatbot, msg])
70
- msg.submit(chat, [msg, chatbot], [chatbot, msg])
71
-
72
- gr.HTML(
73
- """
74
- <div style="text-align: center; padding: 15px; background: #f0f8ff; border-radius: 10px; margin-top: 20px;">
75
- <p>βœ… Platform Active | βœ… 200+ Models Ready | βœ… Authentication Working</p>
76
- </div>
77
- """
78
- )
79
-
80
- app.launch(server_name="0.0.0.0", server_port=7860)
81
-
82
-
83
- if __name__ == "__main__":
84
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app_minimal.py DELETED
@@ -1,153 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- OpenManus - Minimal HuggingFace Spaces Version
4
- """
5
-
6
- import gradio as gr
7
-
8
-
9
- def create_interface():
10
- """Create the main interface"""
11
-
12
- def signup_user(mobile, name, password, confirm_password):
13
- if not all([mobile, name, password, confirm_password]):
14
- return "❌ Please fill in all fields"
15
-
16
- if password != confirm_password:
17
- return "❌ Passwords do not match"
18
-
19
- if len(password) < 6:
20
- return "❌ Password must be at least 6 characters"
21
-
22
- return f"βœ… Account created successfully for {name}! Welcome to OpenManus."
23
-
24
- def login_user(mobile, password):
25
- if not mobile or not password:
26
- return "❌ Please provide mobile number and password"
27
-
28
- return f"βœ… Login successful! Welcome back to OpenManus Platform."
29
-
30
- def chat_with_ai(message, history):
31
- if not message.strip():
32
- return history, ""
33
-
34
- # Simple AI response
35
- response = f"πŸ€– OpenManus AI: Hello! I'm your AI assistant with access to 200+ models including Qwen, DeepSeek, image processing, TTS/STT, and Arabic-English support. You said: '{message}'"
36
-
37
- history.append((message, response))
38
- return history, ""
39
-
40
- # Create the interface
41
- with gr.Blocks(
42
- title="OpenManus - Complete AI Platform", theme=gr.themes.Soft()
43
- ) as demo:
44
-
45
- gr.HTML(
46
- """
47
- <div style="text-align: center; padding: 20px; background: linear-gradient(45deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 10px; margin-bottom: 20px;">
48
- <h1>πŸ€– OpenManus - Complete AI Platform</h1>
49
- <p><strong>Mobile Authentication + 200+ AI Models + Cloud Services</strong></p>
50
- <p>Features: Qwen Models | DeepSeek | Image Processing | TTS/STT | Face Swap | Arabic-English</p>
51
- </div>
52
- """
53
- )
54
-
55
- with gr.Row():
56
- # Authentication Section
57
- with gr.Column(scale=1):
58
- gr.Markdown("## πŸ” Authentication")
59
-
60
- with gr.Tab("Sign Up"):
61
- signup_mobile = gr.Textbox(
62
- label="Mobile Number", placeholder="+1234567890"
63
- )
64
- signup_name = gr.Textbox(
65
- label="Full Name", placeholder="Your full name"
66
- )
67
- signup_password = gr.Textbox(label="Password", type="password")
68
- signup_confirm = gr.Textbox(
69
- label="Confirm Password", type="password"
70
- )
71
- signup_btn = gr.Button("Create Account", variant="primary")
72
- signup_result = gr.Textbox(label="Status", interactive=False)
73
-
74
- signup_btn.click(
75
- signup_user,
76
- [signup_mobile, signup_name, signup_password, signup_confirm],
77
- signup_result,
78
- )
79
-
80
- with gr.Tab("Login"):
81
- login_mobile = gr.Textbox(
82
- label="Mobile Number", placeholder="+1234567890"
83
- )
84
- login_password = gr.Textbox(label="Password", type="password")
85
- login_btn = gr.Button("Login", variant="primary")
86
- login_result = gr.Textbox(label="Status", interactive=False)
87
-
88
- login_btn.click(
89
- login_user, [login_mobile, login_password], login_result
90
- )
91
-
92
- # AI Chat Section
93
- with gr.Column(scale=2):
94
- gr.Markdown("## πŸ€– AI Assistant")
95
-
96
- chatbot = gr.Chatbot(height=400, show_copy_button=True)
97
-
98
- with gr.Row():
99
- msg_input = gr.Textbox(
100
- label="Message",
101
- placeholder="Ask me anything! I have 200+ AI models...",
102
- scale=4,
103
- )
104
- send_btn = gr.Button("Send", variant="primary", scale=1)
105
-
106
- send_btn.click(chat_with_ai, [msg_input, chatbot], [chatbot, msg_input])
107
- msg_input.submit(
108
- chat_with_ai, [msg_input, chatbot], [chatbot, msg_input]
109
- )
110
-
111
- # Status Footer
112
- gr.HTML(
113
- """
114
- <div style="background: #f0f8ff; padding: 15px; border-radius: 10px; margin-top: 20px; text-align: center;">
115
- <h3>πŸ“Š Platform Status</h3>
116
- <p>βœ… Authentication Ready | βœ… AI Models Available | βœ… Platform Active</p>
117
- <p><em>Successfully deployed on HuggingFace Spaces!</em></p>
118
- </div>
119
- """
120
- )
121
-
122
- return demo
123
-
124
-
125
- def main():
126
- """Main entry point"""
127
- print("πŸš€ OpenManus Platform Starting...")
128
-
129
- try:
130
- app = create_interface()
131
- print("βœ… Interface created successfully")
132
-
133
- app.launch(server_name="0.0.0.0", server_port=7860, share=False, show_api=False)
134
-
135
- except Exception as e:
136
- print(f"❌ Error: {e}")
137
- # Create emergency fallback
138
- with gr.Blocks(title="OpenManus") as fallback:
139
- gr.HTML(
140
- """
141
- <div style="text-align: center; padding: 50px;">
142
- <h1>πŸ€– OpenManus Platform</h1>
143
- <h2>βœ… Successfully Deployed!</h2>
144
- <p>Complete AI platform with mobile authentication and 200+ models is ready!</p>
145
- </div>
146
- """
147
- )
148
-
149
- fallback.launch(server_name="0.0.0.0", server_port=7860)
150
-
151
-
152
- if __name__ == "__main__":
153
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app_production.py DELETED
@@ -1,528 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- OpenManus - Complete Production Version for HuggingFace Spaces
4
- Includes: Mobile Authentication + All AI Models + Cloudflare Services (D1, R2, KV, Durable Objects)
5
- """
6
-
7
- import os
8
- import sys
9
- import sqlite3
10
- import logging
11
- import asyncio
12
- from pathlib import Path
13
- from typing import Optional, Dict, Any
14
-
15
- # Add the app directory to Python path
16
- sys.path.append(os.path.join(os.path.dirname(__file__), "app"))
17
-
18
- # Import comprehensive configurations
19
- from app.production_config import OpenManusConfig, config
20
-
21
- # Configure logging
22
- logging.basicConfig(
23
- level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
24
- )
25
- logger = logging.getLogger(__name__)
26
-
27
-
28
- class OpenManusProduction:
29
- """Complete OpenManus production application with all services"""
30
-
31
- def __init__(self):
32
- self.db_path = Path("auth.db")
33
- self.cloudflare_client = None
34
- self.d1_db = None
35
- self.r2_storage = None
36
- self.kv_storage = None
37
- self.durable_objects = None
38
- self.manus_agent = None
39
- self.initialized = False
40
-
41
- def setup_database(self):
42
- """Initialize SQLite database for authentication"""
43
- try:
44
- # Create database if it doesn't exist
45
- conn = sqlite3.connect(self.db_path)
46
- cursor = conn.cursor()
47
-
48
- # Create users table with mobile number authentication
49
- cursor.execute(
50
- """
51
- CREATE TABLE IF NOT EXISTS users (
52
- id INTEGER PRIMARY KEY AUTOINCREMENT,
53
- mobile_number TEXT UNIQUE NOT NULL,
54
- full_name TEXT NOT NULL,
55
- password_hash TEXT NOT NULL,
56
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
57
- last_login TIMESTAMP
58
- )
59
- """
60
- )
61
-
62
- # Create sessions table
63
- cursor.execute(
64
- """
65
- CREATE TABLE IF NOT EXISTS sessions (
66
- id TEXT PRIMARY KEY,
67
- user_id INTEGER NOT NULL,
68
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
69
- expires_at TIMESTAMP NOT NULL,
70
- FOREIGN KEY (user_id) REFERENCES users (id)
71
- )
72
- """
73
- )
74
-
75
- # Create agent interactions log
76
- cursor.execute(
77
- """
78
- CREATE TABLE IF NOT EXISTS agent_interactions (
79
- id INTEGER PRIMARY KEY AUTOINCREMENT,
80
- user_id INTEGER NOT NULL,
81
- session_id TEXT NOT NULL,
82
- model_used TEXT,
83
- input_text TEXT,
84
- output_text TEXT,
85
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
86
- FOREIGN KEY (user_id) REFERENCES users (id)
87
- )
88
- """
89
- )
90
-
91
- conn.commit()
92
- conn.close()
93
- logger.info("Database initialized successfully")
94
- return True
95
-
96
- except Exception as e:
97
- logger.error(f"Database setup failed: {e}")
98
- return False
99
-
100
- async def init_cloudflare_services(self):
101
- """Initialize all Cloudflare services"""
102
- try:
103
- # Get Cloudflare credentials from environment
104
- cf_token = os.getenv("CLOUDFLARE_API_TOKEN")
105
- cf_account_id = os.getenv("CLOUDFLARE_ACCOUNT_ID")
106
- cf_worker_url = os.getenv("CLOUDFLARE_WORKER_URL")
107
-
108
- if cf_token and cf_account_id:
109
- logger.info("Initializing Cloudflare services...")
110
-
111
- # Import Cloudflare services
112
- from cloudflare import (
113
- CloudflareClient,
114
- D1Database,
115
- R2Storage,
116
- KVStorage,
117
- DurableObjects,
118
- )
119
-
120
- # Initialize client
121
- self.cloudflare_client = CloudflareClient(
122
- api_token=cf_token,
123
- account_id=cf_account_id,
124
- worker_url=cf_worker_url,
125
- )
126
-
127
- # Initialize D1 Database
128
- if os.getenv("CLOUDFLARE_D1_DATABASE_ID"):
129
- self.d1_db = D1Database(
130
- client=self.cloudflare_client,
131
- database_id=os.getenv("CLOUDFLARE_D1_DATABASE_ID"),
132
- )
133
- logger.info("D1 Database service initialized")
134
-
135
- # Initialize R2 Storage
136
- if os.getenv("CLOUDFLARE_R2_BUCKET_NAME"):
137
- self.r2_storage = R2Storage(
138
- client=self.cloudflare_client,
139
- bucket_name=os.getenv("CLOUDFLARE_R2_BUCKET_NAME"),
140
- )
141
- logger.info("R2 Storage service initialized")
142
-
143
- # Initialize KV Storage
144
- if os.getenv("CLOUDFLARE_KV_NAMESPACE_ID"):
145
- self.kv_storage = KVStorage(
146
- client=self.cloudflare_client,
147
- namespace_id=os.getenv("CLOUDFLARE_KV_NAMESPACE_ID"),
148
- )
149
- logger.info("KV Storage service initialized")
150
-
151
- # Initialize Durable Objects
152
- self.durable_objects = DurableObjects(self.cloudflare_client)
153
- logger.info("Durable Objects service initialized")
154
-
155
- logger.info("All Cloudflare services initialized successfully")
156
-
157
- else:
158
- logger.warning(
159
- "Cloudflare credentials not provided, running in local mode"
160
- )
161
-
162
- except Exception as e:
163
- logger.error(f"Cloudflare services initialization failed: {e}")
164
- logger.info("Continuing in local mode...")
165
-
166
- async def init_ai_agent(self):
167
- """Initialize the Manus AI agent with all models"""
168
- try:
169
- logger.info("Initializing AI Agent with all HuggingFace models...")
170
-
171
- # Import the agent and models
172
- from app.agent.manus import Manus
173
- from app.huggingface_models import HuggingFaceModels
174
-
175
- # Initialize HuggingFace models with comprehensive configuration
176
- hf_models = HuggingFaceModels()
177
-
178
- # Load all model categories from config
179
- total_models = 0
180
- for category_name, models in [
181
- ("text-generation", config.categories.TEXT_GENERATION_MODELS),
182
- ("image-editing", config.categories.IMAGE_EDITING_MODELS),
183
- ("speech", config.categories.SPEECH_MODELS),
184
- ("face-swap", config.categories.FACE_SWAP_MODELS),
185
- ("avatar", config.categories.AVATAR_MODELS),
186
- ("arabic-english", config.categories.ARABIC_ENGLISH_MODELS),
187
- ]:
188
- logger.info(f"Loading {len(models)} models for {category_name}")
189
- total_models += len(models)
190
-
191
- # Initialize with all services and comprehensive model configuration
192
- self.manus_agent = await Manus.create(
193
- d1_db=self.d1_db,
194
- r2_storage=self.r2_storage,
195
- kv_storage=self.kv_storage,
196
- durable_objects=self.durable_objects,
197
- )
198
-
199
- logger.info(
200
- f"AI Agent initialized with {total_models}+ models across all categories"
201
- )
202
-
203
- except Exception as e:
204
- logger.error(f"AI Agent initialization failed: {e}")
205
- logger.info("Creating fallback agent...")
206
-
207
- # Create a simple fallback agent
208
- class FallbackAgent:
209
- async def process_message(
210
- self, message: str, user_id: Optional[str] = None
211
- ) -> str:
212
- return f"Fallback response for: {message}"
213
-
214
- self.manus_agent = FallbackAgent()
215
-
216
- def create_gradio_interface(self):
217
- """Create the complete Gradio interface with all features"""
218
- try:
219
- import gradio as gr
220
-
221
- # Import authentication components
222
- from auth_service import AuthService
223
- from auth import UserSignupRequest, UserLoginRequest
224
-
225
- auth_service = AuthService()
226
-
227
- # Authentication functions
228
- async def handle_signup(
229
- mobile_number: str, full_name: str, password: str, confirm_password: str
230
- ):
231
- try:
232
- if password != confirm_password:
233
- return "❌ Passwords do not match"
234
-
235
- signup_request = UserSignupRequest(
236
- mobile_number=mobile_number,
237
- full_name=full_name,
238
- password=password,
239
- confirm_password=confirm_password,
240
- )
241
-
242
- success, message = await auth_service.register_user(signup_request)
243
- return f"{'βœ…' if success else '❌'} {message}"
244
-
245
- except Exception as e:
246
- return f"❌ Signup error: {str(e)}"
247
-
248
- async def handle_login(mobile_number: str, password: str):
249
- try:
250
- login_request = UserLoginRequest(
251
- mobile_number=mobile_number, password=password
252
- )
253
-
254
- user, session = await auth_service.login_user(login_request)
255
- if user and session:
256
- return f"βœ… Welcome {user.full_name}!", user.dict(), session.id
257
- else:
258
- return "❌ Invalid credentials", None, None
259
-
260
- except Exception as e:
261
- return f"❌ Login error: {str(e)}", None, None
262
-
263
- async def handle_ai_message(
264
- message: str, history: list, user_data: dict, session_id: str
265
- ):
266
- try:
267
- if not user_data or not session_id:
268
- return (
269
- history
270
- + [
271
- ("You", message),
272
- (
273
- "Assistant",
274
- "Please log in first to use the AI assistant.",
275
- ),
276
- ],
277
- "",
278
- )
279
-
280
- # Process message through AI agent
281
- response = await self.manus_agent.process_message(
282
- message, user_data.get("id")
283
- )
284
-
285
- # Add to history
286
- history.append(("You", message))
287
- history.append(("Assistant", response))
288
-
289
- return history, ""
290
-
291
- except Exception as e:
292
- error_msg = f"AI processing error: {str(e)}"
293
- history.append(("You", message))
294
- history.append(("Assistant", error_msg))
295
- return history, ""
296
-
297
- # Create the interface
298
- with gr.Blocks(
299
- title="OpenManus - Complete AI Platform",
300
- theme=gr.themes.Soft(),
301
- css="""
302
- .container { max-width: 1200px; margin: 0 auto; }
303
- .auth-section { background: #f8f9fa; padding: 20px; border-radius: 10px; margin: 10px 0; }
304
- .chat-section { background: #ffffff; padding: 20px; border-radius: 10px; margin: 10px 0; }
305
- .status-box { background: #e8f5e8; padding: 15px; border-radius: 8px; margin: 10px 0; }
306
- """,
307
- ) as demo:
308
-
309
- # Header
310
- gr.HTML(
311
- """
312
- <div style="text-align: center; padding: 20px;">
313
- <h1>πŸ€– OpenManus - Complete AI Platform</h1>
314
- <p>Mobile Authentication + 200+ AI Models + Cloudflare Services</p>
315
- </div>
316
- """
317
- )
318
-
319
- # State variables
320
- user_state = gr.State(None)
321
- session_state = gr.State(None)
322
-
323
- with gr.Row():
324
- # Authentication Column
325
- with gr.Column(scale=1, elem_classes="auth-section"):
326
- gr.Markdown("## πŸ” Authentication")
327
-
328
- with gr.Tab("Sign Up"):
329
- signup_mobile = gr.Textbox(
330
- label="Mobile Number", placeholder="+1234567890"
331
- )
332
- signup_name = gr.Textbox(
333
- label="Full Name", placeholder="Your full name"
334
- )
335
- signup_password = gr.Textbox(
336
- label="Password", type="password"
337
- )
338
- signup_confirm = gr.Textbox(
339
- label="Confirm Password", type="password"
340
- )
341
- signup_btn = gr.Button("Sign Up", variant="primary")
342
- signup_output = gr.Textbox(
343
- label="Result", interactive=False
344
- )
345
-
346
- signup_btn.click(
347
- handle_signup,
348
- [
349
- signup_mobile,
350
- signup_name,
351
- signup_password,
352
- signup_confirm,
353
- ],
354
- signup_output,
355
- )
356
-
357
- with gr.Tab("Login"):
358
- login_mobile = gr.Textbox(
359
- label="Mobile Number", placeholder="+1234567890"
360
- )
361
- login_password = gr.Textbox(
362
- label="Password", type="password"
363
- )
364
- login_btn = gr.Button("Login", variant="primary")
365
- login_output = gr.Textbox(label="Result", interactive=False)
366
-
367
- login_btn.click(
368
- handle_login,
369
- [login_mobile, login_password],
370
- [login_output, user_state, session_state],
371
- )
372
-
373
- # AI Chat Column
374
- with gr.Column(scale=2, elem_classes="chat-section"):
375
- gr.Markdown("## πŸ€– AI Assistant (200+ Models)")
376
-
377
- chatbot = gr.Chatbot(
378
- label="Chat with OpenManus AI",
379
- height=500,
380
- show_copy_button=True,
381
- )
382
-
383
- with gr.Row():
384
- msg_input = gr.Textbox(
385
- label="Message",
386
- placeholder="Type your message here... (Login required)",
387
- scale=4,
388
- )
389
- send_btn = gr.Button("Send", variant="primary", scale=1)
390
-
391
- # File upload for images/documents
392
- file_upload = gr.File(
393
- label="Upload Files (Images, Documents)",
394
- file_types=["image", "text", ".pdf", ".docx"],
395
- )
396
-
397
- # Send message
398
- send_btn.click(
399
- handle_ai_message,
400
- [msg_input, chatbot, user_state, session_state],
401
- [chatbot, msg_input],
402
- )
403
-
404
- msg_input.submit(
405
- handle_ai_message,
406
- [msg_input, chatbot, user_state, session_state],
407
- [chatbot, msg_input],
408
- )
409
-
410
- # Status Section
411
- with gr.Row():
412
- with gr.Column(elem_classes="status-box"):
413
- gr.HTML(
414
- """
415
- <div>
416
- <h3>πŸš€ Platform Status</h3>
417
- <ul>
418
- <li>βœ… Authentication System: Active</li>
419
- <li>βœ… AI Models: 200+ Available</li>
420
- <li>βœ… HuggingFace Integration: Active</li>
421
- <li>πŸ”„ Cloudflare Services: Dynamic</li>
422
- </ul>
423
- </div>
424
- """
425
- )
426
-
427
- return demo
428
-
429
- except Exception as e:
430
- logger.error(f"Gradio interface creation failed: {e}")
431
-
432
- # Create emergency fallback interface
433
- import gradio as gr
434
-
435
- with gr.Blocks(title="OpenManus - Emergency Mode") as fallback_demo:
436
- gr.Markdown(
437
- f"""
438
- # ⚠️ OpenManus - Emergency Mode
439
-
440
- **Error:** {str(e)}
441
-
442
- The system is running in emergency mode. Basic functionality may be limited.
443
- """
444
- )
445
-
446
- with gr.Row():
447
- emergency_input = gr.Textbox(label="Test Input")
448
- emergency_output = gr.Textbox(label="Test Output")
449
- emergency_btn = gr.Button("Test")
450
-
451
- def emergency_test(text):
452
- return f"Emergency response: {text}"
453
-
454
- emergency_btn.click(emergency_test, emergency_input, emergency_output)
455
-
456
- return fallback_demo
457
-
458
- async def initialize(self):
459
- """Initialize all services"""
460
- if self.initialized:
461
- return True
462
-
463
- try:
464
- logger.info("πŸš€ Starting OpenManus Production initialization...")
465
-
466
- # Setup database
467
- if not self.setup_database():
468
- logger.error("Database setup failed")
469
- return False
470
-
471
- # Initialize Cloudflare services
472
- await self.init_cloudflare_services()
473
-
474
- # Initialize AI agent
475
- await self.init_ai_agent()
476
-
477
- self.initialized = True
478
- logger.info("βœ… OpenManus Production fully initialized")
479
- return True
480
-
481
- except Exception as e:
482
- logger.error(f"Initialization failed: {e}")
483
- return False
484
-
485
- def launch(self):
486
- """Launch the complete application"""
487
- try:
488
- # Create interface
489
- app = self.create_gradio_interface()
490
-
491
- # Launch for HuggingFace Spaces
492
- logger.info("🌟 Launching OpenManus Production on port 7860...")
493
-
494
- app.launch(
495
- server_name="0.0.0.0",
496
- server_port=7860,
497
- share=False,
498
- show_api=False,
499
- quiet=False,
500
- inbrowser=False,
501
- allowed_paths=["./assets", "./workspace"],
502
- )
503
-
504
- except Exception as e:
505
- logger.error(f"Launch failed: {e}")
506
- raise
507
-
508
-
509
- async def main():
510
- """Main function"""
511
- app = OpenManusProduction()
512
-
513
- # Initialize all services
514
- success = await app.initialize()
515
-
516
- if success:
517
- logger.info("βœ… All services initialized successfully")
518
- else:
519
- logger.warning(
520
- "⚠️ Some services failed to initialize, continuing with available services"
521
- )
522
-
523
- # Launch the application
524
- app.launch()
525
-
526
-
527
- if __name__ == "__main__":
528
- asyncio.run(main())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app_simple.py DELETED
@@ -1,326 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- OpenManus - Simple HuggingFace Spaces Version
4
- Mobile Authentication + AI Models (Simplified for reliable deployment)
5
- """
6
-
7
- import os
8
- import sys
9
- import sqlite3
10
- import logging
11
- from pathlib import Path
12
-
13
- # Configure logging
14
- logging.basicConfig(level=logging.INFO)
15
- logger = logging.getLogger(__name__)
16
-
17
-
18
- def setup_database():
19
- """Initialize SQLite database for authentication"""
20
- try:
21
- db_path = Path("auth.db")
22
- conn = sqlite3.connect(db_path)
23
- cursor = conn.cursor()
24
-
25
- # Create users table
26
- cursor.execute(
27
- """
28
- CREATE TABLE IF NOT EXISTS users (
29
- id INTEGER PRIMARY KEY AUTOINCREMENT,
30
- mobile_number TEXT UNIQUE NOT NULL,
31
- full_name TEXT NOT NULL,
32
- password_hash TEXT NOT NULL,
33
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
34
- )
35
- """
36
- )
37
-
38
- # Create sessions table
39
- cursor.execute(
40
- """
41
- CREATE TABLE IF NOT EXISTS sessions (
42
- id TEXT PRIMARY KEY,
43
- user_id INTEGER NOT NULL,
44
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
45
- expires_at TIMESTAMP NOT NULL,
46
- FOREIGN KEY (user_id) REFERENCES users (id)
47
- )
48
- """
49
- )
50
-
51
- conn.commit()
52
- conn.close()
53
- logger.info("Database initialized successfully")
54
- return True
55
- except Exception as e:
56
- logger.error(f"Database setup failed: {e}")
57
- return False
58
-
59
-
60
- def create_simple_interface():
61
- """Create a simple Gradio interface"""
62
- try:
63
- import gradio as gr
64
-
65
- # Simple authentication functions
66
- def simple_signup(mobile, name, password, confirm_password):
67
- if not mobile or not name or not password:
68
- return "❌ Please fill in all fields"
69
-
70
- if password != confirm_password:
71
- return "❌ Passwords do not match"
72
-
73
- if len(password) < 6:
74
- return "❌ Password must be at least 6 characters"
75
-
76
- # Simple validation
77
- if not mobile.startswith("+") and not mobile.isdigit():
78
- return "❌ Please enter a valid mobile number"
79
-
80
- return f"βœ… Account created for {name} ({mobile})"
81
-
82
- def simple_login(mobile, password):
83
- if not mobile or not password:
84
- return "❌ Please fill in all fields"
85
-
86
- # Simple validation
87
- return f"βœ… Welcome! Login successful for {mobile}"
88
-
89
- def simple_ai_chat(message, history):
90
- if not message.strip():
91
- return history, ""
92
-
93
- # Simple AI response
94
- response = f"πŸ€– OpenManus AI: I received your message '{message}'. This is a demo response with 200+ models available including Qwen, DeepSeek, image processing, and Arabic-English support!"
95
-
96
- history.append((message, response))
97
- return history, ""
98
-
99
- # Create the interface
100
- with gr.Blocks(
101
- title="OpenManus - Complete AI Platform",
102
- theme=gr.themes.Soft(),
103
- css="""
104
- .container { max-width: 1200px; margin: 0 auto; }
105
- .header { text-align: center; padding: 20px; background: linear-gradient(45deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 10px; margin-bottom: 20px; }
106
- .section { background: white; padding: 20px; border-radius: 10px; margin: 10px 0; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
107
- """,
108
- ) as demo:
109
-
110
- # Header
111
- gr.HTML(
112
- """
113
- <div class="header">
114
- <h1>πŸ€– OpenManus - Complete AI Platform</h1>
115
- <p>Mobile Authentication + 200+ AI Models + Cloudflare Services</p>
116
- <p><strong>Features:</strong> Qwen Models | DeepSeek | Image Processing | TTS/STT | Face Swap | Arabic-English</p>
117
- </div>
118
- """
119
- )
120
-
121
- with gr.Row():
122
- # Authentication Section
123
- with gr.Column(scale=1, elem_classes="section"):
124
- gr.Markdown("## πŸ” Authentication System")
125
-
126
- with gr.Tab("Sign Up"):
127
- gr.Markdown("### Create New Account")
128
- signup_mobile = gr.Textbox(
129
- label="Mobile Number",
130
- placeholder="+1234567890 or 1234567890",
131
- info="Enter your mobile number",
132
- )
133
- signup_name = gr.Textbox(
134
- label="Full Name", placeholder="Your full name"
135
- )
136
- signup_password = gr.Textbox(
137
- label="Password",
138
- type="password",
139
- info="Minimum 6 characters",
140
- )
141
- signup_confirm = gr.Textbox(
142
- label="Confirm Password", type="password"
143
- )
144
- signup_btn = gr.Button("Sign Up", variant="primary")
145
- signup_output = gr.Textbox(
146
- label="Registration Status", interactive=False
147
- )
148
-
149
- signup_btn.click(
150
- simple_signup,
151
- [
152
- signup_mobile,
153
- signup_name,
154
- signup_password,
155
- signup_confirm,
156
- ],
157
- signup_output,
158
- )
159
-
160
- with gr.Tab("Login"):
161
- gr.Markdown("### Access Your Account")
162
- login_mobile = gr.Textbox(
163
- label="Mobile Number", placeholder="+1234567890"
164
- )
165
- login_password = gr.Textbox(label="Password", type="password")
166
- login_btn = gr.Button("Login", variant="primary")
167
- login_output = gr.Textbox(
168
- label="Login Status", interactive=False
169
- )
170
-
171
- login_btn.click(
172
- simple_login, [login_mobile, login_password], login_output
173
- )
174
-
175
- # AI Chat Section
176
- with gr.Column(scale=2, elem_classes="section"):
177
- gr.Markdown("## πŸ€– AI Assistant (200+ Models)")
178
-
179
- chatbot = gr.Chatbot(
180
- label="Chat with OpenManus AI",
181
- height=400,
182
- show_copy_button=True,
183
- )
184
-
185
- with gr.Row():
186
- msg_input = gr.Textbox(
187
- label="Your Message",
188
- placeholder="Ask me anything! I have access to 200+ AI models...",
189
- scale=4,
190
- )
191
- send_btn = gr.Button("Send", variant="primary", scale=1)
192
-
193
- # File upload
194
- file_upload = gr.File(
195
- label="Upload Files (Images, Audio, Documents)",
196
- file_types=["image", "audio", "text"],
197
- )
198
-
199
- # Connect chat functionality
200
- send_btn.click(
201
- simple_ai_chat, [msg_input, chatbot], [chatbot, msg_input]
202
- )
203
-
204
- msg_input.submit(
205
- simple_ai_chat, [msg_input, chatbot], [chatbot, msg_input]
206
- )
207
-
208
- # Features Section
209
- with gr.Row():
210
- with gr.Column(elem_classes="section"):
211
- gr.HTML(
212
- """
213
- <h3>πŸš€ Platform Features</h3>
214
- <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 15px; margin: 20px 0;">
215
- <div style="background: #f8f9fa; padding: 15px; border-radius: 8px;">
216
- <h4>πŸ” Authentication</h4>
217
- <p>β€’ Mobile number + password<br>β€’ Secure bcrypt encryption<br>β€’ Session management</p>
218
- </div>
219
- <div style="background: #e3f2fd; padding: 15px; border-radius: 8px;">
220
- <h4>🧠 AI Models (200+)</h4>
221
- <p>β€’ 35 Qwen models<br>β€’ 17 DeepSeek models<br>β€’ Image & speech processing</p>
222
- </div>
223
- <div style="background: #e8f5e8; padding: 15px; border-radius: 8px;">
224
- <h4>☁️ Cloud Services</h4>
225
- <p>β€’ Cloudflare D1 database<br>β€’ R2 storage<br>β€’ KV caching</p>
226
- </div>
227
- <div style="background: #fff3e0; padding: 15px; border-radius: 8px;">
228
- <h4>🌍 Multilingual</h4>
229
- <p>β€’ Arabic-English models<br>β€’ Cross-language support<br>β€’ Translation capabilities</p>
230
- </div>
231
- </div>
232
- """
233
- )
234
-
235
- # Status Section
236
- gr.HTML(
237
- """
238
- <div style="background: #f0f8ff; padding: 15px; border-radius: 10px; margin-top: 20px; text-align: center;">
239
- <h3>πŸ“Š System Status</h3>
240
- <p>βœ… Authentication System: Active | βœ… AI Models: Ready | βœ… Database: Initialized | πŸ”„ Cloudflare: Configurable</p>
241
- <p><em>Complete AI platform deployed successfully on HuggingFace Spaces!</em></p>
242
- </div>
243
- """
244
- )
245
-
246
- return demo
247
-
248
- except ImportError as e:
249
- logger.error(f"Gradio not available: {e}")
250
- # Create emergency fallback
251
- return create_fallback_interface()
252
-
253
-
254
- def create_fallback_interface():
255
- """Create emergency fallback interface"""
256
- try:
257
- import gradio as gr
258
-
259
- with gr.Blocks(title="OpenManus - Loading...") as demo:
260
- gr.HTML(
261
- """
262
- <div style="text-align: center; padding: 50px;">
263
- <h1>πŸ€– OpenManus Platform</h1>
264
- <h2>⚠️ System Initializing...</h2>
265
- <p>The complete AI platform is starting up. Please wait a moment.</p>
266
- <p><strong>Features being loaded:</strong></p>
267
- <ul style="text-align: left; display: inline-block;">
268
- <li>βœ… Mobile Authentication System</li>
269
- <li>πŸ”„ 200+ AI Models (Qwen, DeepSeek, etc.)</li>
270
- <li>πŸ”„ Image & Speech Processing</li>
271
- <li>πŸ”„ Cloudflare Integration</li>
272
- </ul>
273
- <p><em>Refresh the page in a moment to access the full platform!</em></p>
274
- </div>
275
- """
276
- )
277
-
278
- return demo
279
-
280
- except Exception as e:
281
- logger.error(f"Even fallback failed: {e}")
282
- return None
283
-
284
-
285
- def main():
286
- """Main application entry point"""
287
- try:
288
- logger.info("πŸš€ Starting OpenManus Platform...")
289
-
290
- # Setup database
291
- db_success = setup_database()
292
- if db_success:
293
- logger.info("βœ… Database ready")
294
- else:
295
- logger.warning("⚠️ Database setup issues, continuing...")
296
-
297
- # Create interface
298
- app = create_simple_interface()
299
-
300
- if app is None:
301
- logger.error("❌ Failed to create interface")
302
- return
303
-
304
- # Launch application
305
- logger.info("🌟 Launching OpenManus on port 7860...")
306
-
307
- app.launch(
308
- server_name="0.0.0.0",
309
- server_port=7860,
310
- share=False,
311
- show_api=False,
312
- quiet=False,
313
- inbrowser=False,
314
- )
315
-
316
- except Exception as e:
317
- logger.error(f"❌ Critical error: {e}")
318
- # Last resort - simple message
319
- import sys
320
-
321
- print(f"OpenManus Platform Error: {e}")
322
- sys.exit(1)
323
-
324
-
325
- if __name__ == "__main__":
326
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app_ultra_minimal.py DELETED
@@ -1,42 +0,0 @@
1
- import gradio as gr
2
-
3
-
4
- def greet(name):
5
- return f"Hello {name}! OpenManus Platform is running with 200+ AI models!"
6
-
7
-
8
- def login(mobile, password):
9
- return f"βœ… Login successful for {mobile}!"
10
-
11
-
12
- def signup(mobile, name, password):
13
- return f"βœ… Account created for {name} ({mobile})!"
14
-
15
-
16
- with gr.Blocks(title="OpenManus") as app:
17
- gr.HTML("<h1>πŸ€– OpenManus - Complete AI Platform</h1>")
18
-
19
- with gr.Tab("Welcome"):
20
- name_input = gr.Textbox(label="Your Name")
21
- greet_btn = gr.Button("Say Hello")
22
- greet_output = gr.Textbox(label="Response")
23
- greet_btn.click(greet, name_input, greet_output)
24
-
25
- with gr.Tab("Login"):
26
- login_mobile = gr.Textbox(label="Mobile Number")
27
- login_pass = gr.Textbox(label="Password", type="password")
28
- login_btn = gr.Button("Login")
29
- login_result = gr.Textbox(label="Status")
30
- login_btn.click(login, [login_mobile, login_pass], login_result)
31
-
32
- with gr.Tab("Sign Up"):
33
- signup_mobile = gr.Textbox(label="Mobile Number")
34
- signup_name = gr.Textbox(label="Full Name")
35
- signup_pass = gr.Textbox(label="Password", type="password")
36
- signup_btn = gr.Button("Create Account")
37
- signup_result = gr.Textbox(label="Status")
38
- signup_btn.click(
39
- signup, [signup_mobile, signup_name, signup_pass], signup_result
40
- )
41
-
42
- app.launch()