Spaces:
Runtime error
Runtime error
Update app.py
Browse filesattempting to resolve the error
app.py
CHANGED
|
@@ -43,30 +43,46 @@ custom_role_conversions=None,
|
|
| 43 |
)
|
| 44 |
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Import tool from Hub
|
| 47 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
@tool
|
| 50 |
def generate_line_drawing_image(description: str) -> str:
|
| 51 |
"""
|
| 52 |
-
Generates a line drawing image based on the given
|
| 53 |
-
|
| 54 |
-
This tool utilizes a text-to-image model to create a line drawing
|
| 55 |
-
representation of the provided description.
|
| 56 |
|
| 57 |
Args:
|
| 58 |
description (str): A descriptive text prompt for the image.
|
| 59 |
-
|
| 60 |
-
Examples:
|
| 61 |
-
- "A cat sitting on a windowsill, looking out at a rainy day"
|
| 62 |
-
- "A futuristic cityscape with towering skyscrapers and flying cars"
|
| 63 |
|
| 64 |
Returns:
|
| 65 |
str: A URL to the generated image.
|
| 66 |
"""
|
| 67 |
-
try:
|
| 68 |
image_url = image_generation_tool.generate_image(
|
| 69 |
-
prompt
|
| 70 |
num_images=1
|
| 71 |
)[0]
|
| 72 |
return f"Here's your line drawing image: {image_url}"
|
|
@@ -75,10 +91,10 @@ def generate_line_drawing_image(description: str) -> str:
|
|
| 75 |
|
| 76 |
with open("prompts.yaml", 'r') as stream:
|
| 77 |
prompt_templates = yaml.safe_load(stream)
|
| 78 |
-
|
| 79 |
agent = CodeAgent(
|
| 80 |
-
model=model,
|
| 81 |
-
tools=[final_answer],
|
| 82 |
max_steps=6,
|
| 83 |
verbosity_level=1,
|
| 84 |
grammar=None,
|
|
@@ -88,5 +104,4 @@ agent = CodeAgent(
|
|
| 88 |
prompt_templates=prompt_templates
|
| 89 |
)
|
| 90 |
|
| 91 |
-
|
| 92 |
GradioUI(agent).launch()
|
|
|
|
| 43 |
)
|
| 44 |
|
| 45 |
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
from smolagents import CodeAgent, load_tool, tool
|
| 49 |
+
from huggingface_hub import InferenceClient
|
| 50 |
+
import yaml
|
| 51 |
+
|
| 52 |
+
# ... (rest of your imports)
|
| 53 |
+
|
| 54 |
# Import tool from Hub
|
| 55 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 56 |
|
| 57 |
+
from smolagents import Tool
|
| 58 |
+
from huggingface_hub import InferenceClient
|
| 59 |
+
|
| 60 |
+
class TextToImageTool(Tool):
|
| 61 |
+
description = "This tool creates an image according to a prompt, which is a text description."
|
| 62 |
+
name = "image_generator"
|
| 63 |
+
inputs = {"prompt": {"type": "string", "description": "The image generator prompt. Don't hesitate to add details in the prompt to make the image look better, like 'high-res, photorealistic', etc."}}
|
| 64 |
+
output_type = "image"
|
| 65 |
+
model_sdxl = "black-forest-labs/FLUX.1-schnell"
|
| 66 |
+
client = InferenceClient(model_sdxl)
|
| 67 |
+
|
| 68 |
+
def forward(self, prompt):
|
| 69 |
+
return self.client.text_to_image(prompt)
|
| 70 |
+
|
| 71 |
@tool
|
| 72 |
def generate_line_drawing_image(description: str) -> str:
|
| 73 |
"""
|
| 74 |
+
Generates a line drawing image based on the given description.
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
Args:
|
| 77 |
description (str): A descriptive text prompt for the image.
|
| 78 |
+
(e.g., "A cat sitting on a windowsill", "A futuristic cityscape")
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
Returns:
|
| 81 |
str: A URL to the generated image.
|
| 82 |
"""
|
| 83 |
+
try:
|
| 84 |
image_url = image_generation_tool.generate_image(
|
| 85 |
+
prompt=f"{description}, in the style of line drawing",
|
| 86 |
num_images=1
|
| 87 |
)[0]
|
| 88 |
return f"Here's your line drawing image: {image_url}"
|
|
|
|
| 91 |
|
| 92 |
with open("prompts.yaml", 'r') as stream:
|
| 93 |
prompt_templates = yaml.safe_load(stream)
|
| 94 |
+
|
| 95 |
agent = CodeAgent(
|
| 96 |
+
model=model,
|
| 97 |
+
tools=[final_answer, generate_line_drawing_image],
|
| 98 |
max_steps=6,
|
| 99 |
verbosity_level=1,
|
| 100 |
grammar=None,
|
|
|
|
| 104 |
prompt_templates=prompt_templates
|
| 105 |
)
|
| 106 |
|
|
|
|
| 107 |
GradioUI(agent).launch()
|