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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -14
app.py CHANGED
@@ -1,25 +1,36 @@
1
  import gradio as gr
2
 
3
- # Assuming you have a dictionary of pet names and their image URLs or file paths
4
- pet_images = {
5
- "David": "./david.jpg",
6
- "Kikou": "./kikou.jpg",
7
- # Add as many pets as you have
8
  }
9
 
10
- # Define your Gradio interface here
11
- def your_function(pet_name):
12
- # Handle the input and produce the image path or URL
13
- image_path = pet_images.get(pet_name, "./default_pet.jpg") # Use a valid default image path
 
 
 
 
 
 
 
 
 
14
  return image_path
15
 
16
  # Create the interface
17
- iface = gr.Interface(fn=your_function, inputs="text", outputs="image")
18
 
19
  # Launch the interface
20
- iface.launch()
21
 
22
  if __name__ == "__main__":
23
- iface.input("Pet Name").send_value("Kikou") # Set the initial value for the input field
24
- output = iface.run().result()
25
- print(f"Image for Kikou: {output}")
 
 
 
1
  import gradio as gr
2
 
3
+ # Define the nested dictionary of owners and their respective pets
4
+ owner_pets = {
5
+ "Emily": {"David": "./David.jpg"},
6
+ "Sasha": {"Kikou": "./Kikou.jpg"},
7
+ # Add more owners and their pets as needed
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}")