Podtekatel's picture
Fix errors in README
b74f8d7
raw
history blame
1.99 kB
import logging
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
logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(message)s',
level=logging.INFO,
datefmt='%Y-%m-%d %H:%M:%S')
MODEL_IMG_SIZE = 256
def load_model():
REPO_ID = "Podtekatel/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 style transfer. To use it, simply upload your image, or click one of the examples to load them."
article = "This is one of my successful experiments on style transfer. I've built my own pipeline, generator model and private dataset to train this model<br>" \
"" \
"" \
"" \
"This model was trained on RTX 2080 Ti 1.5 days with batch size 7" \
"If you want to use this app or integrate this model into yours, please contact me at email '[email protected]'"
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()