Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import subprocess
|
| 4 |
+
import shutil, os
|
| 5 |
+
from gradio_imageslider import ImageSlider
|
| 6 |
+
import cv2
|
| 7 |
+
from modelscope.outputs import OutputKeys
|
| 8 |
+
from modelscope.pipelines import pipeline
|
| 9 |
+
from modelscope.utils.constant import Tasks
|
| 10 |
+
|
| 11 |
+
img_colorization = pipeline(Tasks.image_colorization, model='damo/cv_ddcolor_image-colorization')
|
| 12 |
+
result = img_colorization('https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/audrey_hepburn.jpg')
|
| 13 |
+
cv2.imwrite('result.png', result[OutputKeys.OUTPUT_IMG])
|
| 14 |
+
def generate(image):
|
| 15 |
+
image_in = cv2.imread(image)
|
| 16 |
+
img_colorization = pipeline(Tasks.image_colorization, model='damo/cv_ddcolor_image-colorization')
|
| 17 |
+
result = img_colorization(image_in)
|
| 18 |
+
cv2.imwrite('result.png', result[OutputKeys.OUTPUT_IMG])
|
| 19 |
+
image_in_pil = Image.fromarray(cv2.cvtColor(image_in, cv2.COLOR_BGR2RGB))
|
| 20 |
+
image_out_pil = Image.fromarray(cv2.cvtColor(image_out, cv2.COLOR_BGR2RGB))
|
| 21 |
+
return (image_in_pil, image_out_pil)
|
| 22 |
+
|
| 23 |
+
with gr.Blocks() as demo:
|
| 24 |
+
with gr.Row():
|
| 25 |
+
with gr.Column():
|
| 26 |
+
image = gr.Image(type='filepath')
|
| 27 |
+
button = gr.Button()
|
| 28 |
+
output_image = ImageSlider(show_label=False, type="filepath", interactive=False)
|
| 29 |
+
button.click(fn=generate, inputs=[image], outputs=[output_image])
|
| 30 |
+
|
| 31 |
+
demo.queue().launch(inline=False, share=True, debug=True)
|