Bobricha commited on
Commit
b934bcd
·
verified ·
1 Parent(s): 4706fec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -10
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) -> 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
- # Save the image temporarily to display it in Gradio
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
- image_path = animal_image_generation_tool(animal_name)
55
- if image_path.startswith("Error"):
56
- return image_path # Return the error message if something went wrong
57
- return image_path # Return the path to the image
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: