Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -2,16 +2,32 @@ import torch
|
|
2 |
import gradio as gr
|
3 |
from PIL import Image
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
def predict_image(image):
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
# Set up Gradio interface to
|
15 |
interface = gr.Interface(fn=predict_image, inputs=gr.Image(), outputs=gr.Dataframe())
|
16 |
|
17 |
# Launch the interface
|
|
|
2 |
import gradio as gr
|
3 |
from PIL import Image
|
4 |
|
5 |
+
# Debugging print statements
|
6 |
+
print("Loading YOLOv5 model...")
|
7 |
|
8 |
+
try:
|
9 |
+
# Load YOLOv5 model (adjust based on the model you uploaded)
|
10 |
+
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # 'yolov5s' is the small model, change if needed
|
11 |
+
print("Model loaded successfully!")
|
12 |
+
|
13 |
+
except Exception as e:
|
14 |
+
print(f"Error loading model: {e}")
|
15 |
+
raise
|
16 |
+
|
17 |
+
# Define the function for image inference
|
18 |
def predict_image(image):
|
19 |
+
try:
|
20 |
+
print("Running inference on the uploaded image...")
|
21 |
+
results = model(image) # Run inference on the input image
|
22 |
+
print("Inference completed!")
|
23 |
+
results.show() # Optional: Visualize the results (bounding boxes)
|
24 |
+
return results.pandas().xywh # Return the results (bounding box coordinates)
|
25 |
+
|
26 |
+
except Exception as e:
|
27 |
+
print(f"Error during inference: {e}")
|
28 |
+
return str(e)
|
29 |
|
30 |
+
# Set up Gradio interface to allow image uploads and get predictions
|
31 |
interface = gr.Interface(fn=predict_image, inputs=gr.Image(), outputs=gr.Dataframe())
|
32 |
|
33 |
# Launch the interface
|