Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,30 +2,14 @@ import torch
|
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 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 |
-
|
| 20 |
-
|
| 21 |
-
|
| 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())
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
+
# Load the YOLOv5 model from the uploaded file (e.g., 'yolov5s.pt')
|
| 6 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', path='yolov5s.pt') # Adjust the file name if needed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Define the function for image inference
|
| 9 |
def predict_image(image):
|
| 10 |
+
results = model(image) # Run inference on the input image
|
| 11 |
+
results.show() # Optionally visualize the results (bounding boxes)
|
| 12 |
+
return results.pandas().xywh # Return the results (bounding box coordinates)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Set up Gradio interface to allow image uploads and get predictions
|
| 15 |
interface = gr.Interface(fn=predict_image, inputs=gr.Image(), outputs=gr.Dataframe())
|