user-agent commited on
Commit
5012113
1 Parent(s): a4dc223

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -12,7 +12,6 @@ images="dog.jpg"
12
 
13
  @spaces.GPU
14
  def shot(input, labels_text):
15
- # Check if the input is a URL or an uploaded image
16
  if isinstance(input, str) and (input.startswith("http://") or input.startswith("https://")):
17
  # Input is a URL
18
  response = requests.get(input)
@@ -21,25 +20,20 @@ def shot(input, labels_text):
21
  # Input is an uploaded image
22
  PIL_image = Image.fromarray(np.uint8(input)).convert('RGB')
23
 
24
- # Split labels into a list
25
  labels = labels_text.split(",")
26
-
27
- # Perform the zero-shot image classification
28
  res = pipe(images=PIL_image,
29
  candidate_labels=labels,
30
  hypothesis_template="This is a photo of a {}")
31
-
32
- # Return the classification results as a dictionary
33
  return {dic["label"]: dic["score"] for dic in res}
34
 
35
- # Define the Gradio interface
36
  iface = gr.Interface(
37
  fn=shot,
38
  inputs=[
39
- gr.inputs.Textbox(label="Image URL (starting with http/https) or Upload Image"),
40
- "text"
41
  ],
42
- outputs="label",
43
  examples=[
44
  ["https://example.com/dog.jpg", "dog,cat,bird"],
45
  ["https://example.com/germany.jpg", "germany,belgium,colombia"],
@@ -50,4 +44,4 @@ iface = gr.Interface(
50
  )
51
 
52
  # Launch the interface
53
- iface.launch()
 
12
 
13
  @spaces.GPU
14
  def shot(input, labels_text):
 
15
  if isinstance(input, str) and (input.startswith("http://") or input.startswith("https://")):
16
  # Input is a URL
17
  response = requests.get(input)
 
20
  # Input is an uploaded image
21
  PIL_image = Image.fromarray(np.uint8(input)).convert('RGB')
22
 
 
23
  labels = labels_text.split(",")
 
 
24
  res = pipe(images=PIL_image,
25
  candidate_labels=labels,
26
  hypothesis_template="This is a photo of a {}")
 
 
27
  return {dic["label"]: dic["score"] for dic in res}
28
 
29
+ # Define the Gradio interface with the updated components
30
  iface = gr.Interface(
31
  fn=shot,
32
  inputs=[
33
+ gr.Textbox(label="Image URL (starting with http/https) or Upload Image"),
34
+ gr.Textbox(label="Labels (comma-separated)")
35
  ],
36
+ outputs=gr.Label(),
37
  examples=[
38
  ["https://example.com/dog.jpg", "dog,cat,bird"],
39
  ["https://example.com/germany.jpg", "germany,belgium,colombia"],
 
44
  )
45
 
46
  # Launch the interface
47
+ iface.launch()