File size: 1,568 Bytes
979b420
0a313a4
22386d7
0a313a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39b8f80
0a313a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39b8f80
0a313a4
39b8f80
 
0a313a4
 
 
4fccc9d
0a313a4
22386d7
d58dd74
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
# coding: utf-8
import os
#os.system("pip install gradio==2.8.0b3")
import torch
import gradio as gr
from PIL import ImageFont, ImageDraw

device = "cuda" if torch.cuda.is_available() else "cpu"
model1 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", device=device, pretrained="face_paint_512_v1")
model2 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", device=device, pretrained="face_paint_512_v2")
face2paint = torch.hub.load("bryandlee/animegan2-pytorch:main", "face2paint", device=device)


def inference(img, ver):
    title_font = ImageFont.truetype("LEMONMILK-Regular.otf", 20)
    title_text = "@_temp.late_"
    padding = 10
    x, y = 15, 15  # 180, 412
    w, h = title_font.getsize(title_text)
    if ver == "Version 2 (Réaliste)":
        out = face2paint(model2, img)
    else:
        out = face2paint(model1, img)
    image_editable = ImageDraw.Draw(out)
    image_editable.rectangle((x, y, x + w + padding, y + h + padding), fill="white")
    image_editable.text((x + padding / 2, y + padding / 2), title_text, (0, 0, 0), font=title_font)
    return out


title = "Temp Late"
gr.Interface(
    inference,
    [
        gr.inputs.Image(type="pil", source="upload"),
        gr.inputs.Radio(
            ["Version 1 (Stylisé)", "Version 2 (Réaliste)"],
            type="value",
            default="Version 2 (Réaliste)",
            label="Version",
        ),
    ],
    gr.outputs.Image(type="pil"),
    allow_flagging="auto",
    allow_screenshot=False,
    flagging_dir="flagged",
).launch(enable_queue=True)