Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,6 @@ from PIL import Image
|
|
| 11 |
hf_token = os.getenv("HF_ACCESS_TOKEN")
|
| 12 |
|
| 13 |
|
| 14 |
-
|
| 15 |
@tool
|
| 16 |
def generate_landscape_image(timezone: str) -> Image.Image:
|
| 17 |
"""
|
|
@@ -46,14 +45,17 @@ def generate_landscape_image(timezone: str) -> Image.Image:
|
|
| 46 |
else:
|
| 47 |
prompt = "A serene nighttime landscape featuring a luminous moon shining in the dark sky."
|
| 48 |
|
| 49 |
-
#
|
| 50 |
result = image_generation_tool(prompt)
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
return image
|
| 54 |
except Exception as e:
|
| 55 |
-
# If there's an error, you can either return a string or raise an error.
|
| 56 |
-
# Here we return a string, but Gradio might display it as plain text.
|
| 57 |
return f"Error generating image for timezone '{timezone}': {str(e)}"
|
| 58 |
|
| 59 |
@tool
|
|
|
|
| 11 |
hf_token = os.getenv("HF_ACCESS_TOKEN")
|
| 12 |
|
| 13 |
|
|
|
|
| 14 |
@tool
|
| 15 |
def generate_landscape_image(timezone: str) -> Image.Image:
|
| 16 |
"""
|
|
|
|
| 45 |
else:
|
| 46 |
prompt = "A serene nighttime landscape featuring a luminous moon shining in the dark sky."
|
| 47 |
|
| 48 |
+
# Call the image generation tool loaded from Space
|
| 49 |
result = image_generation_tool(prompt)
|
| 50 |
+
|
| 51 |
+
# If the result is an AgentImage, extract the underlying image.
|
| 52 |
+
if hasattr(result, "to_raw"):
|
| 53 |
+
image = result.to_raw()
|
| 54 |
+
else:
|
| 55 |
+
# Otherwise assume it's a file path and open it.
|
| 56 |
+
image = Image.open(result)
|
| 57 |
return image
|
| 58 |
except Exception as e:
|
|
|
|
|
|
|
| 59 |
return f"Error generating image for timezone '{timezone}': {str(e)}"
|
| 60 |
|
| 61 |
@tool
|