File size: 2,700 Bytes
14dc1a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100804b
14dc1a2
fee6f17
f937c5e
14dc1a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df7ebc5
d67e05e
8357abe
d67e05e
 
100804b
d67e05e
14dc1a2
 
 
 
 
 
 
d67e05e
f937c5e
d67e05e
14baf72
 
14dc1a2
d67e05e
14dc1a2
 
 
 
 
 
 
 
 
 
 
d67e05e
 
14dc1a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python

from __future__ import annotations
import argparse
import functools
import os
import pathlib
import sys
from typing import Callable


import gradio as gr
import huggingface_hub
import numpy as np
import PIL.Image

from io import BytesIO
sys.path.insert(0, 'animeganv2')

import test1 as test
from test1 import ImportGraph

ORIGINAL_REPO_URL = 'https://github.com/TachibanaYoshino/AnimeGANv2'
TITLE = 'TachibanaYoshino/AnimeGANv2'
DESCRIPTION = f"""This is a demo for {ORIGINAL_REPO_URL}.

"""
ARTICLE = """

"""


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser()
    parser.add_argument('--device', type=str, default='cpu')
    parser.add_argument('--theme', type=str)
    parser.add_argument('--live', action='store_true')
    parser.add_argument('--share', action='store_true')
    parser.add_argument('--port', type=int)
    parser.add_argument('--disable-queue',
                        dest='enable_queue',
                        action='store_false')
    parser.add_argument('--allow-flagging', type=str, default='never')
    parser.add_argument('--allow-screenshot', action='store_true')
    return parser.parse_args()


def run(
    image,
) -> tuple[PIL.Image.Image]:
    curPath = os.path.abspath(os.path.dirname(__file__))
    out = test.test(checkpoint_dir=os.path.join(curPath,'animeganv2/checkpoint/generator_Shinkai_weight'),
              style_name='Shinkai', test_file=image.name, if_adjust_brightness=True)

    return PIL.Image.open(out)


def main():
    gr.close_all()

    args = parse_args()

    #curPath = os.path.abspath(os.path.dirname(__file__))
    #init
    #shinkai = ImportGraph(checkpoint_dir=os.path.join(curPath,'animeganv2/checkpoint/generator_Shinkai_weight'))
    #hayao = ImportGraph(checkpoint_dir=os.path.join(curPath,'animeganv2/checkpoint/generator_Hayao_weight'))
    #paprika = ImportGraph(checkpoint_dir=os.path.join(curPath,'animeganv2/checkpoint/generator_Paprika_weight'))

    func = functools.partial(run)
    func = functools.update_wrapper(func, run)

    
    gr.Interface(
        func,
        [
            gr.inputs.Image(type='file', label='Input Image'),
        ],
        [
            gr.outputs.Image(
                type='pil',
                label='Result'),

        ],
        #examples=examples,
        theme=args.theme,
        title=TITLE,
        description=DESCRIPTION,
        article=ARTICLE,
        allow_screenshot=args.allow_screenshot,
        allow_flagging=args.allow_flagging,
        live=args.live,
    ).launch(
        enable_queue=args.enable_queue,
        server_port=args.port,
        share=args.share,
    )


if __name__ == '__main__':
    main()