anime-gan / app.py
hwang1's picture
Update app.py
b4cc2e9 verified
from PIL import Image
import torch
import numpy as np
import gradio as gr
# AnimeGAN-V2 ๋ชจ๋ธ ๋กœ๋“œ
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') # NumPy ๋ฐฐ์—ด์„ PIL ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜
output_image_pil = face2paint(generator, img_pil) # AnimeGAN-V2 ๋ณ€ํ™˜ ์ˆ˜ํ–‰
return np.array(output_image_pil) # ๋ณ€ํ™˜๋œ ์ด๋ฏธ์ง€๋ฅผ NumPy ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜
# Gradio UI ์ƒ์„ฑ
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()