Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoImageProcessor, SapiensForImageSegmentation
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
|
6 |
+
model_name = "facebook/sapiens"
|
7 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
8 |
+
model = SapiensForImageSegmentation.from_pretrained(model_name)
|
9 |
+
|
10 |
+
def segment_image(image):
|
11 |
+
inputs = processor(images=image, return_tensors="pt")
|
12 |
+
outputs = model(**inputs)
|
13 |
+
segmentation = outputs.logits.argmax(dim=1).detach().cpu().numpy()[0]
|
14 |
+
return Image.fromarray(segmentation)
|
15 |
+
|
16 |
+
interface = gr.Interface(
|
17 |
+
fn=segment_image,
|
18 |
+
inputs=gr.Image(type="pil"),
|
19 |
+
outputs=gr.Image(type="pil"),
|
20 |
+
title="Sapiens Body Part Segmentation"
|
21 |
+
)
|
22 |
+
|
23 |
+
interface.launch()
|