poudel commited on
Commit
036a934
·
verified ·
1 Parent(s): f646432

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  from ultralytics import YOLO
3
- from PIL import Image
4
 
5
  # Load YOLOv8 models from Hugging Face Hub
6
  best_model = YOLO('https://huggingface.co/poudel/yolov8-cargo-package-counter/resolve/main/best.pt')
@@ -16,11 +15,11 @@ def count_packages(image, model_choice):
16
 
17
  # Run inference using the selected model
18
  results = model(image)
19
-
20
  # Get the number of detected boxes (packages)
21
  package_count = len(results[0].boxes)
22
-
23
-
24
 
25
  # Gradio interface with model selection dropdown
26
  inputs = [
@@ -28,8 +27,7 @@ inputs = [
28
  gr.Radio(["Best Model", "Last Model"], label="Choose Model")
29
  ]
30
 
31
- outputs = [gr.Textbox(label="Package Count"),
32
- gr.Image(type="pil", label="Annotated Image")]
33
 
34
  # Launch the Gradio app
35
  gr.Interface(fn=count_packages,
@@ -37,4 +35,4 @@ gr.Interface(fn=count_packages,
37
  outputs=outputs,
38
  title="Cargo Package Counting App",
39
  description="Upload an image and select a model to count the number of packages detected.",
40
- live=True).launch()
 
1
  import gradio as gr
2
  from ultralytics import YOLO
 
3
 
4
  # Load YOLOv8 models from Hugging Face Hub
5
  best_model = YOLO('https://huggingface.co/poudel/yolov8-cargo-package-counter/resolve/main/best.pt')
 
15
 
16
  # Run inference using the selected model
17
  results = model(image)
18
+
19
  # Get the number of detected boxes (packages)
20
  package_count = len(results[0].boxes)
21
+
22
+ return package_count
23
 
24
  # Gradio interface with model selection dropdown
25
  inputs = [
 
27
  gr.Radio(["Best Model", "Last Model"], label="Choose Model")
28
  ]
29
 
30
+ outputs = gr.Textbox(label="Package Count")
 
31
 
32
  # Launch the Gradio app
33
  gr.Interface(fn=count_packages,
 
35
  outputs=outputs,
36
  title="Cargo Package Counting App",
37
  description="Upload an image and select a model to count the number of packages detected.",
38
+ live=True).launch()