CharmainChua commited on
Commit
05a6472
·
1 Parent(s): c2d444a

UPDATED app.py and requirements

Browse files
Files changed (2) hide show
  1. app.py +10 -20
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,26 +1,16 @@
1
  import gradio as gr
2
  from ultralytics import YOLO
3
- from PIL import Image
4
 
5
- # Load the YOLO model
6
- model = YOLO("best_int8_openvino_model", task="detect") # Update with your model's path
7
 
8
- # Function to process the uploaded image
9
- def detect_objects(image):
10
- # Convert the uploaded image to YOLO-compatible format
11
- results = model(image) # Perform inference
12
- annotated_image = results[0].plot() # Get annotated image as a NumPy array
13
- return Image.fromarray(annotated_image[..., ::-1]) # Convert BGR to RGB for PIL
14
 
15
  # Create the Gradio interface
16
- demo = gr.Interface(
17
- fn=detect_objects,
18
- inputs=gr.inputs.Image(type="pil"), # Accept image uploads
19
- outputs="image", # Return the processed image
20
- title="Object Detection App",
21
- description="Upload an image to detect objects using a YOLO model."
22
- )
23
-
24
- # Launch the app
25
- if __name__ == "__main__":
26
- demo.launch()
 
1
  import gradio as gr
2
  from ultralytics import YOLO
 
3
 
4
+ # Load your YOLO model (ensure correct path to your model)
5
+ model = YOLO("best_int8_openvino_model.pt", task="detect")
6
 
7
+ # Define the prediction function
8
+ def predict_image(image):
9
+ results = model(image)
10
+ return results.plot() # Returns the image with detected objects
 
 
11
 
12
  # Create the Gradio interface
13
+ demo = gr.Interface(fn=predict_image,
14
+ inputs=gr.Image(type="pil"), # Updated syntax
15
+ outputs=gr.Image()) # Outputs an image
16
+ demo.launch()
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
  ultralytics
2
- gradio
 
1
  ultralytics
2
+ huggingface_hub