Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,15 +52,25 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
| 52 |
|
| 53 |
@tool
|
| 54 |
def generate_image(prompt: str) -> str:
|
| 55 |
-
"""
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
Args:
|
| 59 |
prompt: A descriptive text prompt for the image (e.g., 'A cat on the beach').
|
| 60 |
"""
|
| 61 |
try:
|
| 62 |
-
#
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
except Exception as e:
|
| 65 |
return f"Error generating image: {str(e)}"
|
| 66 |
|
|
|
|
| 52 |
|
| 53 |
@tool
|
| 54 |
def generate_image(prompt: str) -> str:
|
| 55 |
+
"""
|
| 56 |
+
Generates an image using Stable Diffusion XL based on a text prompt.
|
| 57 |
+
Returns the path to the generated image file.
|
| 58 |
|
| 59 |
Args:
|
| 60 |
prompt: A descriptive text prompt for the image (e.g., 'A cat on the beach').
|
| 61 |
"""
|
| 62 |
try:
|
| 63 |
+
# 我们显式指定一个免费的模型 ID:stable-diffusion-xl-base-1.0
|
| 64 |
+
client = InferenceClient("stabilityai/stable-diffusion-xl-base-1.0")
|
| 65 |
+
|
| 66 |
+
# 生成图片
|
| 67 |
+
image = client.text_to_image(prompt)
|
| 68 |
+
|
| 69 |
+
# 将图片保存到本地文件
|
| 70 |
+
filename = "generated_image.png"
|
| 71 |
+
image.save(filename)
|
| 72 |
+
|
| 73 |
+
return f"Image generated successfully and saved to {filename}"
|
| 74 |
except Exception as e:
|
| 75 |
return f"Error generating image: {str(e)}"
|
| 76 |
|