rahul7star commited on
Commit
6eb9546
·
verified ·
1 Parent(s): e34f78d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -54
app.py CHANGED
@@ -6,21 +6,22 @@ import pandas as pd
6
  from datasets import load_dataset
7
 
8
  # ======================================================
9
- # QUOTA CONFIG (ONLY FIX HERE)
10
  # ======================================================
11
- LIMIT = 3 # max unlock attempts
12
- WINDOW = 86400 # 24 hours
13
- usage = {} # in-memory session store
14
 
15
 
16
  def quota_guard(fn):
17
  def wrapper(*args, request: gr.Request = None, **kwargs):
 
18
  session = request.session_hash if request else "global"
19
  now = time.time()
20
 
21
  count, start = usage.get(session, (0, now))
22
 
23
- # Reset after 24 hours
24
  if now - start > WINDOW:
25
  count = 0
26
  start = now
@@ -28,12 +29,14 @@ def quota_guard(fn):
28
  if count >= LIMIT:
29
  raise gr.Error(
30
  "🚫 Demo limit reached.\n\n"
31
- "You have used all 3 unlock attempts today.\n"
32
- "Please come back after 24 hours."
33
  )
34
 
35
  usage[session] = (count + 1, start)
36
- return fn(*args, **kwargs)
 
 
37
 
38
  return wrapper
39
 
@@ -79,13 +82,7 @@ def render_grid(page, page_size):
79
  for _, row in batch.iterrows():
80
  cards.append(f"""
81
  <div class="card">
82
- <video
83
- src="{row[VIDEO_COL]}"
84
- controls
85
- controlsList="nodownload noplaybackrate"
86
- disablePictureInPicture
87
- preload="metadata"
88
- ></video>
89
  <div class="meta">
90
  <div class="date">{row[DATE_COL]}</div>
91
  <div class="caption">{row[TEXT_COL]}</div>
@@ -125,8 +122,8 @@ def check_password(user_password, request: gr.Request):
125
  if user_password == APP_PASSWORD:
126
  html, page = render_grid(0, 5)
127
  return (
128
- gr.update(visible=False), # hide login
129
- gr.update(visible=True), # show app
130
  html,
131
  page,
132
  "✅ Access granted"
@@ -155,7 +152,6 @@ css = """
155
  background: #0b1220;
156
  border-radius: 14px;
157
  padding: 12px;
158
- box-shadow: 0 10px 30px rgba(0,0,0,0.45);
159
  }
160
 
161
  .card video {
@@ -163,45 +159,18 @@ css = """
163
  border-radius: 12px;
164
  }
165
 
166
- .meta {
167
- margin-top: 10px;
168
- }
169
-
170
- .date {
171
- font-size: 12px;
172
- color: #94a3b8;
173
- }
174
-
175
- .caption {
176
- font-size: 14px;
177
- color: #e5e7eb;
178
- line-height: 1.4;
179
- max-height: 4.2em;
180
- overflow: hidden;
181
- }
182
-
183
- .page-info {
184
- margin-top: 14px;
185
- text-align: center;
186
- color: #c7d2fe;
187
- }
188
-
189
  .footer {
190
  position: fixed;
191
  bottom: 0;
192
- left: 0;
193
- z-index: 9999;
194
  width: 100%;
195
  text-align: center;
196
  padding: 10px;
197
  font-size: 12px;
198
  background: #0b1220;
199
  color: #cbd5f5;
200
- border-top: 1px solid #1e293b;
201
  }
202
 
203
- footer,
204
- .gradio-footer {
205
  display: none !important;
206
  }
207
  """
@@ -213,20 +182,14 @@ footer,
213
  with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
214
  gr.Markdown("# 🔐 OhamLab Video Showcase (PRO Access)")
215
 
216
- # -------- LOGIN --------
217
  with gr.Column(visible=True) as login_box:
218
- password_input = gr.Textbox(
219
- label="Enter Password",
220
- type="password",
221
- placeholder="Password"
222
- )
223
  login_btn = gr.Button("Unlock")
224
  login_status = gr.Markdown()
225
 
226
- # -------- APP --------
227
  with gr.Column(visible=False) as app_content:
228
  with gr.Row():
229
- page_size = gr.Dropdown([1, 5, 10], value=5, label="Videos per page")
230
  page_state = gr.State(0)
231
 
232
  gallery = gr.HTML()
 
6
  from datasets import load_dataset
7
 
8
  # ======================================================
9
+ # QUOTA CONFIG
10
  # ======================================================
11
+ LIMIT = 3
12
+ WINDOW = 86400 # 24 hours
13
+ usage = {} # session_hash -> (count, start_time)
14
 
15
 
16
  def quota_guard(fn):
17
  def wrapper(*args, request: gr.Request = None, **kwargs):
18
+ # ---- session id ----
19
  session = request.session_hash if request else "global"
20
  now = time.time()
21
 
22
  count, start = usage.get(session, (0, now))
23
 
24
+ # Reset after window
25
  if now - start > WINDOW:
26
  count = 0
27
  start = now
 
29
  if count >= LIMIT:
30
  raise gr.Error(
31
  "🚫 Demo limit reached.\n\n"
32
+ "You can unlock only 3 times per day.\n"
33
+ "Please try again after 24 hours."
34
  )
35
 
36
  usage[session] = (count + 1, start)
37
+
38
+ # IMPORTANT: forward request explicitly
39
+ return fn(*args, request=request, **kwargs)
40
 
41
  return wrapper
42
 
 
82
  for _, row in batch.iterrows():
83
  cards.append(f"""
84
  <div class="card">
85
+ <video src="{row[VIDEO_COL]}" controls preload="metadata"></video>
 
 
 
 
 
 
86
  <div class="meta">
87
  <div class="date">{row[DATE_COL]}</div>
88
  <div class="caption">{row[TEXT_COL]}</div>
 
122
  if user_password == APP_PASSWORD:
123
  html, page = render_grid(0, 5)
124
  return (
125
+ gr.update(visible=False),
126
+ gr.update(visible=True),
127
  html,
128
  page,
129
  "✅ Access granted"
 
152
  background: #0b1220;
153
  border-radius: 14px;
154
  padding: 12px;
 
155
  }
156
 
157
  .card video {
 
159
  border-radius: 12px;
160
  }
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  .footer {
163
  position: fixed;
164
  bottom: 0;
 
 
165
  width: 100%;
166
  text-align: center;
167
  padding: 10px;
168
  font-size: 12px;
169
  background: #0b1220;
170
  color: #cbd5f5;
 
171
  }
172
 
173
+ footer, .gradio-footer {
 
174
  display: none !important;
175
  }
176
  """
 
182
  with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
183
  gr.Markdown("# 🔐 OhamLab Video Showcase (PRO Access)")
184
 
 
185
  with gr.Column(visible=True) as login_box:
186
+ password_input = gr.Textbox(type="password", label="Password")
 
 
 
 
187
  login_btn = gr.Button("Unlock")
188
  login_status = gr.Markdown()
189
 
 
190
  with gr.Column(visible=False) as app_content:
191
  with gr.Row():
192
+ page_size = gr.Dropdown([1, 5, 10], value=5)
193
  page_state = gr.State(0)
194
 
195
  gallery = gr.HTML()