Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,9 @@ import pytz
|
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
|
8 |
-
|
9 |
from Gradio_UI import GradioUI
|
10 |
-
|
|
|
11 |
|
12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
13 |
#@tool
|
@@ -38,12 +38,23 @@ def animal_image_generation_tool(animal_name: str) -> str:
|
|
38 |
|
39 |
# generates an image based on the description of an animal.
|
40 |
promt=f"Create a realistic image of a {animal_name}"
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
44 |
except Exception as e:
|
45 |
return f"Error during image generation: {str(e)}"
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
@tool
|
49 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -97,5 +108,19 @@ agent = CodeAgent(
|
|
97 |
prompt_templates=prompt_templates
|
98 |
)
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
GradioUI(agent).launch()
|
|
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
|
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
+
from PIL import Image
|
10 |
+
import gradio as gr
|
11 |
|
12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
13 |
#@tool
|
|
|
38 |
|
39 |
# generates an image based on the description of an animal.
|
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:
|
|
|
108 |
prompt_templates=prompt_templates
|
109 |
)
|
110 |
|
111 |
+
# Gradio Interface
|
112 |
+
def gradio_interface(animal_name: str):
|
113 |
+
return display_image(animal_name)
|
114 |
+
|
115 |
+
|
116 |
+
# Launch Gradio UI
|
117 |
+
iface = gr.Interface(
|
118 |
+
fn=gradio_interface,
|
119 |
+
inputs="text",
|
120 |
+
outputs="image",
|
121 |
+
title="Animal Image Generator",
|
122 |
+
description="Generate an image of an animal by its name.",
|
123 |
+
)
|
124 |
+
|
125 |
|
126 |
GradioUI(agent).launch()
|