Speedofmastery commited on
Commit
17b098e
Β·
1 Parent(s): a0f8ceb

Auto-commit: app_simple.py updated

Browse files
Files changed (1) hide show
  1. app_simple.py +96 -87
app_simple.py CHANGED
@@ -14,15 +14,17 @@ from pathlib import Path
14
  logging.basicConfig(level=logging.INFO)
15
  logger = logging.getLogger(__name__)
16
 
 
17
  def setup_database():
18
  """Initialize SQLite database for authentication"""
19
  try:
20
  db_path = Path("auth.db")
21
  conn = sqlite3.connect(db_path)
22
  cursor = conn.cursor()
23
-
24
  # Create users table
25
- cursor.execute("""
 
26
  CREATE TABLE IF NOT EXISTS users (
27
  id INTEGER PRIMARY KEY AUTOINCREMENT,
28
  mobile_number TEXT UNIQUE NOT NULL,
@@ -30,10 +32,12 @@ def setup_database():
30
  password_hash TEXT NOT NULL,
31
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
32
  )
33
- """)
34
-
 
35
  # Create sessions table
36
- cursor.execute("""
 
37
  CREATE TABLE IF NOT EXISTS sessions (
38
  id TEXT PRIMARY KEY,
39
  user_id INTEGER NOT NULL,
@@ -41,8 +45,9 @@ def setup_database():
41
  expires_at TIMESTAMP NOT NULL,
42
  FOREIGN KEY (user_id) REFERENCES users (id)
43
  )
44
- """)
45
-
 
46
  conn.commit()
47
  conn.close()
48
  logger.info("Database initialized successfully")
@@ -51,45 +56,46 @@ def setup_database():
51
  logger.error(f"Database setup failed: {e}")
52
  return False
53
 
 
54
  def create_simple_interface():
55
  """Create a simple Gradio interface"""
56
  try:
57
  import gradio as gr
58
-
59
  # Simple authentication functions
60
  def simple_signup(mobile, name, password, confirm_password):
61
  if not mobile or not name or not password:
62
  return "❌ Please fill in all fields"
63
-
64
  if password != confirm_password:
65
  return "❌ Passwords do not match"
66
-
67
  if len(password) < 6:
68
  return "❌ Password must be at least 6 characters"
69
-
70
  # Simple validation
71
- if not mobile.startswith('+') and not mobile.isdigit():
72
  return "❌ Please enter a valid mobile number"
73
-
74
  return f"βœ… Account created for {name} ({mobile})"
75
-
76
  def simple_login(mobile, password):
77
  if not mobile or not password:
78
  return "❌ Please fill in all fields"
79
-
80
  # Simple validation
81
  return f"βœ… Welcome! Login successful for {mobile}"
82
-
83
  def simple_ai_chat(message, history):
84
  if not message.strip():
85
  return history, ""
86
-
87
  # Simple AI response
88
  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!"
89
-
90
  history.append((message, response))
91
  return history, ""
92
-
93
  # Create the interface
94
  with gr.Blocks(
95
  title="OpenManus - Complete AI Platform",
@@ -98,118 +104,112 @@ def create_simple_interface():
98
  .container { max-width: 1200px; margin: 0 auto; }
99
  .header { text-align: center; padding: 20px; background: linear-gradient(45deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 10px; margin-bottom: 20px; }
100
  .section { background: white; padding: 20px; border-radius: 10px; margin: 10px 0; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
101
- """
102
  ) as demo:
103
-
104
  # Header
105
- gr.HTML("""
 
106
  <div class="header">
107
  <h1>πŸ€– OpenManus - Complete AI Platform</h1>
108
  <p>Mobile Authentication + 200+ AI Models + Cloudflare Services</p>
109
  <p><strong>Features:</strong> Qwen Models | DeepSeek | Image Processing | TTS/STT | Face Swap | Arabic-English</p>
110
  </div>
111
- """)
112
-
 
113
  with gr.Row():
114
  # Authentication Section
115
  with gr.Column(scale=1, elem_classes="section"):
116
  gr.Markdown("## πŸ” Authentication System")
117
-
118
  with gr.Tab("Sign Up"):
119
  gr.Markdown("### Create New Account")
120
  signup_mobile = gr.Textbox(
121
- label="Mobile Number",
122
  placeholder="+1234567890 or 1234567890",
123
- info="Enter your mobile number"
124
  )
125
  signup_name = gr.Textbox(
126
- label="Full Name",
127
- placeholder="Your full name"
128
  )
129
  signup_password = gr.Textbox(
130
- label="Password",
131
  type="password",
132
- info="Minimum 6 characters"
133
  )
134
  signup_confirm = gr.Textbox(
135
- label="Confirm Password",
136
- type="password"
137
  )
138
  signup_btn = gr.Button("Sign Up", variant="primary")
139
  signup_output = gr.Textbox(
140
- label="Registration Status",
141
- interactive=False
142
  )
143
-
144
  signup_btn.click(
145
  simple_signup,
146
- [signup_mobile, signup_name, signup_password, signup_confirm],
147
- signup_output
 
 
 
 
 
148
  )
149
-
150
  with gr.Tab("Login"):
151
  gr.Markdown("### Access Your Account")
152
  login_mobile = gr.Textbox(
153
- label="Mobile Number",
154
- placeholder="+1234567890"
155
- )
156
- login_password = gr.Textbox(
157
- label="Password",
158
- type="password"
159
  )
 
160
  login_btn = gr.Button("Login", variant="primary")
161
  login_output = gr.Textbox(
162
- label="Login Status",
163
- interactive=False
164
  )
165
-
166
  login_btn.click(
167
- simple_login,
168
- [login_mobile, login_password],
169
- login_output
170
  )
171
-
172
  # AI Chat Section
173
  with gr.Column(scale=2, elem_classes="section"):
174
  gr.Markdown("## πŸ€– AI Assistant (200+ Models)")
175
-
176
  chatbot = gr.Chatbot(
177
  label="Chat with OpenManus AI",
178
  height=400,
179
- show_copy_button=True
180
  )
181
-
182
  with gr.Row():
183
  msg_input = gr.Textbox(
184
  label="Your Message",
185
  placeholder="Ask me anything! I have access to 200+ AI models...",
186
- scale=4
187
  )
188
  send_btn = gr.Button("Send", variant="primary", scale=1)
189
-
190
  # File upload
191
  file_upload = gr.File(
192
  label="Upload Files (Images, Audio, Documents)",
193
- file_types=["image", "audio", "text"]
194
  )
195
-
196
  # Connect chat functionality
197
  send_btn.click(
198
- simple_ai_chat,
199
- [msg_input, chatbot],
200
- [chatbot, msg_input]
201
  )
202
-
203
  msg_input.submit(
204
- simple_ai_chat,
205
- [msg_input, chatbot],
206
- [chatbot, msg_input]
207
  )
208
-
209
  # Features Section
210
  with gr.Row():
211
  with gr.Column(elem_classes="section"):
212
- gr.HTML("""
 
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;">
@@ -229,31 +229,36 @@ def create_simple_interface():
229
  <p>β€’ Arabic-English models<br>β€’ Cross-language support<br>β€’ Translation capabilities</p>
230
  </div>
231
  </div>
232
- """)
233
-
 
234
  # Status Section
235
- gr.HTML("""
 
236
  <div style="background: #f0f8ff; padding: 15px; border-radius: 10px; margin-top: 20px; text-align: center;">
237
  <h3>πŸ“Š System Status</h3>
238
  <p>βœ… Authentication System: Active | βœ… AI Models: Ready | βœ… Database: Initialized | πŸ”„ Cloudflare: Configurable</p>
239
  <p><em>Complete AI platform deployed successfully on HuggingFace Spaces!</em></p>
240
  </div>
241
- """)
242
-
 
243
  return demo
244
-
245
  except ImportError as e:
246
  logger.error(f"Gradio not available: {e}")
247
  # Create emergency fallback
248
  return create_fallback_interface()
249
 
 
250
  def create_fallback_interface():
251
  """Create emergency fallback interface"""
252
  try:
253
  import gradio as gr
254
-
255
  with gr.Blocks(title="OpenManus - Loading...") as demo:
256
- gr.HTML("""
 
257
  <div style="text-align: center; padding: 50px;">
258
  <h1>πŸ€– OpenManus Platform</h1>
259
  <h2>⚠️ System Initializing...</h2>
@@ -267,51 +272,55 @@ def create_fallback_interface():
267
  </ul>
268
  <p><em>Refresh the page in a moment to access the full platform!</em></p>
269
  </div>
270
- """)
271
-
 
272
  return demo
273
-
274
  except Exception as e:
275
  logger.error(f"Even fallback failed: {e}")
276
  return None
277
 
 
278
  def main():
279
  """Main application entry point"""
280
  try:
281
  logger.info("πŸš€ Starting OpenManus Platform...")
282
-
283
  # Setup database
284
  db_success = setup_database()
285
  if db_success:
286
  logger.info("βœ… Database ready")
287
  else:
288
  logger.warning("⚠️ Database setup issues, continuing...")
289
-
290
  # Create interface
291
  app = create_simple_interface()
292
-
293
  if app is None:
294
  logger.error("❌ Failed to create interface")
295
  return
296
-
297
  # Launch application
298
  logger.info("🌟 Launching OpenManus on port 7860...")
299
-
300
  app.launch(
301
  server_name="0.0.0.0",
302
  server_port=7860,
303
  share=False,
304
  show_api=False,
305
  quiet=False,
306
- inbrowser=False
307
  )
308
-
309
  except Exception as e:
310
  logger.error(f"❌ Critical error: {e}")
311
  # Last resort - simple message
312
  import sys
 
313
  print(f"OpenManus Platform Error: {e}")
314
  sys.exit(1)
315
 
 
316
  if __name__ == "__main__":
317
- main()
 
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,
 
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,
 
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")
 
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",
 
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;">
 
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>
 
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()