Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -92,13 +92,10 @@ def process_frame(frame, selected_model):
|
|
| 92 |
|
| 93 |
plt.close(fig)
|
| 94 |
|
| 95 |
-
|
| 96 |
-
frame_bgr = cv2.cvtColor(frame_rgb, cv2.COLOR_RGB2BGR)
|
| 97 |
-
|
| 98 |
-
return frame_rgb, frame_bgr, plot_img
|
| 99 |
except Exception as e:
|
| 100 |
print(f"An error occurred: {str(e)}")
|
| 101 |
-
return frame, frame, None
|
| 102 |
|
| 103 |
def process_video(input_video, selected_model, frame_index):
|
| 104 |
try:
|
|
@@ -112,7 +109,7 @@ def process_video(input_video, selected_model, frame_index):
|
|
| 112 |
if not ret:
|
| 113 |
return None, None
|
| 114 |
|
| 115 |
-
|
| 116 |
cap.release()
|
| 117 |
|
| 118 |
return processed_frame, graph
|
|
@@ -162,6 +159,13 @@ with gr.Blocks() as app:
|
|
| 162 |
|
| 163 |
def process_image(image, model):
|
| 164 |
frame_rgb, _, graph = process_frame(image, model)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
return frame_rgb, graph
|
| 166 |
|
| 167 |
process_button_image.click(process_image, inputs=[image_input, model_dropdown_image], outputs=[output_image, output_image_graph])
|
|
|
|
| 92 |
|
| 93 |
plt.close(fig)
|
| 94 |
|
| 95 |
+
return frame_rgb, frame_rgb, plot_img
|
|
|
|
|
|
|
|
|
|
| 96 |
except Exception as e:
|
| 97 |
print(f"An error occurred: {str(e)}")
|
| 98 |
+
return cv2.cvtColor(frame, cv2.COLOR_BGR2RGB), frame, None
|
| 99 |
|
| 100 |
def process_video(input_video, selected_model, frame_index):
|
| 101 |
try:
|
|
|
|
| 109 |
if not ret:
|
| 110 |
return None, None
|
| 111 |
|
| 112 |
+
processed_frame, _, graph = process_frame(frame, selected_model)
|
| 113 |
cap.release()
|
| 114 |
|
| 115 |
return processed_frame, graph
|
|
|
|
| 159 |
|
| 160 |
def process_image(image, model):
|
| 161 |
frame_rgb, _, graph = process_frame(image, model)
|
| 162 |
+
# Ensure the frame is in RGB format
|
| 163 |
+
if len(frame_rgb.shape) == 3 and frame_rgb.shape[2] == 3:
|
| 164 |
+
if frame_rgb.dtype != np.uint8:
|
| 165 |
+
frame_rgb = (frame_rgb * 255).astype(np.uint8)
|
| 166 |
+
else:
|
| 167 |
+
# If the image is not in the correct format, convert it to RGB
|
| 168 |
+
frame_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 169 |
return frame_rgb, graph
|
| 170 |
|
| 171 |
process_button_image.click(process_image, inputs=[image_input, model_dropdown_image], outputs=[output_image, output_image_graph])
|