Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -101,6 +101,9 @@ def main():
|
|
| 101 |
"""
|
| 102 |
|
| 103 |
with gr.Blocks(title="DataPass", theme=theme.get_theme(), css=custom_css) as demo:
|
|
|
|
|
|
|
|
|
|
| 104 |
# Hero Section
|
| 105 |
gr.HTML("""
|
| 106 |
<div class="hero-section">
|
|
@@ -411,9 +414,9 @@ def main():
|
|
| 411 |
|
| 412 |
# Catalog Tab
|
| 413 |
with gr.Tab("Catalog", id="catalog"):
|
| 414 |
-
# Use gr.render to
|
| 415 |
-
@gr.render(
|
| 416 |
-
def render_catalog(
|
| 417 |
datasets = utils.get_catalog() or []
|
| 418 |
|
| 419 |
if not datasets:
|
|
@@ -464,7 +467,7 @@ def main():
|
|
| 464 |
|
| 465 |
# Footer with action
|
| 466 |
with gr.Row(elem_classes="card-footer-row"):
|
| 467 |
-
if
|
| 468 |
# User is logged in - show subscribe button
|
| 469 |
btn = gr.Button(
|
| 470 |
button_text,
|
|
@@ -520,11 +523,12 @@ def main():
|
|
| 520 |
</div>
|
| 521 |
""")
|
| 522 |
|
| 523 |
-
# Load user status
|
| 524 |
def load_user_status(profile: gr.OAuthProfile | None):
|
| 525 |
if profile:
|
| 526 |
-
|
| 527 |
-
|
|
|
|
| 528 |
|
| 529 |
# Load subscriptions
|
| 530 |
def load_subscriptions(profile: gr.OAuthProfile | None, token: gr.OAuthToken | None):
|
|
@@ -541,8 +545,8 @@ def main():
|
|
| 541 |
user_subs = utils.get_user_subscriptions(profile.username, hf_token)
|
| 542 |
return subscriptions.create_subscriptions_html(user_subs)
|
| 543 |
|
| 544 |
-
# Load on page load
|
| 545 |
-
demo.load(fn=load_user_status, outputs=[user_status])
|
| 546 |
demo.load(fn=load_subscriptions, outputs=[subscriptions_container])
|
| 547 |
|
| 548 |
return demo
|
|
|
|
| 101 |
"""
|
| 102 |
|
| 103 |
with gr.Blocks(title="DataPass", theme=theme.get_theme(), css=custom_css) as demo:
|
| 104 |
+
# State to track logged-in username (triggers re-render when changed)
|
| 105 |
+
logged_in_user = gr.State(value=None)
|
| 106 |
+
|
| 107 |
# Hero Section
|
| 108 |
gr.HTML("""
|
| 109 |
<div class="hero-section">
|
|
|
|
| 414 |
|
| 415 |
# Catalog Tab
|
| 416 |
with gr.Tab("Catalog", id="catalog"):
|
| 417 |
+
# Use gr.render with State input to re-render when login state changes
|
| 418 |
+
@gr.render(inputs=[logged_in_user])
|
| 419 |
+
def render_catalog(username):
|
| 420 |
datasets = utils.get_catalog() or []
|
| 421 |
|
| 422 |
if not datasets:
|
|
|
|
| 467 |
|
| 468 |
# Footer with action
|
| 469 |
with gr.Row(elem_classes="card-footer-row"):
|
| 470 |
+
if username:
|
| 471 |
# User is logged in - show subscribe button
|
| 472 |
btn = gr.Button(
|
| 473 |
button_text,
|
|
|
|
| 523 |
</div>
|
| 524 |
""")
|
| 525 |
|
| 526 |
+
# Load user status and update login state
|
| 527 |
def load_user_status(profile: gr.OAuthProfile | None):
|
| 528 |
if profile:
|
| 529 |
+
# Return both status text AND username for the State
|
| 530 |
+
return f"👤 Signed in as **{profile.username}**", profile.username
|
| 531 |
+
return "Sign in to subscribe to datasets", None
|
| 532 |
|
| 533 |
# Load subscriptions
|
| 534 |
def load_subscriptions(profile: gr.OAuthProfile | None, token: gr.OAuthToken | None):
|
|
|
|
| 545 |
user_subs = utils.get_user_subscriptions(profile.username, hf_token)
|
| 546 |
return subscriptions.create_subscriptions_html(user_subs)
|
| 547 |
|
| 548 |
+
# Load on page load - update both user_status and logged_in_user state
|
| 549 |
+
demo.load(fn=load_user_status, outputs=[user_status, logged_in_user])
|
| 550 |
demo.load(fn=load_subscriptions, outputs=[subscriptions_container])
|
| 551 |
|
| 552 |
return demo
|