Haiyu Wu
commited on
Commit
·
90ad1e9
1
Parent(s):
e1eebbb
change discription
Browse files
app.py
CHANGED
@@ -8,12 +8,13 @@ from huggingface_hub import hf_hub_download
|
|
8 |
from models import iresnet
|
9 |
from sixdrepnet.model import SixDRepNet
|
10 |
import pixel_generator.vec2face.model_vec2face as model_vec2face
|
11 |
-
MAX_SEED = np.iinfo(np.int32).max
|
12 |
import torch
|
13 |
-
import
|
|
|
14 |
from time import time
|
15 |
|
16 |
|
|
|
17 |
device = "cuda"
|
18 |
|
19 |
def clear_image():
|
@@ -80,13 +81,13 @@ def initialize_models():
|
|
80 |
|
81 |
return generator, id_model, pose_model, quality_model
|
82 |
|
83 |
-
@spaces.GPU
|
84 |
def image_generation(input_image, quality, random_perturbation, sigma, dimension, progress=gr.Progress()):
|
85 |
generator, id_model, pose_model, quality_model = initialize_models()
|
86 |
|
87 |
generated_images = []
|
88 |
if input_image is None:
|
89 |
-
|
90 |
else:
|
91 |
input_image = np.transpose(input_image, (2, 0, 1))
|
92 |
input_image = torch.from_numpy(input_image).unsqueeze(0).float().to(device)
|
@@ -120,7 +121,7 @@ def image_generation(input_image, quality, random_perturbation, sigma, dimension
|
|
120 |
|
121 |
return generated_images
|
122 |
|
123 |
-
@spaces.GPU
|
124 |
def process_input(image_input, num1, num2, num3, num4, random_seed, target_quality, random_perturbation, sigma, progress=gr.Progress()):
|
125 |
# Ensure all dimension numbers are within [0, 512)
|
126 |
num1, num2, num3, num4 = [max(0, min(int(n), 511)) for n in [num1, num2, num3, num4]]
|
@@ -168,7 +169,7 @@ def main():
|
|
168 |
How to use:<br>
|
169 |
1. Upload an image with a cropped face image or directly click <b>Submit</b> button, three images will be shown on the right.
|
170 |
2. You can control the image quality, image pose, and modify the values in the target dimensions to change the output images.
|
171 |
-
3. The output results will shown three results of dimension modification or
|
172 |
4. Enjoy! 😊
|
173 |
"""
|
174 |
|
@@ -200,14 +201,25 @@ def main():
|
|
200 |
random_perturbation = gr.Checkbox(label="Random Perturbation")
|
201 |
sigma = gr.Slider(label="Sigma value", value=0, minimum=0, maximum=1, step=0.1, visible=False)
|
202 |
|
203 |
-
submit = gr.Button("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
|
205 |
gr.Markdown("""
|
206 |
## Usage tips of Vec2Face
|
207 |
- Directly clicking "Submit" button will give you results from a randomly sampled vector.
|
208 |
- If you want to modify more dimensions or change attributes, Code snippets in [Vec2Face repo](https://github.com/HaiyuWu/vec2face) might be helpful.
|
209 |
-
- For better experience, we suggest you to run code on a GPU machine.
|
210 |
""")
|
|
|
211 |
|
212 |
with gr.Column():
|
213 |
gallery = gr.Image(label="Generated Image")
|
@@ -282,7 +294,7 @@ def main():
|
|
282 |
"""
|
283 |
gr.Markdown(article)
|
284 |
|
285 |
-
demo.launch()
|
286 |
|
287 |
|
288 |
if __name__ == "__main__":
|
|
|
8 |
from models import iresnet
|
9 |
from sixdrepnet.model import SixDRepNet
|
10 |
import pixel_generator.vec2face.model_vec2face as model_vec2face
|
|
|
11 |
import torch
|
12 |
+
import os
|
13 |
+
# import spaces
|
14 |
from time import time
|
15 |
|
16 |
|
17 |
+
MAX_SEED = np.iinfo(np.int32).max
|
18 |
device = "cuda"
|
19 |
|
20 |
def clear_image():
|
|
|
81 |
|
82 |
return generator, id_model, pose_model, quality_model
|
83 |
|
84 |
+
# @spaces.GPU
|
85 |
def image_generation(input_image, quality, random_perturbation, sigma, dimension, progress=gr.Progress()):
|
86 |
generator, id_model, pose_model, quality_model = initialize_models()
|
87 |
|
88 |
generated_images = []
|
89 |
if input_image is None:
|
90 |
+
raise gr.Error("No image uploaded!")
|
91 |
else:
|
92 |
input_image = np.transpose(input_image, (2, 0, 1))
|
93 |
input_image = torch.from_numpy(input_image).unsqueeze(0).float().to(device)
|
|
|
121 |
|
122 |
return generated_images
|
123 |
|
124 |
+
# @spaces.GPU
|
125 |
def process_input(image_input, num1, num2, num3, num4, random_seed, target_quality, random_perturbation, sigma, progress=gr.Progress()):
|
126 |
# Ensure all dimension numbers are within [0, 512)
|
127 |
num1, num2, num3, num4 = [max(0, min(int(n), 511)) for n in [num1, num2, num3, num4]]
|
|
|
169 |
How to use:<br>
|
170 |
1. Upload an image with a cropped face image or directly click <b>Submit</b> button, three images will be shown on the right.
|
171 |
2. You can control the image quality, image pose, and modify the values in the target dimensions to change the output images.
|
172 |
+
3. The output results will shown three results of dimension modification or vector perturbation.
|
173 |
4. Enjoy! 😊
|
174 |
"""
|
175 |
|
|
|
201 |
random_perturbation = gr.Checkbox(label="Random Perturbation")
|
202 |
sigma = gr.Slider(label="Sigma value", value=0, minimum=0, maximum=1, step=0.1, visible=False)
|
203 |
|
204 |
+
submit = gr.Button("Generate", variant="primary")
|
205 |
+
|
206 |
+
with gr.Row(variant="panel"):
|
207 |
+
gr.Examples(
|
208 |
+
examples=[
|
209 |
+
os.path.join("examples", img_name) for img_name in sorted(os.listdir("examples"))
|
210 |
+
],
|
211 |
+
inputs=[image_file],
|
212 |
+
label="Examples",
|
213 |
+
cache_examples=False,
|
214 |
+
examples_per_page=8
|
215 |
+
)
|
216 |
|
217 |
gr.Markdown("""
|
218 |
## Usage tips of Vec2Face
|
219 |
- Directly clicking "Submit" button will give you results from a randomly sampled vector.
|
220 |
- If you want to modify more dimensions or change attributes, Code snippets in [Vec2Face repo](https://github.com/HaiyuWu/vec2face) might be helpful.
|
|
|
221 |
""")
|
222 |
+
# - For better experience, we suggest you to run code on a GPU machine.
|
223 |
|
224 |
with gr.Column():
|
225 |
gallery = gr.Image(label="Generated Image")
|
|
|
294 |
"""
|
295 |
gr.Markdown(article)
|
296 |
|
297 |
+
demo.launch(share=True)
|
298 |
|
299 |
|
300 |
if __name__ == "__main__":
|