Haiyu Wu
commited on
Commit
·
d1455ac
1
Parent(s):
96c5656
update
Browse files
app.py
CHANGED
@@ -17,6 +17,12 @@ from time import time
|
|
17 |
MAX_SEED = np.iinfo(np.int32).max
|
18 |
device = "cuda"
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def clear_image():
|
21 |
return None
|
22 |
|
@@ -86,13 +92,10 @@ def image_generation(input_image, quality, random_perturbation, sigma, dimension
|
|
86 |
generator, id_model, pose_model, quality_model = initialize_models()
|
87 |
|
88 |
generated_images = []
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
input_image = torch.from_numpy(input_image).unsqueeze(0).float().to(device)
|
94 |
-
input_image.div_(255).sub_(0.5).div_(0.5)
|
95 |
-
feature = id_model(input_image).clone().detach().cpu().numpy()
|
96 |
|
97 |
if not random_perturbation:
|
98 |
features = []
|
@@ -175,7 +178,7 @@ def main():
|
|
175 |
|
176 |
gr.Markdown(title)
|
177 |
gr.Markdown(description)
|
178 |
-
with gr.Row():
|
179 |
with gr.Column():
|
180 |
image_file = gr.Image(label="Upload an image (optional)", type="filepath")
|
181 |
|
@@ -243,7 +246,7 @@ def main():
|
|
243 |
fn=clear_image,
|
244 |
inputs=[],
|
245 |
outputs=[gallery]
|
246 |
-
).then(
|
247 |
fn=generating,
|
248 |
inputs=[],
|
249 |
outputs=[generation_time]
|
|
|
17 |
MAX_SEED = np.iinfo(np.int32).max
|
18 |
device = "cuda"
|
19 |
|
20 |
+
|
21 |
+
def check_input_image(input_image):
|
22 |
+
if input_image is None:
|
23 |
+
raise gr.Error("No image uploaded!")
|
24 |
+
|
25 |
+
|
26 |
def clear_image():
|
27 |
return None
|
28 |
|
|
|
92 |
generator, id_model, pose_model, quality_model = initialize_models()
|
93 |
|
94 |
generated_images = []
|
95 |
+
input_image = np.transpose(input_image, (2, 0, 1))
|
96 |
+
input_image = torch.from_numpy(input_image).unsqueeze(0).float().to(device)
|
97 |
+
input_image.div_(255).sub_(0.5).div_(0.5)
|
98 |
+
feature = id_model(input_image).clone().detach().cpu().numpy()
|
|
|
|
|
|
|
99 |
|
100 |
if not random_perturbation:
|
101 |
features = []
|
|
|
178 |
|
179 |
gr.Markdown(title)
|
180 |
gr.Markdown(description)
|
181 |
+
with gr.Row(variant="panel"):
|
182 |
with gr.Column():
|
183 |
image_file = gr.Image(label="Upload an image (optional)", type="filepath")
|
184 |
|
|
|
246 |
fn=clear_image,
|
247 |
inputs=[],
|
248 |
outputs=[gallery]
|
249 |
+
).then(fn=check_input_image, inputs=[image_file]).success(
|
250 |
fn=generating,
|
251 |
inputs=[],
|
252 |
outputs=[generation_time]
|