Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,16 @@
|
|
| 1 |
import os
|
| 2 |
import math
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import pandas as pd
|
| 5 |
from datasets import load_dataset
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
WINDOW = 86400
|
| 14 |
-
usage = {}
|
| 15 |
|
| 16 |
def quota_guard(fn):
|
| 17 |
def wrapper(*args, **kwargs):
|
|
@@ -21,12 +20,17 @@ def quota_guard(fn):
|
|
| 21 |
|
| 22 |
count, start = usage.get(session, (0, now))
|
| 23 |
|
|
|
|
| 24 |
if now - start > WINDOW:
|
| 25 |
count = 0
|
| 26 |
start = now
|
| 27 |
|
| 28 |
if count >= LIMIT:
|
| 29 |
-
raise gr.Error(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
usage[session] = (count + 1, start)
|
| 32 |
return fn(*args, **kwargs)
|
|
@@ -34,8 +38,6 @@ def quota_guard(fn):
|
|
| 34 |
return wrapper
|
| 35 |
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
# ======================================================
|
| 40 |
# CONFIG
|
| 41 |
# ======================================================
|
|
@@ -57,7 +59,7 @@ df = dataset.to_pandas()
|
|
| 57 |
df = df[[VIDEO_COL, TEXT_COL, DATE_COL]].dropna().reset_index(drop=True)
|
| 58 |
|
| 59 |
# ======================================================
|
| 60 |
-
# PAGINATION
|
| 61 |
# ======================================================
|
| 62 |
def render_grid(page, page_size):
|
| 63 |
page = int(page)
|
|
@@ -113,7 +115,7 @@ def reset_page(page_size):
|
|
| 113 |
return render_grid(0, page_size)
|
| 114 |
|
| 115 |
# ======================================================
|
| 116 |
-
# AUTH GATE
|
| 117 |
# ======================================================
|
| 118 |
@quota_guard
|
| 119 |
def check_password(user_password):
|
|
@@ -136,10 +138,9 @@ def check_password(user_password):
|
|
| 136 |
)
|
| 137 |
|
| 138 |
# ======================================================
|
| 139 |
-
# CSS
|
| 140 |
# ======================================================
|
| 141 |
css = """
|
| 142 |
-
/* ================= GRID ================= */
|
| 143 |
.grid {
|
| 144 |
display: grid;
|
| 145 |
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
|
@@ -170,9 +171,6 @@ css = """
|
|
| 170 |
.caption {
|
| 171 |
font-size: 14px;
|
| 172 |
color: #e5e7eb;
|
| 173 |
-
line-height: 1.4;
|
| 174 |
-
max-height: 4.2em;
|
| 175 |
-
overflow: hidden;
|
| 176 |
}
|
| 177 |
|
| 178 |
.page-info {
|
|
@@ -181,7 +179,6 @@ css = """
|
|
| 181 |
color: #c7d2fe;
|
| 182 |
}
|
| 183 |
|
| 184 |
-
/* ================= YOUR FOOTER ================= */
|
| 185 |
.footer {
|
| 186 |
position: fixed;
|
| 187 |
bottom: 0;
|
|
@@ -196,19 +193,10 @@ css = """
|
|
| 196 |
border-top: 1px solid #1e293b;
|
| 197 |
}
|
| 198 |
|
| 199 |
-
/*
|
| 200 |
footer,
|
| 201 |
-
.gradio-footer
|
| 202 |
-
#footer,
|
| 203 |
-
.svelte-1ipelgc,
|
| 204 |
-
.svelte-1p9xokt {
|
| 205 |
display: none !important;
|
| 206 |
-
visibility: hidden !important;
|
| 207 |
-
height: 0 !important;
|
| 208 |
-
}
|
| 209 |
-
|
| 210 |
-
body {
|
| 211 |
-
padding-bottom: 0 !important;
|
| 212 |
}
|
| 213 |
"""
|
| 214 |
|
|
@@ -216,19 +204,18 @@ body {
|
|
| 216 |
# UI
|
| 217 |
# ======================================================
|
| 218 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 219 |
-
gr.Markdown("# 🔐 OhamLab Video Showcase
|
| 220 |
|
| 221 |
-
#
|
| 222 |
with gr.Column(visible=True) as login_box:
|
| 223 |
password_input = gr.Textbox(
|
| 224 |
label="Enter Password",
|
| 225 |
-
type="password"
|
| 226 |
-
placeholder="Password"
|
| 227 |
)
|
| 228 |
login_btn = gr.Button("Unlock")
|
| 229 |
login_status = gr.Markdown()
|
| 230 |
|
| 231 |
-
#
|
| 232 |
with gr.Column(visible=False) as app_content:
|
| 233 |
with gr.Row():
|
| 234 |
page_size = gr.Dropdown([1, 5, 10], value=5, label="Videos per page")
|
|
@@ -250,9 +237,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 250 |
outputs=[login_box, app_content, gallery, page_state, login_status]
|
| 251 |
)
|
| 252 |
|
| 253 |
-
|
| 254 |
-
gr.HTML(
|
| 255 |
-
"<div class='footer'>© OhamLab Copyright</div>"
|
| 256 |
-
)
|
| 257 |
|
| 258 |
demo.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
import math
|
| 3 |
+
import time
|
| 4 |
import gradio as gr
|
| 5 |
import pandas as pd
|
| 6 |
from datasets import load_dataset
|
| 7 |
|
| 8 |
+
# ======================================================
|
| 9 |
+
# QUOTA LOGIC (DO NOT TOUCH APP LOGIC)
|
| 10 |
+
# ======================================================
|
| 11 |
+
LIMIT = 3 # max unlocks
|
| 12 |
+
WINDOW = 86400 # 24 hours
|
| 13 |
+
usage = {} # session -> (count, window_start)
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def quota_guard(fn):
|
| 16 |
def wrapper(*args, **kwargs):
|
|
|
|
| 20 |
|
| 21 |
count, start = usage.get(session, (0, now))
|
| 22 |
|
| 23 |
+
# reset window after 24h
|
| 24 |
if now - start > WINDOW:
|
| 25 |
count = 0
|
| 26 |
start = now
|
| 27 |
|
| 28 |
if count >= LIMIT:
|
| 29 |
+
raise gr.Error(
|
| 30 |
+
"🚫 Daily demo limit reached.\n\n"
|
| 31 |
+
"You have used all 3 unlock attempts.\n"
|
| 32 |
+
"Please come back after 24 hours."
|
| 33 |
+
)
|
| 34 |
|
| 35 |
usage[session] = (count + 1, start)
|
| 36 |
return fn(*args, **kwargs)
|
|
|
|
| 38 |
return wrapper
|
| 39 |
|
| 40 |
|
|
|
|
|
|
|
| 41 |
# ======================================================
|
| 42 |
# CONFIG
|
| 43 |
# ======================================================
|
|
|
|
| 59 |
df = df[[VIDEO_COL, TEXT_COL, DATE_COL]].dropna().reset_index(drop=True)
|
| 60 |
|
| 61 |
# ======================================================
|
| 62 |
+
# PAGINATION
|
| 63 |
# ======================================================
|
| 64 |
def render_grid(page, page_size):
|
| 65 |
page = int(page)
|
|
|
|
| 115 |
return render_grid(0, page_size)
|
| 116 |
|
| 117 |
# ======================================================
|
| 118 |
+
# AUTH GATE (QUOTA APPLIED HERE)
|
| 119 |
# ======================================================
|
| 120 |
@quota_guard
|
| 121 |
def check_password(user_password):
|
|
|
|
| 138 |
)
|
| 139 |
|
| 140 |
# ======================================================
|
| 141 |
+
# CSS
|
| 142 |
# ======================================================
|
| 143 |
css = """
|
|
|
|
| 144 |
.grid {
|
| 145 |
display: grid;
|
| 146 |
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
|
|
|
| 171 |
.caption {
|
| 172 |
font-size: 14px;
|
| 173 |
color: #e5e7eb;
|
|
|
|
|
|
|
|
|
|
| 174 |
}
|
| 175 |
|
| 176 |
.page-info {
|
|
|
|
| 179 |
color: #c7d2fe;
|
| 180 |
}
|
| 181 |
|
|
|
|
| 182 |
.footer {
|
| 183 |
position: fixed;
|
| 184 |
bottom: 0;
|
|
|
|
| 193 |
border-top: 1px solid #1e293b;
|
| 194 |
}
|
| 195 |
|
| 196 |
+
/* Hide HF footer */
|
| 197 |
footer,
|
| 198 |
+
.gradio-footer {
|
|
|
|
|
|
|
|
|
|
| 199 |
display: none !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
}
|
| 201 |
"""
|
| 202 |
|
|
|
|
| 204 |
# UI
|
| 205 |
# ======================================================
|
| 206 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 207 |
+
gr.Markdown("# 🔐 OhamLab Video Showcase")
|
| 208 |
|
| 209 |
+
# LOGIN
|
| 210 |
with gr.Column(visible=True) as login_box:
|
| 211 |
password_input = gr.Textbox(
|
| 212 |
label="Enter Password",
|
| 213 |
+
type="password"
|
|
|
|
| 214 |
)
|
| 215 |
login_btn = gr.Button("Unlock")
|
| 216 |
login_status = gr.Markdown()
|
| 217 |
|
| 218 |
+
# APP
|
| 219 |
with gr.Column(visible=False) as app_content:
|
| 220 |
with gr.Row():
|
| 221 |
page_size = gr.Dropdown([1, 5, 10], value=5, label="Videos per page")
|
|
|
|
| 237 |
outputs=[login_box, app_content, gallery, page_state, login_status]
|
| 238 |
)
|
| 239 |
|
| 240 |
+
gr.HTML("<div class='footer'>© OhamLab Copyright</div>")
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
demo.launch()
|