Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -233,6 +233,7 @@ class Model:
|
|
233 |
imgs.append(temp_img)
|
234 |
return imgs
|
235 |
|
|
|
236 |
def gen_video(self, w1, w2, noise, path, frame_num=10):
|
237 |
video = imageio.get_writer(path, mode='I', fps=frame_num // 2, codec='libx264', bitrate='16M')
|
238 |
lin = np.linspace(0, 1, frame_num)
|
@@ -242,6 +243,18 @@ class Model:
|
|
242 |
video.close()
|
243 |
|
244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
def get_thumbnail(img):
|
246 |
img_new = np.full((256, 384, 3), 200, dtype=np.uint8)
|
247 |
img_new[:, 128:256] = transform.resize(img, (256, 128), preserve_range=True)
|
@@ -268,19 +281,6 @@ def encode_img_fn(img, noise):
|
|
268 |
img_out = model.get_img(w, noise)
|
269 |
return "success", imgs[0], img_out, w, get_thumbnail(img_out)
|
270 |
|
271 |
-
|
272 |
-
def gen_video2(self, w1, w2, noise, path, frame_num=10):
|
273 |
-
video = imageio.get_writer(path, mode='I', fps=frame_num // 2, codec='libx264', bitrate='16M')
|
274 |
-
lin = np.linspace(0, 1, frame_num)
|
275 |
-
for i in range(0, frame_num):
|
276 |
-
img = self.get_img(((1 - lin[i]) * w1) + (lin[i] * w2), noise)
|
277 |
-
video.append_data(img)
|
278 |
-
for i in range(frame_num, 0, -1):
|
279 |
-
img = self.get_img(((1 - lin[i]) * w1) + (lin[i] * w2), noise)
|
280 |
-
video.append_data(img)
|
281 |
-
video.close()
|
282 |
-
|
283 |
-
|
284 |
def gen_video_fn(w1, w2, noise, frame):
|
285 |
if w1 is None or w2 is None:
|
286 |
return None
|
@@ -294,7 +294,7 @@ if __name__ == '__main__':
|
|
294 |
|
295 |
app = gr.Blocks()
|
296 |
with app:
|
297 |
-
gr.Markdown("# full-body anime GAN
|
298 |
"![visitor badge](https://visitor-badge.glitch.me/badge?page_id=o_ob.hf.full-body-anime-gan)\ntransformを使った画像生成とブレンドです(text2image, Stable Diffusionではありません)\n動画をA→B→Aというパターンで作ります\n")
|
299 |
with gr.Tabs():
|
300 |
with gr.TabItem("generate image 新規画像生成"):
|
@@ -319,7 +319,7 @@ if __name__ == '__main__':
|
|
319 |
with gr.Column():
|
320 |
gr.Markdown("you'd better upload a standing full-body image")
|
321 |
encode_img_input = gr.Image(label="input image")
|
322 |
-
examples_data = [[f"examples/{x:02d}.jpg"] for x in range(1,
|
323 |
encode_img_examples = gr.Dataset(components=[encode_img_input], samples=examples_data)
|
324 |
with gr.Group():
|
325 |
encode_img_submit = gr.Button("Run", variant="primary")
|
|
|
233 |
imgs.append(temp_img)
|
234 |
return imgs
|
235 |
|
236 |
+
# video A-B style
|
237 |
def gen_video(self, w1, w2, noise, path, frame_num=10):
|
238 |
video = imageio.get_writer(path, mode='I', fps=frame_num // 2, codec='libx264', bitrate='16M')
|
239 |
lin = np.linspace(0, 1, frame_num)
|
|
|
243 |
video.close()
|
244 |
|
245 |
|
246 |
+
# video A-B-A style
|
247 |
+
def gen_video2(self, w1, w2, noise, path, frame_num=10):
|
248 |
+
video = imageio.get_writer(path, mode='I', fps=frame_num // 2, codec='libx264', bitrate='16M')
|
249 |
+
lin = np.linspace(0, 1, frame_num)
|
250 |
+
for i in range(0, frame_num):
|
251 |
+
img = self.get_img(((1 - lin[i]) * w1) + (lin[i] * w2), noise)
|
252 |
+
video.append_data(img)
|
253 |
+
for i in range(frame_num, 0, -1):
|
254 |
+
img = self.get_img(((1 - lin[i]) * w1) + (lin[i] * w2), noise)
|
255 |
+
video.append_data(img)
|
256 |
+
video.close()
|
257 |
+
|
258 |
def get_thumbnail(img):
|
259 |
img_new = np.full((256, 384, 3), 200, dtype=np.uint8)
|
260 |
img_new[:, 128:256] = transform.resize(img, (256, 128), preserve_range=True)
|
|
|
281 |
img_out = model.get_img(w, noise)
|
282 |
return "success", imgs[0], img_out, w, get_thumbnail(img_out)
|
283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
def gen_video_fn(w1, w2, noise, frame):
|
285 |
if w1 is None or w2 is None:
|
286 |
return None
|
|
|
294 |
|
295 |
app = gr.Blocks()
|
296 |
with app:
|
297 |
+
gr.Markdown("# full-body anime GAN\nfork from [skytnt](https://huggingface.co/spaces/skytnt/full-body-anime-gan)\n\n"
|
298 |
"![visitor badge](https://visitor-badge.glitch.me/badge?page_id=o_ob.hf.full-body-anime-gan)\ntransformを使った画像生成とブレンドです(text2image, Stable Diffusionではありません)\n動画をA→B→Aというパターンで作ります\n")
|
299 |
with gr.Tabs():
|
300 |
with gr.TabItem("generate image 新規画像生成"):
|
|
|
319 |
with gr.Column():
|
320 |
gr.Markdown("you'd better upload a standing full-body image")
|
321 |
encode_img_input = gr.Image(label="input image")
|
322 |
+
examples_data = [[f"examples/{x:02d}.jpg"] for x in range(1, 6)]
|
323 |
encode_img_examples = gr.Dataset(components=[encode_img_input], samples=examples_data)
|
324 |
with gr.Group():
|
325 |
encode_img_submit = gr.Button("Run", variant="primary")
|