EmilyWitko HF staff commited on
Commit
c045160
1 Parent(s): f3f10d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -8,29 +8,31 @@ owner_pets = {
8
  }
9
 
10
  # Define your function
11
- def your_function(owner_name, pet_name):
12
  pets = owner_pets.get(owner_name)
13
-
 
 
 
 
14
  pet_image = None
15
- if pets and pet_name in pets:
16
  pet_image = pets[pet_name]
17
-
18
  return pet_image or "./download.jpeg"
19
 
20
  # Define your Gradio interface
21
- def your_gradio_function(owner_name, pet_name):
22
- image_path = your_function(owner_name, pet_name)
23
  return image_path
24
 
25
  # Create the interface
26
- interface = gr.Interface(fn=your_gradio_function, inputs=["text", "text"], outputs="image")
27
 
28
  # Launch the interface
29
  interface.launch()
30
 
31
  if __name__ == "__main__":
32
- interface.inputs([{"label": "Owner Name", "type": "text"}, {"label": "Pet Name", "type": "text"}])
33
- interface.input("Owner Name").send_value("John Doe")
34
- interface.input("Pet Name").send_value("Doggo")
35
  output = interface.run().result()
36
- print(f"Image for Emily and David: {output}")
 
8
  }
9
 
10
  # Define your function
11
+ def your_function(owner_name, pet_name=None):
12
  pets = owner_pets.get(owner_name)
13
+
14
+ if pets is None:
15
+ # Return the first pet image if no pet name was provided
16
+ return next((val for sublist in owner_pets.values() for val in sublist), "./download.jpeg")
17
+
18
  pet_image = None
19
+ if pets and (pet_name is None or pet_name in pets):
20
  pet_image = pets[pet_name]
21
+
22
  return pet_image or "./download.jpeg"
23
 
24
  # Define your Gradio interface
25
+ def your_gradio_function(owner_name):
26
+ image_path = your_function(owner_name)
27
  return image_path
28
 
29
  # Create the interface
30
+ interface = gr.Interface(fn=your_gradio_function, inputs=["text"], outputs="image")
31
 
32
  # Launch the interface
33
  interface.launch()
34
 
35
  if __name__ == "__main__":
36
+ interface.input("Owner Name").send_value("Emily")
 
 
37
  output = interface.run().result()
38
+ print(f"Image for Emily: {output}")