Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,7 +23,7 @@ import gradio as gr
|
|
23 |
|
24 |
# tool which i creating. A tool for generating an animal image
|
25 |
@tool
|
26 |
-
def animal_image_generation_tool(animal_name: str) ->
|
27 |
"""Generating an image of an animal by its name.
|
28 |
Args:
|
29 |
animal_name: A string representing the name of the animal to search for (e.g., 'cat').
|
@@ -40,21 +40,17 @@ def animal_image_generation_tool(animal_name: str) -> str:
|
|
40 |
promt=f"Create a realistic image of a {animal_name}"
|
41 |
image = image_generation_tool(promt) # This returns a PIL image
|
42 |
|
43 |
-
#
|
44 |
-
image_path = f"{animal_name}_generated_image.jpg"
|
45 |
-
image.save(image_path)
|
46 |
-
|
47 |
-
return image_path # Return the path to the saved image
|
48 |
except Exception as e:
|
49 |
return f"Error during image generation: {str(e)}"
|
50 |
|
51 |
# Function to display the image in Gradio
|
52 |
def display_image(animal_name: str):
|
53 |
# Call the tool to generate the image
|
54 |
-
|
55 |
-
if
|
56 |
-
return
|
57 |
-
return
|
58 |
|
59 |
@tool
|
60 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
23 |
|
24 |
# tool which i creating. A tool for generating an animal image
|
25 |
@tool
|
26 |
+
def animal_image_generation_tool(animal_name: str) -> Image.Image:
|
27 |
"""Generating an image of an animal by its name.
|
28 |
Args:
|
29 |
animal_name: A string representing the name of the animal to search for (e.g., 'cat').
|
|
|
40 |
promt=f"Create a realistic image of a {animal_name}"
|
41 |
image = image_generation_tool(promt) # This returns a PIL image
|
42 |
|
43 |
+
return image # Return the path to the saved image
|
|
|
|
|
|
|
|
|
44 |
except Exception as e:
|
45 |
return f"Error during image generation: {str(e)}"
|
46 |
|
47 |
# Function to display the image in Gradio
|
48 |
def display_image(animal_name: str):
|
49 |
# Call the tool to generate the image
|
50 |
+
image = animal_image_generation_tool(animal_name)
|
51 |
+
if isinstance(image, str): # If an error message is returned
|
52 |
+
return image # Return the error message
|
53 |
+
return image # Return the PIL image object
|
54 |
|
55 |
@tool
|
56 |
def get_current_time_in_timezone(timezone: str) -> str:
|