Spaces:
Runtime error
Runtime error
Commit
·
a97698b
1
Parent(s):
d1f4717
initial commit
Browse files- app.py +44 -0
- requirements.txt +7 -0
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
import argparse
|
4 |
+
import git
|
5 |
+
|
6 |
+
git.Repo.clone_from("https://github.com/timroelofs123/face_reaging.git", "./face_reaging")
|
7 |
+
git.Repo.clone_from("https://huggingface.co/timroelofs123/face_re-aging", "./hf")
|
8 |
+
|
9 |
+
import sys
|
10 |
+
sys.path.append("./face_reaging")
|
11 |
+
|
12 |
+
from model.models import UNet
|
13 |
+
from scripts.test_functions import process_image
|
14 |
+
|
15 |
+
|
16 |
+
model_path = "hf/best_unet_model.pth"
|
17 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
18 |
+
unet_model = UNet().to(device)
|
19 |
+
unet_model.load_state_dict(torch.load(model_path))
|
20 |
+
unet_model.eval()
|
21 |
+
|
22 |
+
def block(image, source_age, target_age):
|
23 |
+
return process_image(unet_model, image, video=False, source_age=source_age,
|
24 |
+
target_age=target_age, window_size=512, stride=256)
|
25 |
+
|
26 |
+
demo = gr.Interface(
|
27 |
+
fn=block,
|
28 |
+
inputs=[
|
29 |
+
gr.Image(type="pil"),
|
30 |
+
gr.Slider(10, 90, value=20, step=1, label="Current age", info="Choose your current age"),
|
31 |
+
gr.Slider(10, 90, value=80, step=1, label="Target age", info="Choose the age you want to become")
|
32 |
+
],
|
33 |
+
outputs="image",
|
34 |
+
examples=[
|
35 |
+
['assets/gradio_example_images/1.png', 20, 80],
|
36 |
+
['assets/gradio_example_images/2.png', 75, 40],
|
37 |
+
['assets/gradio_example_images/3.png', 30, 70],
|
38 |
+
['assets/gradio_example_images/4.png', 22, 60],
|
39 |
+
['assets/gradio_example_images/5.png', 28, 75],
|
40 |
+
['assets/gradio_example_images/6.png', 35, 15]
|
41 |
+
],
|
42 |
+
)
|
43 |
+
|
44 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
torchvision
|
3 |
+
antialiased_cnns
|
4 |
+
numpy
|
5 |
+
face_recognition
|
6 |
+
tempfile
|
7 |
+
gitpython
|