akhaliq HF staff commited on
Commit
f5bf298
1 Parent(s): 64dbbc4

app and reqs

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from modelscope.outputs import OutputKeys
4
+ from modelscope.pipelines import pipeline
5
+ from modelscope.utils.constant import Tasks
6
+ from modelscope.hub.snapshot_download import snapshot_download
7
+
8
+ model_dir = snapshot_download('damo/cv_unet_person-image-cartoon_compound-models', cache_dir='.')
9
+
10
+ img_cartoon = pipeline(
11
+ Tasks.image_portrait_stylization,
12
+ model='damo/cv_unet_person-image-cartoon_compound-models')
13
+
14
+
15
+ def infer(image):
16
+ result = img_cartoon(image.name)
17
+ out = result[OutputKeys.OUTPUT_IMG]
18
+ out = np.clip(out, 0, 255).astype(np.uint8)
19
+ return out[:, :, ::-1]
20
+
21
+
22
+ with gr.Blocks() as demo:
23
+ with gr.Row():
24
+ image = gr.Image(label='Input', type='file')
25
+ run_button = gr.Button('Run')
26
+ result = gr.Image(label='Output')
27
+ run_button.click(fn=infer, inputs=image, outputs=result)
28
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ tensorflow
2
+ "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html