Preview-vs-save flow, interactive recreate checkbox, top status message
Browse files
app.py
CHANGED
|
@@ -119,7 +119,7 @@ def lookup_participant(username: str):
|
|
| 119 |
def on_load(profile: gr.OAuthProfile | None):
|
| 120 |
"""Runs on page load. Drives which panel is shown, pre-fills the form, and β if the user
|
| 121 |
already generated a certificate β shows it and reveals the 'Recreate' control."""
|
| 122 |
-
|
| 123 |
|
| 124 |
if profile is None:
|
| 125 |
return (
|
|
@@ -131,7 +131,7 @@ def on_load(profile: gr.OAuthProfile | None):
|
|
| 131 |
"", # data_status
|
| 132 |
None, # certificate_image
|
| 133 |
None, # certificate_file
|
| 134 |
-
|
| 135 |
"", # generation_status
|
| 136 |
)
|
| 137 |
|
|
@@ -145,7 +145,7 @@ def on_load(profile: gr.OAuthProfile | None):
|
|
| 145 |
gr.update(visible=False),
|
| 146 |
gr.update(visible=True),
|
| 147 |
"", gr.update(value="", visible=True), "",
|
| 148 |
-
None, None,
|
| 149 |
)
|
| 150 |
|
| 151 |
name_value = full_name or profile_name
|
|
@@ -176,10 +176,10 @@ def on_load(profile: gr.OAuthProfile | None):
|
|
| 176 |
"- Want to **replace** your saved copy? Tick **Recreate certificate** below, then generate. "
|
| 177 |
"There's one certificate per participant, so the new one overwrites the old."
|
| 178 |
)
|
| 179 |
-
cb =
|
| 180 |
else:
|
| 181 |
gen_status = ""
|
| 182 |
-
cb =
|
| 183 |
|
| 184 |
return (
|
| 185 |
f"Signed in as **{username}**.",
|
|
@@ -207,7 +207,7 @@ def generate_linkedin_url(participant_name, project_name):
|
|
| 207 |
# ----------------------------------------------------------------------------- generate
|
| 208 |
def create_certificate(participant_name, project_name, recreate,
|
| 209 |
oauth_token: gr.OAuthToken | None, profile: gr.OAuthProfile | None):
|
| 210 |
-
hide_cb = gr.update(
|
| 211 |
if profile is None:
|
| 212 |
return None, None, "β Please sign in first to generate your certificate.", "", hide_cb
|
| 213 |
|
|
@@ -245,9 +245,9 @@ def create_certificate(participant_name, project_name, recreate,
|
|
| 245 |
client = get_gradio_client()
|
| 246 |
image_path = client.predict(html_file=handle_file(html_path), api_name="/predict")[0]
|
| 247 |
except Exception as e:
|
| 248 |
-
return None, None, f"β Error generating certificate image: {e}", "", gr.update(
|
| 249 |
|
| 250 |
-
show_cb = gr.update(
|
| 251 |
linkedin_url = generate_linkedin_url(participant_name, project_name)
|
| 252 |
|
| 253 |
# Decide what happens to the SAVED copy in the dataset.
|
|
@@ -321,8 +321,9 @@ button.primary, .bs-generate button{background:var(--forest) !important;border:2
|
|
| 321 |
.bs-contact a{color:var(--forest);font-weight:700;}
|
| 322 |
.bs-linkedin{display:inline-block;background:var(--ink);color:var(--paper) !important;text-decoration:none;
|
| 323 |
font-weight:800;padding:11px 20px;border:2px solid var(--ink);box-shadow:3px 3px 0 var(--amber);}
|
| 324 |
-
input, textarea{border-radius:0 !important;
|
| 325 |
-
|
|
|
|
| 326 |
footer{display:none !important;}
|
| 327 |
"""
|
| 328 |
|
|
@@ -384,7 +385,8 @@ with gr.Blocks(title="Build Small β Certificate Generator") as demo:
|
|
| 384 |
)
|
| 385 |
recreate_checkbox = gr.Checkbox(
|
| 386 |
label="Recreate certificate β replace the copy saved in our records",
|
| 387 |
-
|
|
|
|
| 388 |
)
|
| 389 |
with gr.Row(elem_classes=["bs-generate"]):
|
| 390 |
generate_btn = gr.Button("Generate my certificate", variant="primary", size="lg")
|
|
|
|
| 119 |
def on_load(profile: gr.OAuthProfile | None):
|
| 120 |
"""Runs on page load. Drives which panel is shown, pre-fills the form, and β if the user
|
| 121 |
already generated a certificate β shows it and reveals the 'Recreate' control."""
|
| 122 |
+
reset_cb = gr.update(value=False) # never toggle the checkbox's own visibility (keeps it interactive)
|
| 123 |
|
| 124 |
if profile is None:
|
| 125 |
return (
|
|
|
|
| 131 |
"", # data_status
|
| 132 |
None, # certificate_image
|
| 133 |
None, # certificate_file
|
| 134 |
+
reset_cb, # recreate_checkbox
|
| 135 |
"", # generation_status
|
| 136 |
)
|
| 137 |
|
|
|
|
| 145 |
gr.update(visible=False),
|
| 146 |
gr.update(visible=True),
|
| 147 |
"", gr.update(value="", visible=True), "",
|
| 148 |
+
None, None, reset_cb, "",
|
| 149 |
)
|
| 150 |
|
| 151 |
name_value = full_name or profile_name
|
|
|
|
| 176 |
"- Want to **replace** your saved copy? Tick **Recreate certificate** below, then generate. "
|
| 177 |
"There's one certificate per participant, so the new one overwrites the old."
|
| 178 |
)
|
| 179 |
+
cb = reset_cb
|
| 180 |
else:
|
| 181 |
gen_status = ""
|
| 182 |
+
cb = reset_cb
|
| 183 |
|
| 184 |
return (
|
| 185 |
f"Signed in as **{username}**.",
|
|
|
|
| 207 |
# ----------------------------------------------------------------------------- generate
|
| 208 |
def create_certificate(participant_name, project_name, recreate,
|
| 209 |
oauth_token: gr.OAuthToken | None, profile: gr.OAuthProfile | None):
|
| 210 |
+
hide_cb = gr.update(value=False)
|
| 211 |
if profile is None:
|
| 212 |
return None, None, "β Please sign in first to generate your certificate.", "", hide_cb
|
| 213 |
|
|
|
|
| 245 |
client = get_gradio_client()
|
| 246 |
image_path = client.predict(html_file=handle_file(html_path), api_name="/predict")[0]
|
| 247 |
except Exception as e:
|
| 248 |
+
return None, None, f"β Error generating certificate image: {e}", "", gr.update(value=False)
|
| 249 |
|
| 250 |
+
show_cb = gr.update(value=False)
|
| 251 |
linkedin_url = generate_linkedin_url(participant_name, project_name)
|
| 252 |
|
| 253 |
# Decide what happens to the SAVED copy in the dataset.
|
|
|
|
| 321 |
.bs-contact a{color:var(--forest);font-weight:700;}
|
| 322 |
.bs-linkedin{display:inline-block;background:var(--ink);color:var(--paper) !important;text-decoration:none;
|
| 323 |
font-weight:800;padding:11px 20px;border:2px solid var(--ink);box-shadow:3px 3px 0 var(--amber);}
|
| 324 |
+
input:not([type='checkbox']):not([type='radio']), textarea{border-radius:0 !important;
|
| 325 |
+
border:2px solid var(--ink) !important;background:#fff !important;
|
| 326 |
+
font-family:'Spline Sans Mono',monospace !important;}
|
| 327 |
footer{display:none !important;}
|
| 328 |
"""
|
| 329 |
|
|
|
|
| 385 |
)
|
| 386 |
recreate_checkbox = gr.Checkbox(
|
| 387 |
label="Recreate certificate β replace the copy saved in our records",
|
| 388 |
+
info="Only matters once you already have a saved certificate β tick it to overwrite the stored copy.",
|
| 389 |
+
value=False, visible=True, interactive=True,
|
| 390 |
)
|
| 391 |
with gr.Row(elem_classes=["bs-generate"]):
|
| 392 |
generate_btn = gr.Button("Generate my certificate", variant="primary", size="lg")
|