Spaces:
Runtime error
Runtime error
File size: 950 Bytes
2074a2d |
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 |
import os import cv2 import tempfile from modelscope.outputs import OutputKeys from modelscope.pipelines import pipeline from modelscope.utils.constant import Tasks import PIL from pathlib import Path import gradio as gr import numpy as np """Load the model into memory to make running multiple predictions efficient""" img_colorization = pipeline(Tasks.image_colorization, model='iic/cv_ddcolor_image-colorization') def inference(img): image = cv2.imread(str(img)) output = img_colorization(image[..., ::-1]) result = output[OutputKeys.OUTPUT_IMG].astype(np.uint8) temp_dir = tempfile.mkdtemp() out_path = os.path.join(temp_dir, 'old-to-color.png') cv2.imwrite(out_path, result) return Path(out_path) title = "Color Restorization Model" gr.Interface( inference, [gr.inputs.Image(type="filepath", label="Input")], gr.outputs.Image(type="pil", label="Output"), title=title ).launch(enable_queue=True) |