Spaces:
Runtime error
Runtime error
Commit
•
ed2f488
1
Parent(s):
4551514
Added gradio app code
Browse files- app.py +39 -0
- examples/d_r_84_.jpg +0 -0
- examples/f_r_1920_.jpg +0 -0
- examples/n_l_87_.jpg +0 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
|
6 |
+
def predict(image):
|
7 |
+
result = pipe(image)
|
8 |
+
return image, [
|
9 |
+
(
|
10 |
+
np.array(subsection["mask"]) / 255,
|
11 |
+
subsection["label"],
|
12 |
+
)
|
13 |
+
for subsection in result
|
14 |
+
]
|
15 |
+
|
16 |
+
|
17 |
+
pipe = pipeline(
|
18 |
+
"image-segmentation",
|
19 |
+
model="SatwikKambham/segformer-b0-finetuned-suim",
|
20 |
+
)
|
21 |
+
demo = gr.Interface(
|
22 |
+
fn=predict,
|
23 |
+
inputs=gr.Image(type="pil"),
|
24 |
+
outputs=gr.AnnotatedImage(
|
25 |
+
color_map={
|
26 |
+
"Background (waterbody)": "#000000",
|
27 |
+
"Human divers": "#0000FF",
|
28 |
+
"Aquatic plants and sea-grass": "#00FF00",
|
29 |
+
"Wrecks and ruins": "#FF0000",
|
30 |
+
"Robots (AUVs/ROVs/instruments)": "#FFFF00",
|
31 |
+
"Reefs and invertebrates": "#00FFFF",
|
32 |
+
"Fish and vertebrates": "#FF00FF",
|
33 |
+
"Sea-floor and rocks": "#FFFFFF",
|
34 |
+
}
|
35 |
+
),
|
36 |
+
examples="examples",
|
37 |
+
)
|
38 |
+
|
39 |
+
demo.launch()
|
examples/d_r_84_.jpg
ADDED
![]() |
examples/f_r_1920_.jpg
ADDED
![]() |
examples/n_l_87_.jpg
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
numpy
|