Spaces:
Sleeping
Sleeping
Mohammed Abdeldayem
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,9 @@ def init():
|
|
| 10 |
|
| 11 |
# Step 1: Load the YOLOv5 model from Hugging Face
|
| 12 |
try:
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
print("YOLOv5 model loaded successfully.")
|
| 15 |
except Exception as e:
|
| 16 |
print(f"Error loading YOLOv5 model: {e}")
|
|
@@ -76,15 +78,16 @@ def process_image(image):
|
|
| 76 |
# Initialize models
|
| 77 |
init()
|
| 78 |
|
| 79 |
-
# Gradio
|
| 80 |
interface = gr.Interface(
|
| 81 |
fn=process_image, # Function to run
|
| 82 |
-
inputs=gr.
|
| 83 |
-
outputs=[gr.
|
| 84 |
-
gr.
|
| 85 |
-
gr.
|
| 86 |
live=True
|
| 87 |
)
|
| 88 |
|
|
|
|
| 89 |
# Launch the Gradio app
|
| 90 |
interface.launch()
|
|
|
|
| 10 |
|
| 11 |
# Step 1: Load the YOLOv5 model from Hugging Face
|
| 12 |
try:
|
| 13 |
+
# Load the YOLOv5 model with trust_repo=True to skip the warning
|
| 14 |
+
object_detection_model = torch.hub.load('ultralytics/yolov5', 'custom', path='yolov5/weights/best14.pt', trust_repo=True)
|
| 15 |
+
# Assuming model is locally available
|
| 16 |
print("YOLOv5 model loaded successfully.")
|
| 17 |
except Exception as e:
|
| 18 |
print(f"Error loading YOLOv5 model: {e}")
|
|
|
|
| 78 |
# Initialize models
|
| 79 |
init()
|
| 80 |
|
| 81 |
+
# Updated Gradio interface with new syntax
|
| 82 |
interface = gr.Interface(
|
| 83 |
fn=process_image, # Function to run
|
| 84 |
+
inputs=gr.Image(type="pil"), # Input: Image upload
|
| 85 |
+
outputs=[gr.Image(type="pil", label="Detected Objects"), # Output 1: Image with bounding boxes
|
| 86 |
+
gr.JSON(label="Object Captions & Bounding Boxes"), # Output 2: JSON results for each object
|
| 87 |
+
gr.Textbox(label="Whole Image Caption")], # Output 3: Caption for the whole image
|
| 88 |
live=True
|
| 89 |
)
|
| 90 |
|
| 91 |
+
|
| 92 |
# Launch the Gradio app
|
| 93 |
interface.launch()
|