Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from torchvision import transforms
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from animegan2_pytorch import AnimeGAN2
|
| 6 |
+
|
| 7 |
+
# Load AnimeGAN model
|
| 8 |
+
model = AnimeGAN2('face_paint_512_v2')
|
| 9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
+
model = model.to(device)
|
| 11 |
+
|
| 12 |
+
# Function to process images
|
| 13 |
+
def convert_to_anime(image):
|
| 14 |
+
image = Image.fromarray(image)
|
| 15 |
+
image = transforms.ToTensor()(image).unsqueeze(0).to(device)
|
| 16 |
+
with torch.no_grad():
|
| 17 |
+
output = model(image)[0].cpu()
|
| 18 |
+
output = transforms.ToPILImage()(output)
|
| 19 |
+
return output
|
| 20 |
+
|
| 21 |
+
# Gradio UI
|
| 22 |
+
iface = gr.Interface(
|
| 23 |
+
fn=convert_to_anime,
|
| 24 |
+
inputs=gr.Image(type="numpy"),
|
| 25 |
+
outputs=gr.Image(type="pil"),
|
| 26 |
+
title="AnimeGAN Image Converter",
|
| 27 |
+
description="Upload an image to convert it into anime style!",
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
iface.launch()
|