DexterSptizu commited on
Commit
5314499
·
verified ·
1 Parent(s): 927d5e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -19
app.py CHANGED
@@ -4,7 +4,6 @@ from PIL import Image
4
  import gradio as gr
5
  from transformers import pipeline
6
  import matplotlib.pyplot as plt
7
- import requests
8
 
9
  # Initialize the models
10
  detector50 = pipeline(model="facebook/detr-resnet-50")
@@ -51,36 +50,26 @@ def infer(model, in_pil_img):
51
  results = detector101(in_pil_img) if model == "detr-resnet-101" else detector50(in_pil_img)
52
  return get_figure(in_pil_img, results)
53
 
54
- def url_to_image(url):
55
- response = requests.get(url)
56
- img = Image.open(io.BytesIO(response.content))
57
- return img
58
-
59
- # Define Gradio interface
60
  with gr.Blocks() as demo:
61
  gr.Markdown("## DETR Object Detection")
 
62
  model = gr.Radio(["detr-resnet-50", "detr-resnet-101"], value="detr-resnet-50", label="Model name")
63
-
64
- # Example images from the internet
65
- example_urls = [
66
- "https://www.quickanddirtytips.com/wp-content/uploads/2022/05/ezgif.com-gif-maker-3.jpg",
67
- "https://img.freepik.com/free-photo/people-posing-together-registration-day_23-2149096794.jpg",
68
- "https://www.shutterstock.com/shutterstock/photos/2077329079/display_1500/stock-photo-pushkar-india-nov-people-walking-in-a-busy-road-in-the-street-market-in-holy-city-2077329079.jpg",
69
- "https://static.autox.com/uploads/2023/01/mahindra-xuv400.jpg",
70
- "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQrmOeQJN9IzbR8ofJDpxcIHDSOSXg_5hzgfA&s"
71
- ]
72
 
 
73
  examples = gr.Examples(
74
- examples=example_urls,
 
 
 
75
  inputs=[gr.Image(type="pil")],
76
- fn=lambda x: url_to_image(x),
77
  label="Try these example images"
78
  )
79
 
80
  input_image = gr.Image(label="Input image", type="pil")
81
  output_image = gr.Image(label="Output image")
82
  send_btn = gr.Button("Infer")
83
-
84
  # Trigger inference on button click
85
  send_btn.click(fn=infer, inputs=[model, input_image], outputs=output_image)
86
 
 
4
  import gradio as gr
5
  from transformers import pipeline
6
  import matplotlib.pyplot as plt
 
7
 
8
  # Initialize the models
9
  detector50 = pipeline(model="facebook/detr-resnet-50")
 
50
  results = detector101(in_pil_img) if model == "detr-resnet-101" else detector50(in_pil_img)
51
  return get_figure(in_pil_img, results)
52
 
53
+ # Define Gradio interface with local image examples
 
 
 
 
 
54
  with gr.Blocks() as demo:
55
  gr.Markdown("## DETR Object Detection")
56
+
57
  model = gr.Radio(["detr-resnet-50", "detr-resnet-101"], value="detr-resnet-50", label="Model name")
 
 
 
 
 
 
 
 
 
58
 
59
+ # Use local image files instead of URLs
60
  examples = gr.Examples(
61
+ examples=[
62
+ ["image1.jpg"],
63
+ ["image2.jpg"]
64
+ ],
65
  inputs=[gr.Image(type="pil")],
 
66
  label="Try these example images"
67
  )
68
 
69
  input_image = gr.Image(label="Input image", type="pil")
70
  output_image = gr.Image(label="Output image")
71
  send_btn = gr.Button("Infer")
72
+
73
  # Trigger inference on button click
74
  send_btn.click(fn=infer, inputs=[model, input_image], outputs=output_image)
75