Kushalmanda commited on
Commit
2da5946
·
verified ·
1 Parent(s): 78b2af3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -7
app.py CHANGED
@@ -2,16 +2,32 @@ import torch
2
  import gradio as gr
3
  from PIL import Image
4
 
5
- # Load the YOLOv5 model (adjust based on the model you uploaded)
6
- model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # You can choose yolov5s, yolov5m, yolov5l
7
 
8
- # Function to handle 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 upload an image and get predictions
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