Spaces:
Running
Running
si.qian
commited on
Commit
·
ba42db4
1
Parent(s):
cdf6850
add model
Browse files
app.py
CHANGED
|
@@ -31,7 +31,15 @@ def run_rembg(img):
|
|
| 31 |
|
| 32 |
return cropped_image
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
|
|
|
|
|
|
| 35 |
def from_zip(inputs):
|
| 36 |
work_dir = get_random_name()
|
| 37 |
os.makedirs(work_dir, exist_ok=True)
|
|
@@ -240,7 +248,42 @@ if __name__=="__main__":
|
|
| 240 |
outputs=image_output,
|
| 241 |
api_name="imageMatting"
|
| 242 |
)
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
|
| 246 |
|
|
|
|
| 31 |
|
| 32 |
return cropped_image
|
| 33 |
|
| 34 |
+
def run_rembg_withmodel(img,model):
|
| 35 |
+
output = remove(img)
|
| 36 |
+
output_pil = Image.fromarray(output)
|
| 37 |
+
|
| 38 |
+
# Remove margins
|
| 39 |
+
cropped_image = output_pil.crop(output_pil.getbbox())
|
| 40 |
|
| 41 |
+
return cropped_image
|
| 42 |
+
|
| 43 |
def from_zip(inputs):
|
| 44 |
work_dir = get_random_name()
|
| 45 |
os.makedirs(work_dir, exist_ok=True)
|
|
|
|
| 248 |
outputs=image_output,
|
| 249 |
api_name="imageMatting"
|
| 250 |
)
|
| 251 |
+
|
| 252 |
+
with gr.Tab("ImageWithModel"):
|
| 253 |
+
gr.Markdown(
|
| 254 |
+
"""
|
| 255 |
+
<center><h1>Image Matting using different models</h1></center>
|
| 256 |
+
"""
|
| 257 |
+
)
|
| 258 |
+
with gr.Row():
|
| 259 |
+
gr.Markdown(
|
| 260 |
+
"""
|
| 261 |
+
### Input Image
|
| 262 |
+
<img src='file/assets/cat-3038243_1280.jpg' width="50%" height="50%">
|
| 263 |
+
"""
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
gr.Markdown(
|
| 267 |
+
"""
|
| 268 |
+
### Output Image
|
| 269 |
+
<img src='file/assets/objects/cat-3038243_1280.png' width="20%" height="20%">
|
| 270 |
+
"""
|
| 271 |
+
)
|
| 272 |
+
with gr.Row():
|
| 273 |
+
with gr.Column():
|
| 274 |
+
model_name = gr.Textbox(label="Model Name", value="", placeholder="u2net")
|
| 275 |
+
image_input = gr.Image(type="numpy")
|
| 276 |
+
image_output = gr.Image(type="pil")
|
| 277 |
+
|
| 278 |
+
btn = gr.Button("Run!")
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
btn.click(
|
| 282 |
+
fn=run_rembg_withmodel,
|
| 283 |
+
inputs=[image_input, model_name]
|
| 284 |
+
outputs=image_output,
|
| 285 |
+
api_name="imageMattingWithModel"
|
| 286 |
+
)
|
| 287 |
|
| 288 |
|
| 289 |
|