|
from PIL import Image |
|
import torch |
|
import numpy as np |
|
import gradio as gr |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
generator = torch.hub.load( |
|
"AK391/animegan2-pytorch:main", "generator", pretrained=True, progress=False |
|
) |
|
face2paint = torch.hub.load( |
|
"AK391/animegan2-pytorch:main", "face2paint", size=512, side_by_side=False |
|
) |
|
|
|
|
|
def inference(img): |
|
"""AnimeGAN-V2๋ฅผ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง๋ฅผ ์ ๋๋ฉ์ด์
์คํ์ผ๋ก ๋ณํํ๋ ํจ์""" |
|
img_pil = Image.fromarray(img.astype('uint8'), 'RGB') |
|
output_image_pil = face2paint(generator, img_pil) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return np.array(output_image_pil) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gr.Interface( |
|
fn=inference, |
|
inputs=gr.Image(type="numpy"), |
|
outputs=gr.Image(type="numpy"), |
|
title="AnimeGAN-V2 Image Transformation", |
|
description="Upload an image to transform it into an anime-style image using AnimeGAN-V2.", |
|
live=True |
|
).launch() |