Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import sqlite3
|
| 3 |
import hashlib
|
|
|
|
| 4 |
|
| 5 |
# ---------------- Database Setup ----------------
|
| 6 |
-
|
|
|
|
| 7 |
cursor = conn.cursor()
|
| 8 |
|
| 9 |
# Users table
|
|
@@ -52,7 +54,7 @@ def register_admin(username, password):
|
|
| 52 |
cursor.execute("INSERT INTO users(username,password_hash) VALUES (?,?)", (username, password_hash))
|
| 53 |
conn.commit()
|
| 54 |
return "Admin registered successfully!"
|
| 55 |
-
except:
|
| 56 |
return "Username already exists!"
|
| 57 |
|
| 58 |
def check_login(username, password):
|
|
@@ -168,4 +170,5 @@ with gr.Blocks() as demo:
|
|
| 168 |
delete_expense_btn.click(delete_expense, [expense_id], expenses_output)
|
| 169 |
view_expenses_btn.click(view_expenses, [], expenses_output)
|
| 170 |
|
|
|
|
| 171 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import sqlite3
|
| 3 |
import hashlib
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
# ---------------- Database Setup ----------------
|
| 7 |
+
DB_PATH = './family.db' # relative path for HF Space
|
| 8 |
+
conn = sqlite3.connect(DB_PATH, check_same_thread=False)
|
| 9 |
cursor = conn.cursor()
|
| 10 |
|
| 11 |
# Users table
|
|
|
|
| 54 |
cursor.execute("INSERT INTO users(username,password_hash) VALUES (?,?)", (username, password_hash))
|
| 55 |
conn.commit()
|
| 56 |
return "Admin registered successfully!"
|
| 57 |
+
except sqlite3.IntegrityError:
|
| 58 |
return "Username already exists!"
|
| 59 |
|
| 60 |
def check_login(username, password):
|
|
|
|
| 170 |
delete_expense_btn.click(delete_expense, [expense_id], expenses_output)
|
| 171 |
view_expenses_btn.click(view_expenses, [], expenses_output)
|
| 172 |
|
| 173 |
+
# ---------------- Launch without errors ----------------
|
| 174 |
demo.launch()
|