Spaces:
Runtime error
Runtime error
#!/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 | |
import cv2 | |
from io import BytesIO | |
sys.path.insert(0, 'p2c') | |
from test_onnx import Photo2Cartoon | |
ORIGINAL_REPO_URL = 'https://github.com/minivision-ai/photo2cartoon' | |
TITLE = 'minivision-ai/photo2cartoon' | |
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, | |
p2c : Photo2Cartoon, | |
) -> tuple[PIL.Image.Image]: | |
cartoon = p2c.inference(image.name) | |
return PIL.Image.fromarray(cartoon) | |
def main(): | |
gr.close_all() | |
args = parse_args() | |
p2c = Photo2Cartoon() | |
func = functools.partial(run, p2c) | |
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() | |