Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,7 @@ DB_PATH = DATA_DIR / "usage_limits.db"
|
|
| 21 |
|
| 22 |
DAILY_LIMIT_STANDARD = 75
|
| 23 |
DAILY_LIMIT_PRO = 50
|
| 24 |
-
EXEMPTED_USERS = [
|
| 25 |
db_lock = Lock()
|
| 26 |
|
| 27 |
def init_db():
|
|
@@ -29,16 +29,53 @@ def init_db():
|
|
| 29 |
print(f"Initializing database at: {DB_PATH}")
|
| 30 |
try:
|
| 31 |
with sqlite3.connect(DB_PATH) as conn:
|
| 32 |
-
conn.
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
print(f"Error initializing database: {e}")
|
| 44 |
import traceback
|
|
@@ -457,6 +494,8 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=css) as demo:
|
|
| 457 |
model_radio = gr.Radio(
|
| 458 |
choices=["Nano Banana", "Nano Banana PRO"],
|
| 459 |
value="Nano Banana PRO",
|
|
|
|
|
|
|
| 460 |
)
|
| 461 |
|
| 462 |
with gr.Row():
|
|
@@ -468,13 +507,14 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=css) as demo:
|
|
| 468 |
)
|
| 469 |
|
| 470 |
resolution_dropdown = gr.Dropdown(
|
| 471 |
-
label="Resolution",
|
| 472 |
choices=["1K", "2K", "4K"],
|
| 473 |
value="1K",
|
| 474 |
interactive=True,
|
|
|
|
| 475 |
)
|
| 476 |
|
| 477 |
-
|
| 478 |
|
| 479 |
generate_button = gr.Button("Generate", variant="primary")
|
| 480 |
with gr.Column(scale=1):
|
|
|
|
| 21 |
|
| 22 |
DAILY_LIMIT_STANDARD = 75
|
| 23 |
DAILY_LIMIT_PRO = 50
|
| 24 |
+
EXEMPTED_USERS = []
|
| 25 |
db_lock = Lock()
|
| 26 |
|
| 27 |
def init_db():
|
|
|
|
| 29 |
print(f"Initializing database at: {DB_PATH}")
|
| 30 |
try:
|
| 31 |
with sqlite3.connect(DB_PATH) as conn:
|
| 32 |
+
cursor = conn.cursor()
|
| 33 |
+
|
| 34 |
+
# Check if table exists and what columns it has
|
| 35 |
+
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='usage'")
|
| 36 |
+
table_exists = cursor.fetchone()
|
| 37 |
+
|
| 38 |
+
if table_exists:
|
| 39 |
+
# Check current schema
|
| 40 |
+
cursor.execute("PRAGMA table_info(usage)")
|
| 41 |
+
columns = [col[1] for col in cursor.fetchall()]
|
| 42 |
+
|
| 43 |
+
# Migrate if old schema (only has 'count' column)
|
| 44 |
+
if 'count' in columns and 'count_standard' not in columns:
|
| 45 |
+
print("Migrating database from old schema to new schema...")
|
| 46 |
+
# Rename old count to count_standard, add count_pro
|
| 47 |
+
cursor.execute("ALTER TABLE usage RENAME COLUMN count TO count_standard")
|
| 48 |
+
cursor.execute("ALTER TABLE usage ADD COLUMN count_pro INTEGER NOT NULL DEFAULT 0")
|
| 49 |
+
conn.commit()
|
| 50 |
+
print("Database migration completed successfully")
|
| 51 |
+
elif 'count_standard' not in columns:
|
| 52 |
+
# Table exists but doesn't have the right columns - recreate it
|
| 53 |
+
print("Recreating table with new schema...")
|
| 54 |
+
cursor.execute("DROP TABLE usage")
|
| 55 |
+
cursor.execute('''
|
| 56 |
+
CREATE TABLE usage (
|
| 57 |
+
username TEXT PRIMARY KEY,
|
| 58 |
+
date TEXT NOT NULL,
|
| 59 |
+
count_standard INTEGER NOT NULL DEFAULT 0,
|
| 60 |
+
count_pro INTEGER NOT NULL DEFAULT 0
|
| 61 |
+
)
|
| 62 |
+
''')
|
| 63 |
+
conn.commit()
|
| 64 |
+
print("Database recreated successfully")
|
| 65 |
+
else:
|
| 66 |
+
print("Database schema is already up to date")
|
| 67 |
+
else:
|
| 68 |
+
# Create new table with updated schema
|
| 69 |
+
cursor.execute('''
|
| 70 |
+
CREATE TABLE IF NOT EXISTS usage (
|
| 71 |
+
username TEXT PRIMARY KEY,
|
| 72 |
+
date TEXT NOT NULL,
|
| 73 |
+
count_standard INTEGER NOT NULL DEFAULT 0,
|
| 74 |
+
count_pro INTEGER NOT NULL DEFAULT 0
|
| 75 |
+
)
|
| 76 |
+
''')
|
| 77 |
+
conn.commit()
|
| 78 |
+
print("Database initialized successfully")
|
| 79 |
except Exception as e:
|
| 80 |
print(f"Error initializing database: {e}")
|
| 81 |
import traceback
|
|
|
|
| 494 |
model_radio = gr.Radio(
|
| 495 |
choices=["Nano Banana", "Nano Banana PRO"],
|
| 496 |
value="Nano Banana PRO",
|
| 497 |
+
label="Model Selection",
|
| 498 |
+
info="PRO: Higher quality, slower generation (50 credits/day) | Standard: Faster generation (75/day)"
|
| 499 |
)
|
| 500 |
|
| 501 |
with gr.Row():
|
|
|
|
| 507 |
)
|
| 508 |
|
| 509 |
resolution_dropdown = gr.Dropdown(
|
| 510 |
+
label="Resolution (PRO only)",
|
| 511 |
choices=["1K", "2K", "4K"],
|
| 512 |
value="1K",
|
| 513 |
interactive=True,
|
| 514 |
+
visible=True
|
| 515 |
)
|
| 516 |
|
| 517 |
+
gr.Markdown("💡 **Credit costs:** 1K = 1 credit, 2K = 2 credits, 4K = 4 credits")
|
| 518 |
|
| 519 |
generate_button = gr.Button("Generate", variant="primary")
|
| 520 |
with gr.Column(scale=1):
|