Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import math
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
|
@@ -12,15 +13,14 @@ VIDEO_COL = "video"
|
|
| 12 |
TEXT_COL = "text"
|
| 13 |
DATE_COL = "date"
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# ======================================================
|
| 16 |
# LOAD DATASET (PRIVATE-SAFE)
|
| 17 |
# ======================================================
|
| 18 |
-
|
| 19 |
-
# - `huggingface-cli login`
|
| 20 |
-
# - or HUGGINGFACE_HUB_TOKEN env var
|
| 21 |
-
dataset = load_dataset(DATASET_NAME, split="test")
|
| 22 |
-
|
| 23 |
-
# Convert to pandas for easy slicing
|
| 24 |
df = dataset.to_pandas()
|
| 25 |
df = df[[VIDEO_COL, TEXT_COL, DATE_COL]].dropna().reset_index(drop=True)
|
| 26 |
|
|
@@ -79,6 +79,28 @@ def prev_page(page, page_size):
|
|
| 79 |
def reset_page(page_size):
|
| 80 |
return render_grid(0, page_size)
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
# ======================================================
|
| 83 |
# UI
|
| 84 |
# ======================================================
|
|
@@ -99,17 +121,13 @@ css = """
|
|
| 99 |
.card video {
|
| 100 |
width: 100%;
|
| 101 |
border-radius: 12px;
|
| 102 |
-
outline: none;
|
| 103 |
}
|
| 104 |
|
| 105 |
-
.meta {
|
| 106 |
-
margin-top: 10px;
|
| 107 |
-
}
|
| 108 |
|
| 109 |
.date {
|
| 110 |
font-size: 12px;
|
| 111 |
color: #94a3b8;
|
| 112 |
-
margin-bottom: 4px;
|
| 113 |
}
|
| 114 |
|
| 115 |
.caption {
|
|
@@ -124,54 +142,42 @@ css = """
|
|
| 124 |
margin-top: 14px;
|
| 125 |
text-align: center;
|
| 126 |
color: #c7d2fe;
|
| 127 |
-
font-weight: 500;
|
| 128 |
}
|
| 129 |
"""
|
| 130 |
|
| 131 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 132 |
-
gr.Markdown(
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
page_size = gr.Dropdown(
|
| 141 |
-
choices=[1, 5, 10],
|
| 142 |
-
value=5,
|
| 143 |
-
label="Videos per page"
|
| 144 |
)
|
| 145 |
-
|
|
|
|
| 146 |
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
-
|
| 150 |
-
prev_btn = gr.Button("⬅ Previous")
|
| 151 |
-
next_btn = gr.Button("Next ➡")
|
| 152 |
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
outputs=[gallery, page_state]
|
| 157 |
-
)
|
| 158 |
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
outputs=[gallery, page_state]
|
| 163 |
-
)
|
| 164 |
-
|
| 165 |
-
prev_btn.click(
|
| 166 |
-
prev_page,
|
| 167 |
-
inputs=[page_state, page_size],
|
| 168 |
-
outputs=[gallery, page_state]
|
| 169 |
-
)
|
| 170 |
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
inputs=
|
| 174 |
-
outputs=[gallery, page_state]
|
| 175 |
)
|
| 176 |
|
| 177 |
demo.launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
import math
|
| 3 |
import gradio as gr
|
| 4 |
import pandas as pd
|
|
|
|
| 13 |
TEXT_COL = "text"
|
| 14 |
DATE_COL = "date"
|
| 15 |
|
| 16 |
+
APP_PASSWORD = os.getenv("APP_PASSWORD")
|
| 17 |
+
if not APP_PASSWORD:
|
| 18 |
+
raise RuntimeError("APP_PASSWORD environment variable not set")
|
| 19 |
+
|
| 20 |
# ======================================================
|
| 21 |
# LOAD DATASET (PRIVATE-SAFE)
|
| 22 |
# ======================================================
|
| 23 |
+
dataset = load_dataset(DATASET_NAME, split="train")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
df = dataset.to_pandas()
|
| 25 |
df = df[[VIDEO_COL, TEXT_COL, DATE_COL]].dropna().reset_index(drop=True)
|
| 26 |
|
|
|
|
| 79 |
def reset_page(page_size):
|
| 80 |
return render_grid(0, page_size)
|
| 81 |
|
| 82 |
+
# ======================================================
|
| 83 |
+
# AUTH GATE
|
| 84 |
+
# ======================================================
|
| 85 |
+
def check_password(user_password):
|
| 86 |
+
if user_password == APP_PASSWORD:
|
| 87 |
+
html, page = render_grid(0, 5)
|
| 88 |
+
return (
|
| 89 |
+
gr.update(visible=False), # hide password box
|
| 90 |
+
gr.update(visible=True), # show app content
|
| 91 |
+
html,
|
| 92 |
+
page,
|
| 93 |
+
"✅ Access granted"
|
| 94 |
+
)
|
| 95 |
+
else:
|
| 96 |
+
return (
|
| 97 |
+
gr.update(visible=True),
|
| 98 |
+
gr.update(visible=False),
|
| 99 |
+
"",
|
| 100 |
+
0,
|
| 101 |
+
"❌ Incorrect password"
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
# ======================================================
|
| 105 |
# UI
|
| 106 |
# ======================================================
|
|
|
|
| 121 |
.card video {
|
| 122 |
width: 100%;
|
| 123 |
border-radius: 12px;
|
|
|
|
| 124 |
}
|
| 125 |
|
| 126 |
+
.meta { margin-top: 10px; }
|
|
|
|
|
|
|
| 127 |
|
| 128 |
.date {
|
| 129 |
font-size: 12px;
|
| 130 |
color: #94a3b8;
|
|
|
|
| 131 |
}
|
| 132 |
|
| 133 |
.caption {
|
|
|
|
| 142 |
margin-top: 14px;
|
| 143 |
text-align: center;
|
| 144 |
color: #c7d2fe;
|
|
|
|
| 145 |
}
|
| 146 |
"""
|
| 147 |
|
| 148 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 149 |
+
gr.Markdown("# 🔐 Wan Video Dataset (Password Protected)")
|
| 150 |
+
|
| 151 |
+
# -------- Password Gate --------
|
| 152 |
+
with gr.Column(visible=True) as login_box:
|
| 153 |
+
password_input = gr.Textbox(
|
| 154 |
+
label="Enter Password",
|
| 155 |
+
type="password",
|
| 156 |
+
placeholder="Password"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
)
|
| 158 |
+
login_btn = gr.Button("Unlock")
|
| 159 |
+
login_status = gr.Markdown()
|
| 160 |
|
| 161 |
+
# -------- Main App (Hidden) --------
|
| 162 |
+
with gr.Column(visible=False) as app_content:
|
| 163 |
+
with gr.Row():
|
| 164 |
+
page_size = gr.Dropdown([1, 5, 10], value=5, label="Videos per page")
|
| 165 |
+
page_state = gr.State(0)
|
| 166 |
|
| 167 |
+
gallery = gr.HTML()
|
|
|
|
|
|
|
| 168 |
|
| 169 |
+
with gr.Row():
|
| 170 |
+
prev_btn = gr.Button("⬅ Previous")
|
| 171 |
+
next_btn = gr.Button("Next ➡")
|
|
|
|
|
|
|
| 172 |
|
| 173 |
+
next_btn.click(next_page, [page_state, page_size], [gallery, page_state])
|
| 174 |
+
prev_btn.click(prev_page, [page_state, page_size], [gallery, page_state])
|
| 175 |
+
page_size.change(reset_page, [page_size], [gallery, page_state])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
+
login_btn.click(
|
| 178 |
+
check_password,
|
| 179 |
+
inputs=password_input,
|
| 180 |
+
outputs=[login_box, app_content, gallery, page_state, login_status]
|
| 181 |
)
|
| 182 |
|
| 183 |
demo.launch()
|