Spaces:
Running
Running
Add example images and improve model download logging in app.py
Browse files- app.py +5 -2
- examples/girl.jpg +0 -0
- examples/trump.jpg +0 -0
app.py
CHANGED
@@ -15,12 +15,11 @@ os.makedirs("model", exist_ok=True)
|
|
15 |
if not os.path.exists(MODEL_PATH):
|
16 |
print("Starting model download at", time.strftime("%Y-%m-%d %H:%M:%S"))
|
17 |
path = hf_hub_download(repo_id="Robys01/face-aging", filename="best_unet_model.pth", local_dir="model", cache_dir="model")
|
18 |
-
print("Model downloaded to
|
19 |
|
20 |
model = UNet()
|
21 |
model.load_state_dict(torch.load(MODEL_PATH, map_location=torch.device("cpu"), weights_only=False))
|
22 |
model.eval()
|
23 |
-
print("Model loaded at", time.strftime("%Y-%m-%d %H:%M:%S"))
|
24 |
|
25 |
def age_image(image: Image.Image, source_age: int, target_age: int) -> Image.Image:
|
26 |
# Ensure the image is in RGB or grayscale; if not, convert it.
|
@@ -39,6 +38,10 @@ iface = gr.Interface(
|
|
39 |
gr.Slider(10, 90, value=70, step=1, label="Target age", info="Choose the desired age")
|
40 |
],
|
41 |
outputs=gr.Image(type="pil", label="Aged Image"),
|
|
|
|
|
|
|
|
|
42 |
title="Face Aging Demo",
|
43 |
description="Upload an image along with a source age approximation and a target age to generate an aged version of the face."
|
44 |
)
|
|
|
15 |
if not os.path.exists(MODEL_PATH):
|
16 |
print("Starting model download at", time.strftime("%Y-%m-%d %H:%M:%S"))
|
17 |
path = hf_hub_download(repo_id="Robys01/face-aging", filename="best_unet_model.pth", local_dir="model", cache_dir="model")
|
18 |
+
print(f"Model downloaded to {path}")
|
19 |
|
20 |
model = UNet()
|
21 |
model.load_state_dict(torch.load(MODEL_PATH, map_location=torch.device("cpu"), weights_only=False))
|
22 |
model.eval()
|
|
|
23 |
|
24 |
def age_image(image: Image.Image, source_age: int, target_age: int) -> Image.Image:
|
25 |
# Ensure the image is in RGB or grayscale; if not, convert it.
|
|
|
38 |
gr.Slider(10, 90, value=70, step=1, label="Target age", info="Choose the desired age")
|
39 |
],
|
40 |
outputs=gr.Image(type="pil", label="Aged Image"),
|
41 |
+
examples=[
|
42 |
+
["examples/girl.jpg", 14, 50],
|
43 |
+
["examples/trump.jpg", 74, 30],
|
44 |
+
],
|
45 |
title="Face Aging Demo",
|
46 |
description="Upload an image along with a source age approximation and a target age to generate an aged version of the face."
|
47 |
)
|
examples/girl.jpg
ADDED
![]() |
examples/trump.jpg
ADDED
![]() |