jsr90 commited on
Commit
6a0206a
·
1 Parent(s): b67bcf9

Update app.py

Browse files

This updated code adds the option to upload an image by changing the source parameter of the gr.inputs.Image component to ["upload", "webcam"].

Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -3,24 +3,28 @@ import torch
3
  import numpy as np
4
  from PIL import Image
5
 
 
6
  model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', _verbose=False)
7
 
8
  def gradio_wrapper(img):
9
  global model
 
10
  results = model(img)
 
11
  return results.render()[0]
12
 
13
- image = gr.Image(source="webcam", streaming=True)
14
-
15
-
16
 
 
17
  demo = gr.Interface(
18
  gradio_wrapper,
19
  image,
20
  'image',
21
  live=True,
22
  title="CiclopeIA",
23
- description="Aplicación basada en el proyecto CiclopeIA de Saturdays AI. Identifica el valor de los billetes de Euro."
24
  )
25
 
26
- demo.launch()
 
 
3
  import numpy as np
4
  from PIL import Image
5
 
6
+ # Load the custom-trained YOLOv5 model
7
  model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', _verbose=False)
8
 
9
  def gradio_wrapper(img):
10
  global model
11
+ # Run the model on the input image and get the results
12
  results = model(img)
13
+ # Render the results and return the annotated image
14
  return results.render()[0]
15
 
16
+ # Set up the Gradio image input component with the option to upload an image or use the webcam
17
+ image = gr.inputs.Image(source=["upload", "webcam"], streaming=True)
 
18
 
19
+ # Create the Gradio interface with the gradio_wrapper function, the image input component, and an image output component
20
  demo = gr.Interface(
21
  gradio_wrapper,
22
  image,
23
  'image',
24
  live=True,
25
  title="CiclopeIA",
26
+ description="App based on the CiclopeIA project from Saturdays AI. Identifies the value of Euro banknotes."
27
  )
28
 
29
+ # Launch the Gradio interface
30
+ demo.launch()