Spaces:
Runtime error
Runtime error
Kushal commited on
Commit ·
6fa3cde
1
Parent(s): 34c2ec3
Admin access fix & automated creation via HF Secret
Browse files- Dockerfile +2 -2
- hf_make_admin.py +20 -0
Dockerfile
CHANGED
|
@@ -31,5 +31,5 @@ ENV PORT=7860
|
|
| 31 |
# Expose port
|
| 32 |
EXPOSE ${PORT}
|
| 33 |
|
| 34 |
-
# Start uvicorn with configurable port
|
| 35 |
-
CMD uvicorn app.main:app --host 0.0.0.0 --port ${PORT}
|
|
|
|
| 31 |
# Expose port
|
| 32 |
EXPOSE ${PORT}
|
| 33 |
|
| 34 |
+
# Start uvicorn with configurable port (and run admin script)
|
| 35 |
+
CMD python hf_make_admin.py && uvicorn app.main:app --host 0.0.0.0 --port ${PORT}
|
hf_make_admin.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sqlite3
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# This script will run on HF Spaces and make the email provided in the ADMIN_EMAIL secret an admin
|
| 5 |
+
email = os.environ.get('ADMIN_EMAIL')
|
| 6 |
+
|
| 7 |
+
if not email:
|
| 8 |
+
print("❌ ADMIN_EMAIL environment variable not set. Please add it to HF Space Secrets.")
|
| 9 |
+
else:
|
| 10 |
+
try:
|
| 11 |
+
conn = sqlite3.connect('/app/data/database.db')
|
| 12 |
+
conn.execute("UPDATE users SET is_admin = 1 WHERE email = ?", (email,))
|
| 13 |
+
conn.commit()
|
| 14 |
+
if conn.total_changes > 0:
|
| 15 |
+
print(f"✅ User {email} is now an ADMIN!")
|
| 16 |
+
else:
|
| 17 |
+
print(f"⚠️ User {email} not found in database. Sign up with this email first.")
|
| 18 |
+
conn.close()
|
| 19 |
+
except Exception as e:
|
| 20 |
+
print(f"❌ Error: {e}")
|