druvx13 commited on
Commit
2074a2d
·
verified ·
1 Parent(s): 8d50cb2

Create app-sample.txt

Browse files
Files changed (1) hide show
  1. app-sample.txt +34 -0
app-sample.txt ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import cv2
3
+ import tempfile
4
+ from modelscope.outputs import OutputKeys
5
+ from modelscope.pipelines import pipeline
6
+ from modelscope.utils.constant import Tasks
7
+ import PIL
8
+ from pathlib import Path
9
+ import gradio as gr
10
+ import numpy as np
11
+
12
+ """Load the model into memory to make running multiple predictions efficient"""
13
+ img_colorization = pipeline(Tasks.image_colorization, model='iic/cv_ddcolor_image-colorization')
14
+
15
+
16
+ def inference(img):
17
+ image = cv2.imread(str(img))
18
+
19
+ output = img_colorization(image[..., ::-1])
20
+ result = output[OutputKeys.OUTPUT_IMG].astype(np.uint8)
21
+
22
+ temp_dir = tempfile.mkdtemp()
23
+ out_path = os.path.join(temp_dir, 'old-to-color.png')
24
+ cv2.imwrite(out_path, result)
25
+ return Path(out_path)
26
+
27
+
28
+ title = "Color Restorization Model"
29
+ gr.Interface(
30
+ inference,
31
+ [gr.inputs.Image(type="filepath", label="Input")],
32
+ gr.outputs.Image(type="pil", label="Output"),
33
+ title=title
34
+ ).launch(enable_queue=True)