Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,26 +9,6 @@ from PIL import Image
|
|
| 9 |
import io
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
| 12 |
-
@tool
|
| 13 |
-
def generate_image(prompt: str) -> str:
|
| 14 |
-
"""
|
| 15 |
-
Generates an image based on a provided text prompt using an open-source model,
|
| 16 |
-
saves it locally, and returns the path to render it in the chat interface.
|
| 17 |
-
|
| 18 |
-
Args:
|
| 19 |
-
prompt: A detailed text description of the image to create.
|
| 20 |
-
"""
|
| 21 |
-
# 1. Fetch image from Hugging Face Inference API
|
| 22 |
-
client = InferenceClient("black-forest-labs/FLUX.1-schnell")
|
| 23 |
-
image_bytes = client.text_to_image(prompt)
|
| 24 |
-
image = Image.open(io.BytesIO(image_bytes))
|
| 25 |
-
|
| 26 |
-
# 2. Save it locally inside your execution workspace
|
| 27 |
-
output_path = "generated_output.png"
|
| 28 |
-
image.save(output_path)
|
| 29 |
-
|
| 30 |
-
# 3. Return the string file path. Gradio will intercept this path and display the actual image!
|
| 31 |
-
return output_path
|
| 32 |
|
| 33 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 34 |
@tool
|
|
@@ -84,7 +64,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 84 |
|
| 85 |
agent = CodeAgent(
|
| 86 |
model=model,
|
| 87 |
-
tools=[final_answer, get_current_time_in_timezone, image_generation_tool, cast_spell
|
| 88 |
max_steps=6,
|
| 89 |
verbosity_level=1,
|
| 90 |
grammar=None,
|
|
|
|
| 9 |
import io
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 14 |
@tool
|
|
|
|
| 64 |
|
| 65 |
agent = CodeAgent(
|
| 66 |
model=model,
|
| 67 |
+
tools=[final_answer, get_current_time_in_timezone, image_generation_tool, cast_spell], ## add your tools here (don't remove final answer)
|
| 68 |
max_steps=6,
|
| 69 |
verbosity_level=1,
|
| 70 |
grammar=None,
|