Spaces:
Running
Running
Chandima Prabhath
commited on
Commit
Β·
b2ef8c6
1
Parent(s):
05a6e54
Refactor prepare_tables function to use raw SQL for creating users and images tables
Browse files
app.py
CHANGED
@@ -51,32 +51,26 @@ app = FastAPI()
|
|
51 |
def prepare_tables():
|
52 |
"""
|
53 |
Ensure 'users' and 'images' tables exist. Creates them if they don't.
|
|
|
54 |
"""
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
chat_id TEXT NOT NULL,
|
74 |
-
prompt TEXT NOT NULL,
|
75 |
-
url TEXT NOT NULL,
|
76 |
-
created_at BIGINT NOT NULL
|
77 |
-
);
|
78 |
-
"""}
|
79 |
-
).execute()
|
80 |
|
81 |
# βββββ Inactivity Monitor βββββ
|
82 |
def inactivity_monitor():
|
@@ -346,10 +340,14 @@ def index():
|
|
346 |
return "Eve is running! π"
|
347 |
|
348 |
if __name__ == "__main__":
|
349 |
-
# prepare Supabase schema
|
350 |
prepare_tables()
|
|
|
|
|
351 |
threading.Thread(target=inactivity_monitor, daemon=True).start()
|
352 |
threading.Thread(target=worker, daemon=True).start()
|
|
|
|
|
353 |
send_startup_message()
|
354 |
import uvicorn
|
355 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
51 |
def prepare_tables():
|
52 |
"""
|
53 |
Ensure 'users' and 'images' tables exist. Creates them if they don't.
|
54 |
+
Uses postgrest.raw() to execute raw SQL.
|
55 |
"""
|
56 |
+
users_sql = """
|
57 |
+
CREATE TABLE IF NOT EXISTS users (
|
58 |
+
id SERIAL PRIMARY KEY,
|
59 |
+
chat_id TEXT UNIQUE NOT NULL,
|
60 |
+
created_at BIGINT NOT NULL
|
61 |
+
);
|
62 |
+
"""
|
63 |
+
images_sql = """
|
64 |
+
CREATE TABLE IF NOT EXISTS images (
|
65 |
+
id SERIAL PRIMARY KEY,
|
66 |
+
chat_id TEXT NOT NULL,
|
67 |
+
prompt TEXT NOT NULL,
|
68 |
+
url TEXT NOT NULL,
|
69 |
+
created_at BIGINT NOT NULL
|
70 |
+
);
|
71 |
+
"""
|
72 |
+
supabase.postgrest.raw(users_sql).execute()
|
73 |
+
supabase.postgrest.raw(images_sql).execute()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
# βββββ Inactivity Monitor βββββ
|
76 |
def inactivity_monitor():
|
|
|
340 |
return "Eve is running! π"
|
341 |
|
342 |
if __name__ == "__main__":
|
343 |
+
# 1) prepare Supabase schema
|
344 |
prepare_tables()
|
345 |
+
|
346 |
+
# 2) start background threads
|
347 |
threading.Thread(target=inactivity_monitor, daemon=True).start()
|
348 |
threading.Thread(target=worker, daemon=True).start()
|
349 |
+
|
350 |
+
# 3) send startup message & run server
|
351 |
send_startup_message()
|
352 |
import uvicorn
|
353 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|