Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,16 +7,17 @@ from matplotlib import cm
|
|
| 7 |
import torch
|
| 8 |
from PIL import Image
|
| 9 |
import requests
|
|
|
|
| 10 |
import gradio as gr
|
| 11 |
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def replace(text):
|
| 14 |
-
processor = AutoImageProcessor.from_pretrained("facebook/mask2former-swin-base-coco-panoptic")
|
| 15 |
-
model = Mask2FormerForUniversalSegmentation.from_pretrained("facebook/mask2former-swin-base-coco-panoptic")
|
| 16 |
# image = Image.open(text).convert("RGB")
|
| 17 |
inputs = processor(text, return_tensors="pt")
|
| 18 |
outputs = model(**inputs)
|
| 19 |
-
prediction = processor.post_process_panoptic_segmentation(outputs, target_sizes=[
|
| 20 |
|
| 21 |
return draw_panoptic_segmentation(**prediction)
|
| 22 |
def draw_panoptic_segmentation(segmentation, segments_info):
|
|
@@ -56,4 +57,4 @@ interface = gr.Interface(
|
|
| 56 |
)
|
| 57 |
|
| 58 |
# Launch the Gradio app
|
| 59 |
-
interface.launch(debug=True)
|
|
|
|
| 7 |
import torch
|
| 8 |
from PIL import Image
|
| 9 |
import requests
|
| 10 |
+
from io import BytesIO
|
| 11 |
import gradio as gr
|
| 12 |
|
| 13 |
+
processor = AutoImageProcessor.from_pretrained("facebook/mask2former-swin-base-coco-panoptic")
|
| 14 |
+
model = Mask2FormerForUniversalSegmentation.from_pretrained("facebook/mask2former-swin-base-coco-panoptic")
|
| 15 |
|
| 16 |
def replace(text):
|
|
|
|
|
|
|
| 17 |
# image = Image.open(text).convert("RGB")
|
| 18 |
inputs = processor(text, return_tensors="pt")
|
| 19 |
outputs = model(**inputs)
|
| 20 |
+
prediction = processor.post_process_panoptic_segmentation(outputs, target_sizes=[text.size[::-1]])[0]
|
| 21 |
|
| 22 |
return draw_panoptic_segmentation(**prediction)
|
| 23 |
def draw_panoptic_segmentation(segmentation, segments_info):
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
# Launch the Gradio app
|
| 60 |
+
interface.launch(debug=True)
|