update app.py to change the login visibility
Browse files
app.py
CHANGED
|
@@ -1201,9 +1201,24 @@ CSS = """
|
|
| 1201 |
text-decoration: none !important; }
|
| 1202 |
.gradio-container .dr-mark { height: 32px !important; width: auto !important; margin: 0 !important; }
|
| 1203 |
.gradio-container .dr-word { height: 20px !important; width: auto !important; margin: 0 !important; }
|
| 1204 |
-
#dr-login { max-width:
|
| 1205 |
-
#dr-login button { border-radius:
|
| 1206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1207 |
|
| 1208 |
/* hero */
|
| 1209 |
.gradio-container .dr-hero { text-align: center !important; padding: 64px 0 44px; position: relative; z-index: 1; }
|
|
@@ -1429,9 +1444,10 @@ body.dr-sliding, body.dr-sliding * { cursor: grabbing !important; user-select: n
|
|
| 1429 |
.gradio-container .dr-meta span + span::before { content: none; }
|
| 1430 |
.gradio-container .dr-hero-actions a.dr-btn { flex: 1 1 100%; text-align: center; }
|
| 1431 |
.gradio-container .dr-head { min-height: 0; }
|
|
|
|
| 1432 |
.gradio-container .dr-card { padding: 16px !important; }
|
| 1433 |
.gradio-container .dr-mark { height: 28px !important; } .dr-word { height: 17px !important; }
|
| 1434 |
-
#dr-login button { font-size: 12px !important; padding:
|
| 1435 |
.gradio-container .dr-cta-btns { width: 100%; } .gradio-container .dr-cta-btns a.dr-btn { flex: 1 1 100%; text-align: center; }
|
| 1436 |
.gradio-container .dr-section { padding-top: 64px !important; }
|
| 1437 |
.gradio-container .dr-foot { grid-template-columns: 1fr; margin-top: 64px; }
|
|
@@ -1478,12 +1494,17 @@ FORCE_DARK = """
|
|
| 1478 |
}
|
| 1479 |
} catch (e) {}
|
| 1480 |
document.addEventListener('click', (e) => {
|
| 1481 |
-
const btn = e.target.closest && e.target.closest('#dr-login');
|
| 1482 |
if (!btn || !window.__drFramedNoCookies) return;
|
| 1483 |
if (!/sign in/i.test(btn.textContent || '')) return; // leave "Logout" alone
|
| 1484 |
e.preventDefault(); e.stopImmediatePropagation();
|
| 1485 |
window.open(window.location.origin + '/login/huggingface?_target_url=/', '_blank', 'noopener');
|
| 1486 |
}, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1487 |
// Before/after: switch examples
|
| 1488 |
document.addEventListener('click', (e) => {
|
| 1489 |
const chip = e.target.closest && e.target.closest('.dr-ba-chip'); if (!chip) return;
|
|
@@ -1611,7 +1632,7 @@ fetch_samples()
|
|
| 1611 |
def remaining_html(profile: gr.OAuthProfile | None = None):
|
| 1612 |
"""Free allowance line next to the Generate button, with the live balance for signed-in users."""
|
| 1613 |
if profile is None:
|
| 1614 |
-
left = "
|
| 1615 |
elif is_admin(profile.username):
|
| 1616 |
left = "Team account: no daily limit."
|
| 1617 |
else:
|
|
@@ -1627,6 +1648,12 @@ def remaining_html(profile: gr.OAuthProfile | None = None):
|
|
| 1627 |
HIDE_DL = gr.update(visible=False, value=None)
|
| 1628 |
|
| 1629 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1630 |
def generate(video, mood, excited, angry, updates, preset_name, profile: gr.OAuthProfile | None):
|
| 1631 |
"""UI wrapper around run(): adds the download button and the remaining-generations line."""
|
| 1632 |
last = (None, IDLE)
|
|
@@ -1647,7 +1674,7 @@ with gr.Blocks(title=PAGE_TITLE) as demo:
|
|
| 1647 |
gr.HTML('<div class="dr-glow"></div>')
|
| 1648 |
with gr.Row(elem_id="dr-top"):
|
| 1649 |
gr.HTML(logo_html())
|
| 1650 |
-
gr.LoginButton(elem_id="dr-login", size="sm")
|
| 1651 |
|
| 1652 |
gr.HTML(f"""
|
| 1653 |
<header class="dr-hero">
|
|
@@ -1691,7 +1718,9 @@ with gr.Blocks(title=PAGE_TITLE) as demo:
|
|
| 1691 |
angry = gr.Slider(0, 1, value=d_ang, step=0.05, label="Anger",
|
| 1692 |
info="0 = no added anger · 1 = strongest anger")
|
| 1693 |
quota = gr.HTML(remaining_html())
|
| 1694 |
-
|
|
|
|
|
|
|
| 1695 |
updates = gr.Checkbox(label="Email me DRAMA product updates and offers.", value=False,
|
| 1696 |
container=False, elem_id="dr-optin")
|
| 1697 |
gr.HTML('<div class="dr-fine">Only upload footage you have the right to edit, with permission from '
|
|
@@ -1775,6 +1804,7 @@ with gr.Blocks(title=PAGE_TITLE) as demo:
|
|
| 1775 |
api_visibility="private")
|
| 1776 |
demo.load(on_visit, inputs=None, outputs=None, api_visibility="private", show_progress="hidden")
|
| 1777 |
demo.load(remaining_html, inputs=None, outputs=[quota], api_visibility="private", show_progress="hidden")
|
|
|
|
| 1778 |
go.click(
|
| 1779 |
generate,
|
| 1780 |
inputs=[video_in, mood, excited, angry, updates, preset],
|
|
@@ -1798,4 +1828,6 @@ def favicon_file():
|
|
| 1798 |
startup_check()
|
| 1799 |
demo.queue(max_size=20).launch(theme=THEME, css=CSS, js=FORCE_DARK, head=HEAD,
|
| 1800 |
allowed_paths=[os.path.abspath(SAMPLES_DIR), os.path.abspath("examples"), SAMPLES_CACHE],
|
| 1801 |
-
favicon_path=favicon_file(), footer_links=[])
|
|
|
|
|
|
|
|
|
| 1201 |
text-decoration: none !important; }
|
| 1202 |
.gradio-container .dr-mark { height: 32px !important; width: auto !important; margin: 0 !important; }
|
| 1203 |
.gradio-container .dr-word { height: 20px !important; width: auto !important; margin: 0 !important; }
|
| 1204 |
+
#dr-login { max-width: 280px; margin-left: auto; flex: none !important; width: auto !important; }
|
| 1205 |
+
.gradio-container #dr-login, .gradio-container #dr-login button { border-radius: 10px !important; }
|
| 1206 |
+
.gradio-container #dr-login button, .gradio-container button#dr-login {
|
| 1207 |
+
background: #fff !important; color: #111 !important; border: 1px solid #fff !important;
|
| 1208 |
+
font-size: 14px !important; font-weight: 600 !important; padding: 9px 16px !important;
|
| 1209 |
+
box-shadow: 0 0 0 4px rgba(255,255,255,.08) !important; }
|
| 1210 |
+
.gradio-container #dr-login button:hover, .gradio-container button#dr-login:hover { background: #e9e9ee !important; }
|
| 1211 |
+
/* once signed in it becomes a quiet account button */
|
| 1212 |
+
.gradio-container .dr-signed-in#dr-login, .gradio-container .dr-signed-in#dr-login button,
|
| 1213 |
+
.gradio-container #dr-login.dr-signed-in button {
|
| 1214 |
+
background: transparent !important; color: var(--dr-muted) !important; border: 1px solid var(--dr-line) !important;
|
| 1215 |
+
box-shadow: none !important; font-weight: 500 !important; font-size: 13px !important; }
|
| 1216 |
+
/* in-form sign-in, shown in place of Generate while signed out */
|
| 1217 |
+
.gradio-container #dr-login-cta, .gradio-container #dr-login-cta button {
|
| 1218 |
+
width: 100% !important; background: #fff !important; color: #111 !important; border: 1px solid #fff !important;
|
| 1219 |
+
border-radius: 10px !important; font-size: 16px !important; font-weight: 700 !important; min-height: 50px; }
|
| 1220 |
+
.gradio-container #dr-login-cta:hover, .gradio-container #dr-login-cta button:hover { background: #e9e9ee !important; }
|
| 1221 |
+
.gradio-container #dr-login-cta img, .gradio-container #dr-login img { filter: none !important; }
|
| 1222 |
|
| 1223 |
/* hero */
|
| 1224 |
.gradio-container .dr-hero { text-align: center !important; padding: 64px 0 44px; position: relative; z-index: 1; }
|
|
|
|
| 1444 |
.gradio-container .dr-meta span + span::before { content: none; }
|
| 1445 |
.gradio-container .dr-hero-actions a.dr-btn { flex: 1 1 100%; text-align: center; }
|
| 1446 |
.gradio-container .dr-head { min-height: 0; }
|
| 1447 |
+
.gradio-container #dr-login-cta, .gradio-container #dr-login-cta button { font-size: 15px !important; }
|
| 1448 |
.gradio-container .dr-card { padding: 16px !important; }
|
| 1449 |
.gradio-container .dr-mark { height: 28px !important; } .dr-word { height: 17px !important; }
|
| 1450 |
+
.gradio-container #dr-login button, .gradio-container button#dr-login { font-size: 12px !important; padding: 7px 10px !important; }
|
| 1451 |
.gradio-container .dr-cta-btns { width: 100%; } .gradio-container .dr-cta-btns a.dr-btn { flex: 1 1 100%; text-align: center; }
|
| 1452 |
.gradio-container .dr-section { padding-top: 64px !important; }
|
| 1453 |
.gradio-container .dr-foot { grid-template-columns: 1fr; margin-top: 64px; }
|
|
|
|
| 1494 |
}
|
| 1495 |
} catch (e) {}
|
| 1496 |
document.addEventListener('click', (e) => {
|
| 1497 |
+
const btn = e.target.closest && e.target.closest('#dr-login, #dr-login-cta');
|
| 1498 |
if (!btn || !window.__drFramedNoCookies) return;
|
| 1499 |
if (!/sign in/i.test(btn.textContent || '')) return; // leave "Logout" alone
|
| 1500 |
e.preventDefault(); e.stopImmediatePropagation();
|
| 1501 |
window.open(window.location.origin + '/login/huggingface?_target_url=/', '_blank', 'noopener');
|
| 1502 |
}, true);
|
| 1503 |
+
const markSignedIn = () => {
|
| 1504 |
+
const b = document.getElementById('dr-login'); if (!b) return;
|
| 1505 |
+
b.classList.toggle('dr-signed-in', /^\\s*sign out/i.test(b.textContent || ''));
|
| 1506 |
+
};
|
| 1507 |
+
new MutationObserver(markSignedIn).observe(document.body, { childList: true, subtree: true, characterData: true });
|
| 1508 |
// Before/after: switch examples
|
| 1509 |
document.addEventListener('click', (e) => {
|
| 1510 |
const chip = e.target.closest && e.target.closest('.dr-ba-chip'); if (!chip) return;
|
|
|
|
| 1632 |
def remaining_html(profile: gr.OAuthProfile | None = None):
|
| 1633 |
"""Free allowance line next to the Generate button, with the live balance for signed-in users."""
|
| 1634 |
if profile is None:
|
| 1635 |
+
left = "Free with a Hugging Face account."
|
| 1636 |
elif is_admin(profile.username):
|
| 1637 |
left = "Team account: no daily limit."
|
| 1638 |
else:
|
|
|
|
| 1648 |
HIDE_DL = gr.update(visible=False, value=None)
|
| 1649 |
|
| 1650 |
|
| 1651 |
+
def signin_state(profile: gr.OAuthProfile | None = None):
|
| 1652 |
+
"""Signed out: the big sign-in button sits where Generate goes. Signed in: show Generate."""
|
| 1653 |
+
signed_in = profile is not None
|
| 1654 |
+
return gr.update(visible=not signed_in), gr.update(visible=signed_in)
|
| 1655 |
+
|
| 1656 |
+
|
| 1657 |
def generate(video, mood, excited, angry, updates, preset_name, profile: gr.OAuthProfile | None):
|
| 1658 |
"""UI wrapper around run(): adds the download button and the remaining-generations line."""
|
| 1659 |
last = (None, IDLE)
|
|
|
|
| 1674 |
gr.HTML('<div class="dr-glow"></div>')
|
| 1675 |
with gr.Row(elem_id="dr-top"):
|
| 1676 |
gr.HTML(logo_html())
|
| 1677 |
+
gr.LoginButton("Sign in with Hugging Face", logout_value="Sign out ({})", elem_id="dr-login", size="sm")
|
| 1678 |
|
| 1679 |
gr.HTML(f"""
|
| 1680 |
<header class="dr-hero">
|
|
|
|
| 1718 |
angry = gr.Slider(0, 1, value=d_ang, step=0.05, label="Anger",
|
| 1719 |
info="0 = no added anger · 1 = strongest anger")
|
| 1720 |
quota = gr.HTML(remaining_html())
|
| 1721 |
+
login_cta = gr.LoginButton("Sign in with Hugging Face to generate", logout_value="Sign out ({})",
|
| 1722 |
+
elem_id="dr-login-cta", size="lg")
|
| 1723 |
+
go = gr.Button("Generate edited video", variant="primary", elem_id="dr-go", visible=False)
|
| 1724 |
updates = gr.Checkbox(label="Email me DRAMA product updates and offers.", value=False,
|
| 1725 |
container=False, elem_id="dr-optin")
|
| 1726 |
gr.HTML('<div class="dr-fine">Only upload footage you have the right to edit, with permission from '
|
|
|
|
| 1804 |
api_visibility="private")
|
| 1805 |
demo.load(on_visit, inputs=None, outputs=None, api_visibility="private", show_progress="hidden")
|
| 1806 |
demo.load(remaining_html, inputs=None, outputs=[quota], api_visibility="private", show_progress="hidden")
|
| 1807 |
+
demo.load(signin_state, inputs=None, outputs=[login_cta, go], api_visibility="private", show_progress="hidden")
|
| 1808 |
go.click(
|
| 1809 |
generate,
|
| 1810 |
inputs=[video_in, mood, excited, angry, updates, preset],
|
|
|
|
| 1828 |
startup_check()
|
| 1829 |
demo.queue(max_size=20).launch(theme=THEME, css=CSS, js=FORCE_DARK, head=HEAD,
|
| 1830 |
allowed_paths=[os.path.abspath(SAMPLES_DIR), os.path.abspath("examples"), SAMPLES_CACHE],
|
| 1831 |
+
favicon_path=favicon_file(), footer_links=[])
|
| 1832 |
+
|
| 1833 |
+
|