Speedofmastery commited on
Commit
4e704c1
Β·
1 Parent(s): 691fbab

Deploy complete working OpenManus platform - syntax validated

Browse files
Files changed (1) hide show
  1. app.py +40 -103
app.py CHANGED
@@ -1,43 +1,10 @@
1
- #!/usr/bin/env python3
2
- """
3
- OpenManus - Complete AI Platform
4
- Linux-optimized deployment for HuggingFace Spaces
5
- """
6
-
7
  import gradio as gr
8
  import os
9
- import sys
10
  import json
11
  import sqlite3
12
  import hashlib
13
  import datetime
14
  from pathlib import Path
15
- import logging
16
-
17
- # Configure logging for Linux environment
18
- try:
19
- # Try to create logs directory if it doesn't exist
20
- log_dir = Path("/home/user/app/logs")
21
- log_dir.mkdir(parents=True, exist_ok=True)
22
-
23
- logging.basicConfig(
24
- level=logging.INFO,
25
- format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
26
- handlers=[
27
- logging.StreamHandler(sys.stdout),
28
- logging.FileHandler("/home/user/app/logs/openmanus.log", mode="a"),
29
- ],
30
- )
31
- except Exception:
32
- # Fallback to console-only logging
33
- logging.basicConfig(
34
- level=logging.INFO,
35
- format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
36
- handlers=[logging.StreamHandler(sys.stdout)],
37
- )
38
-
39
- logger = logging.getLogger(__name__)
40
- logger.info("🐧 OpenManus Platform starting on Linux environment")
41
 
42
  # Cloudflare configuration
43
  CLOUDFLARE_CONFIG = {
@@ -224,21 +191,14 @@ AI_MODELS = {
224
 
225
 
226
  def init_database():
227
- """Initialize SQLite database for authentication - Linux optimized"""
228
- try:
229
- # Use Linux-friendly paths
230
- data_dir = Path("/home/user/app/data")
231
- data_dir.mkdir(exist_ok=True)
232
-
233
- db_path = data_dir / "openmanus.db"
234
- logger.info(f"Initializing database at {db_path}")
235
 
236
- conn = sqlite3.connect(str(db_path))
237
- cursor = conn.cursor()
238
-
239
- # Create users table
240
- cursor.execute(
241
- """
242
  CREATE TABLE IF NOT EXISTS users (
243
  id INTEGER PRIMARY KEY AUTOINCREMENT,
244
  mobile_number TEXT UNIQUE NOT NULL,
@@ -249,48 +209,43 @@ def init_database():
249
  is_active BOOLEAN DEFAULT 1
250
  )
251
  """
252
- )
253
 
254
- # Create sessions table
255
- cursor.execute(
256
- """
257
- CREATE TABLE IF NOT EXISTS sessions (
258
- id TEXT PRIMARY KEY,
259
- user_id INTEGER NOT NULL,
260
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
261
- expires_at TIMESTAMP NOT NULL,
262
- ip_address TEXT,
263
- user_agent TEXT,
264
- FOREIGN KEY (user_id) REFERENCES users (id)
265
- )
266
  """
267
- )
 
 
 
 
 
 
 
 
 
 
268
 
269
- # Create model usage table
270
- cursor.execute(
271
- """
272
- CREATE TABLE IF NOT EXISTS model_usage (
273
- id INTEGER PRIMARY KEY AUTOINCREMENT,
274
- user_id INTEGER,
275
- model_name TEXT NOT NULL,
276
- category TEXT NOT NULL,
277
- input_text TEXT,
278
- output_text TEXT,
279
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
280
- processing_time REAL,
281
- FOREIGN KEY (user_id) REFERENCES users (id)
282
- )
283
  """
284
- )
285
-
286
- conn.commit()
287
- conn.close()
288
- logger.info("Database initialized successfully")
289
- return True
 
 
 
 
 
 
 
290
 
291
- except Exception as e:
292
- logger.error(f"Database initialization failed: {e}")
293
- return False
294
 
295
 
296
  def hash_password(password):
@@ -757,22 +712,4 @@ with gr.Blocks(
757
  )
758
 
759
  if __name__ == "__main__":
760
- logger.info("πŸš€ Launching OpenManus Platform...")
761
-
762
- try:
763
- # Initialize database
764
- init_database()
765
-
766
- # Launch with Linux-optimized settings
767
- app.launch(
768
- server_name="0.0.0.0",
769
- server_port=7860,
770
- share=False,
771
- debug=False,
772
- enable_queue=True,
773
- show_error=True,
774
- quiet=False,
775
- )
776
- except Exception as e:
777
- logger.error(f"Failed to launch application: {e}")
778
- sys.exit(1)
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import os
 
3
  import json
4
  import sqlite3
5
  import hashlib
6
  import datetime
7
  from pathlib import Path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  # Cloudflare configuration
10
  CLOUDFLARE_CONFIG = {
 
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,
 
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,
220
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
221
+ expires_at TIMESTAMP NOT NULL,
222
+ ip_address TEXT,
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,
235
+ model_name TEXT NOT NULL,
236
+ category TEXT NOT NULL,
237
+ input_text TEXT,
238
+ output_text TEXT,
239
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
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):
 
712
  )
713
 
714
  if __name__ == "__main__":
715
+ app.launch(server_name="0.0.0.0", server_port=7860)