File size: 1,783 Bytes
d44e389
 
dab5d0e
d44e389
 
dab5d0e
 
d44e389
 
 
 
 
dab5d0e
 
 
 
 
d44e389
dab5d0e
d44e389
 
dab5d0e
d44e389
dab5d0e
d44e389
dab5d0e
 
d44e389
dab5d0e
d44e389
 
 
 
 
dab5d0e
 
 
 
d44e389
 
 
 
 
 
 
 
 
dab5d0e
 
 
 
 
 
 
 
 
 
 
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
import os

import gradio as gr
import numpy as np
from PIL import Image
from huggingface_hub import hf_hub_url, cached_download

from inference.face_detector import StatRetinaFaceDetector
from inference.model_pipeline import VSNetModelPipeline
from inference.onnx_model import ONNXModel

MODEL_IMG_SIZE = 256
def load_model():
    REPO_ID = "MalchuL/JJBAGAN"
    FILENAME = "198_jjba_8_k_2_099_ep.onnx"

    global model
    global pipeline

    model_path = cached_download(
        hf_hub_url(REPO_ID, FILENAME), use_auth_token=os.getenv('HF_TOKEN')
    )
    model = ONNXModel(model_path)

    pipeline = VSNetModelPipeline(model, StatRetinaFaceDetector(MODEL_IMG_SIZE), background_resize=1024, no_detected_resize=1024)
    return model

load_model()

def inference(img):
    img = np.array(img)
    out_img = pipeline(img)
    out_img = Image.fromarray(out_img)
    return out_img


title = "JJStyleTransfer"
description = "Gradio Demo for JoJo Bizzare Adventures 5 season style transfer. To use it, simply upload your image, or click one of the examples to load them."
article = "There is one of my successful experiments on style transfer. I used my own pipeline, generator model and private dataset to train this model<br>" \
          "" \
          "" \
          "" \
          "" \
          "If you want use this app or integrate this model into your app please contact with me at email 'neuromancer.ai.lover@gmail.com'"

imgs_folder = 'demo'
examples = [[os.path.join(imgs_folder, img_filename)] for img_filename in os.listdir(imgs_folder)]

demo = gr.Interface(
    fn=inference,
    inputs=[gr.inputs.Image(type="pil")],
    outputs=gr.outputs.Image(type="pil"),
    title=title,
    description=description,
    article=article,
    examples=examples)

demo.launch()