Spaces:
Running
on
Zero
Running
on
Zero
Martin Tomov
commited on
testing outputs
Browse files
app.py
CHANGED
@@ -13,6 +13,8 @@ import matplotlib.pyplot as plt
|
|
13 |
from transformers import AutoModelForMaskGeneration, AutoProcessor, pipeline
|
14 |
import gradio as gr
|
15 |
import spaces
|
|
|
|
|
16 |
|
17 |
@dataclass
|
18 |
class BoundingBox:
|
@@ -178,15 +180,13 @@ def draw_classification_boxes(image_with_insects, detections):
|
|
178 |
f"{label}: {score:.2f}",
|
179 |
(box.xmin, box.ymin - baseline),
|
180 |
cv2.FONT_HERSHEY_SIMPLEX,
|
181 |
-
|
182 |
(255, 255, 255),
|
183 |
2
|
184 |
)
|
185 |
return image_with_insects
|
186 |
|
187 |
def plot_detections_plotly(image: np.ndarray, detections: List[DetectionResult]) -> str:
|
188 |
-
from plotly import graph_objects as go
|
189 |
-
import plotly.express as px
|
190 |
fig = px.imshow(image)
|
191 |
class_colors = {i: f'rgb({random.randint(0, 255)}, {random.randint(0, 255)}, {random.randint(0, 255)})' for i in range(len(detections))}
|
192 |
for idx, detection in enumerate(detections):
|
@@ -225,7 +225,9 @@ def process_image(image):
|
|
225 |
yellow_background_with_insects = create_yellow_background_with_insects(np.array(original_image), detections)
|
226 |
yellow_background_with_boxes = draw_classification_boxes(yellow_background_with_insects.copy(), detections)
|
227 |
plotly_image_path = plot_detections_plotly(original_image, detections)
|
228 |
-
|
|
|
|
|
229 |
|
230 |
gr.Interface(
|
231 |
fn=process_image,
|
|
|
13 |
from transformers import AutoModelForMaskGeneration, AutoProcessor, pipeline
|
14 |
import gradio as gr
|
15 |
import spaces
|
16 |
+
from plotly import graph_objects as go
|
17 |
+
import plotly.express as px
|
18 |
|
19 |
@dataclass
|
20 |
class BoundingBox:
|
|
|
180 |
f"{label}: {score:.2f}",
|
181 |
(box.xmin, box.ymin - baseline),
|
182 |
cv2.FONT_HERSHEY_SIMPLEX,
|
183 |
+
0.5,
|
184 |
(255, 255, 255),
|
185 |
2
|
186 |
)
|
187 |
return image_with_insects
|
188 |
|
189 |
def plot_detections_plotly(image: np.ndarray, detections: List[DetectionResult]) -> str:
|
|
|
|
|
190 |
fig = px.imshow(image)
|
191 |
class_colors = {i: f'rgb({random.randint(0, 255)}, {random.randint(0, 255)}, {random.randint(0, 255)})' for i in range(len(detections))}
|
192 |
for idx, detection in enumerate(detections):
|
|
|
225 |
yellow_background_with_insects = create_yellow_background_with_insects(np.array(original_image), detections)
|
226 |
yellow_background_with_boxes = draw_classification_boxes(yellow_background_with_insects.copy(), detections)
|
227 |
plotly_image_path = plot_detections_plotly(original_image, detections)
|
228 |
+
with open(plotly_image_path, 'r') as file:
|
229 |
+
plotly_html = file.read()
|
230 |
+
return annotated_image, yellow_background_with_boxes, plotly_html
|
231 |
|
232 |
gr.Interface(
|
233 |
fn=process_image,
|