Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import yolov7
|
3 |
import tempfile
|
4 |
import cv2
|
|
|
5 |
from pathlib import Path
|
6 |
|
7 |
def image_fn(image, model_path, image_size, conf_threshold, iou_threshold):
|
@@ -20,11 +21,19 @@ def image_fn(image, model_path, image_size, conf_threshold, iou_threshold):
|
|
20 |
model.conf = conf_threshold
|
21 |
model.iou = iou_threshold
|
22 |
results = model([image], size=image_size)
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
return img
|
26 |
|
27 |
-
# Use gr
|
28 |
image_interface = gr.Interface(
|
29 |
fn=image_fn,
|
30 |
inputs=[
|
|
|
2 |
import yolov7
|
3 |
import tempfile
|
4 |
import cv2
|
5 |
+
import numpy as np
|
6 |
from pathlib import Path
|
7 |
|
8 |
def image_fn(image, model_path, image_size, conf_threshold, iou_threshold):
|
|
|
21 |
model.conf = conf_threshold
|
22 |
model.iou = iou_threshold
|
23 |
results = model([image], size=image_size)
|
24 |
+
|
25 |
+
# Convert PIL image to NumPy array if necessary
|
26 |
+
if isinstance(results.render()[0], np.ndarray):
|
27 |
+
img = results.render()[0]
|
28 |
+
else:
|
29 |
+
img = np.array(results.render()[0])
|
30 |
+
|
31 |
+
# Ensure the image array is writable
|
32 |
+
img.flags.writeable = True
|
33 |
+
|
34 |
return img
|
35 |
|
36 |
+
# Use gr instead of gr.inputs and gr.outputs
|
37 |
image_interface = gr.Interface(
|
38 |
fn=image_fn,
|
39 |
inputs=[
|