Spaces:
Runtime error
Runtime error
File size: 1,426 Bytes
1ff7175 aa07dbb f3f10d4 aa07dbb c576123 f3f10d4 c045160 f3f10d4 c045160 f3f10d4 c045160 f3f10d4 c045160 f3f10d4 c045160 c576123 c045160 c576123 c7a0ce6 aa07dbb c7a0ce6 1ff7175 aa07dbb c7a0ce6 f3f10d4 807dd72 c045160 f3f10d4 c045160 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# Import necessary library
import gradio
# Define the nested dictionary of owners and their respective pets
owner_pets = {
"Emily": {"David": "./David.jpg"},
"Sasha": {"Kikou": "./Kikou.jpg"},
# Add more owners and their pets as needed
}
import os
for owner, owned_pets in owner_pets.items():
for pet, img_path in owned_pets.items():
assert os.path.isfile(img_path), f"File '{img_path}' does not exist."
# Define your function
def your_function(owner_name, pet_name=None):
pets = owner_pets.get(owner_name)
if pets is None:
# Return the first pet image if no pet name was provided
return next((val for sublist in owner_pets.values() for val in sublist), "./download.jpeg")
pet_image = None
if pets and (pet_name is None or pet_name in pets):
pet_image = pets[pet_name]
return pet_image or "./download.jpeg"
# Define your Gradio interface
def your_gradio_function(owner_name):
print(f"Received owner name: {owner_name}")
image_path = your_function(owner_name)
print(f"Returned image path: {image_path}")
return image_path
# Create the interface
interface = gradio.Interface(fn=your_gradio_function, inputs=["text"], outputs="image")
# Launch the interface
interface.launch()
if __name__ == "__main__":
interface.input("Owner Name").send_value("Emily")
output = interface.run().result()
print(f"Image for Emily: {output}") |