File size: 2,000 Bytes
8790417
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import shutil
import torch
import cv2
import gradio as gr
from PIL import Image

# Download sample images
os.makedirs("sample_images", exist_ok=True)
os.chdir("sample_images")
os.system("gdown 1LiKfKhksfu8f_A4x-BhOjZgZHADdLdWz -O img1.jpg")
os.system("gdown 1jJ6uP_bpdnCRqCuiqZjJG8yeexsz6IUp -O img2.jpg")
os.system("gdown 1usp9c4VcTX2yche5o2WCi7yJw85n_yeZ -O img3.jpg")

os.chdir("../")


examples = [['sample_images/img1.jpg', "Cartoonify"],
            ['sample_images/img2.jpg', "Cartoonify"],
            ['sample_images/img3.jpg', "Cartoonify"],
            ]

inference_on = ['Full Resolution Image', 'Downsampled Image']

title = "Face Cartoonify for Video Call Privacy"
description = """
Gradio demo for <b>Face Cartoonify for Video Call Privacy</b>.\n 
"""

article = "<p style='text-align: center'><a href='#'> Face Cartoonify for Video Call Privacy </a> | <a href='#'>Github Repo</a></p>"

model = torch.hub.load(
    "AK391/animegan2-pytorch:main",
    "generator",
    pretrained=True,
    device="cpu",
    progress=False
)

face2paint = torch.hub.load(
    'AK391/animegan2-pytorch:main', 'face2paint', 
    size=512, device="cpu",side_by_side=False
)

def inference(img, method):
    if not os.path.exists('temp'):
      os.system('mkdir temp')
    
    img.save("temp/image.jpg", "JPEG")

    if method == "Cartoonify AnimeGanV2":
      out = face2paint(model, img)
      return out
    else:
      os.system("python cartoon.py --input_path 'temp/image.jpg'  --result_dir './temp/'")
      return 'temp/image.jpg'
    
gr.Interface(
    inference,
    [
        gr.inputs.Image(type="pil", label="Input"),
        gr.inputs.Radio(["Cartoonify OpenCV", "Cartoonify AnimeGanV2"], default="Cartoonify AnimeGanV2", label='Method'),

    ],
    gr.outputs.Image(type="file", label="Output"),
    title=title,
    description=description,
    article=article,
    theme ="huggingface",
    examples=examples,
    allow_flagging=False,
    ).launch(debug=True,enable_queue=True)