Spaces:
Running
Running
css update
Browse files
app.py
CHANGED
|
@@ -117,8 +117,6 @@ def crop_face(img: Image.Image):
|
|
| 117 |
# Prediction function
|
| 118 |
# ============================
|
| 119 |
def predict(img):
|
| 120 |
-
# Step 1: Show initial placeholder
|
| 121 |
-
yield "<div style='font-size:40px; font-weight:bold; color:#555; text-align:center;'>99+ years lifespan</div>"
|
| 122 |
|
| 123 |
# Step 2: Fake progress updates
|
| 124 |
for i in range(3):
|
|
@@ -134,7 +132,7 @@ def predict(img):
|
|
| 134 |
mu, logvar = model(x)
|
| 135 |
pred_years = mu.item() * lifespan_std + lifespan_mean
|
| 136 |
|
| 137 |
-
yield f"<div style='font-size:42px; font-weight:bold; color:#2E86AB; text-align:center;'>Estimated remaining lifespan: {pred_years:.1f} years</div>"
|
| 138 |
# ============================
|
| 139 |
# Gradio UI (Webcam + Upload)
|
| 140 |
# ============================
|
|
@@ -152,24 +150,40 @@ img3.save("example3.jpg")
|
|
| 152 |
demo = gr.Interface(
|
| 153 |
fn=predict,
|
| 154 |
inputs=gr.Image(height=500, type="pil", sources=["upload", "webcam"], label="Face Photo"),
|
| 155 |
-
outputs=gr.HTML(label="Prediction", elem_id="pred-box"),
|
| 156 |
live=False,
|
| 157 |
title="Lifespan Predictor (Demo)",
|
| 158 |
description="Upload or take a face photo. Model predicts remaining lifespan (years).",
|
| 159 |
examples=[["example1.jpg"],["example2.jpg"],["example3.jpg"]], # π make sure example.jpg exists in repo
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
)
|
| 174 |
demo.queue()
|
| 175 |
if __name__ == "__main__":
|
|
|
|
| 117 |
# Prediction function
|
| 118 |
# ============================
|
| 119 |
def predict(img):
|
|
|
|
|
|
|
| 120 |
|
| 121 |
# Step 2: Fake progress updates
|
| 122 |
for i in range(3):
|
|
|
|
| 132 |
mu, logvar = model(x)
|
| 133 |
pred_years = mu.item() * lifespan_std + lifespan_mean
|
| 134 |
|
| 135 |
+
yield f"<div style='font-size:42px; font-weight:bold; color:#2E86AB; text-align:center;'>Estimated remaining lifespan: <br> {pred_years:.1f} years</div>"
|
| 136 |
# ============================
|
| 137 |
# Gradio UI (Webcam + Upload)
|
| 138 |
# ============================
|
|
|
|
| 150 |
demo = gr.Interface(
|
| 151 |
fn=predict,
|
| 152 |
inputs=gr.Image(height=500, type="pil", sources=["upload", "webcam"], label="Face Photo"),
|
| 153 |
+
outputs=gr.HTML(label="Prediction", elem_id="pred-box", value="<div style='font-size:36px; font-weight:bold; color:#2E86AB; text-align:center;'>Predict remaining lifespan: <br> ??? years</div>"),
|
| 154 |
live=False,
|
| 155 |
title="Lifespan Predictor (Demo)",
|
| 156 |
description="Upload or take a face photo. Model predicts remaining lifespan (years).",
|
| 157 |
examples=[["example1.jpg"],["example2.jpg"],["example3.jpg"]], # π make sure example.jpg exists in repo
|
| 158 |
+
css="""
|
| 159 |
+
#pred-box {
|
| 160 |
+
/* size & layout to mirror the image area */
|
| 161 |
+
height: 500px; /* match inputs=gr.Image(height=500) */
|
| 162 |
+
display: flex;
|
| 163 |
+
align-items: center;
|
| 164 |
+
justify-content: center;
|
| 165 |
+
text-align: center;
|
| 166 |
+
|
| 167 |
+
/* typography */
|
| 168 |
+
font-size: 42px;
|
| 169 |
+
font-weight: 700;
|
| 170 |
+
color: var(--body-text-color);
|
| 171 |
+
|
| 172 |
+
/* make it look like a Gradio card */
|
| 173 |
+
background: var(--block-background-fill);
|
| 174 |
+
border: 1px solid var(--border-color);
|
| 175 |
+
border-radius: var(--radius-lg);
|
| 176 |
+
box-shadow: var(--shadow-drop);
|
| 177 |
+
padding: 16px;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
/* tighten the label spacing so it feels like the input card */
|
| 181 |
+
#pred-box + .wrap.svelte-1ipelgc, /* older gradio */
|
| 182 |
+
#pred-box + .container.svelte-1ipelgc, /* fallback */
|
| 183 |
+
#pred-box:has(+ *) { /* future-proof: keep label close */
|
| 184 |
+
margin-top: 0;
|
| 185 |
+
}
|
| 186 |
+
"""
|
| 187 |
)
|
| 188 |
demo.queue()
|
| 189 |
if __name__ == "__main__":
|