Spaces:
Sleeping
Sleeping
Update app.py
Browse filesconvert to PIL image in the comic generator
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
|
|
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
@@ -33,20 +35,34 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
| 36 |
@tool
|
| 37 |
def comic_strip_generator(scene_description: str) -> str:
|
| 38 |
-
"""Generates a comic strip from a scene description using image generation.
|
| 39 |
Args:
|
| 40 |
scene_description: A creative, descriptive text outlining a scene or story.
|
| 41 |
"""
|
| 42 |
try:
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
except Exception as e:
|
| 47 |
return f"Error generating comic: {str(e)}"
|
| 48 |
|
| 49 |
|
|
|
|
| 50 |
final_answer = FinalAnswerTool()
|
| 51 |
|
| 52 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
+
import os
|
| 4 |
+
from PIL import Image
|
| 5 |
import requests
|
| 6 |
import pytz
|
| 7 |
import yaml
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 37 |
|
| 38 |
+
|
| 39 |
+
|
| 40 |
@tool
|
| 41 |
def comic_strip_generator(scene_description: str) -> str:
|
| 42 |
+
"""Generates a comic strip image from a scene description using image generation.
|
| 43 |
Args:
|
| 44 |
scene_description: A creative, descriptive text outlining a scene or story.
|
| 45 |
"""
|
| 46 |
try:
|
| 47 |
+
image = image_generation_tool(scene_description)
|
| 48 |
+
# Generate a unique filename
|
| 49 |
+
filename = f"comic_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
| 50 |
+
filepath = os.path.join("generated_comics", filename)
|
| 51 |
+
|
| 52 |
+
# Ensure the output directory exists
|
| 53 |
+
os.makedirs("generated_comics", exist_ok=True)
|
| 54 |
+
|
| 55 |
+
# Save image if it's a PIL image
|
| 56 |
+
if isinstance(image, Image.Image):
|
| 57 |
+
image.save(filepath)
|
| 58 |
+
return f"Here's your comic scene saved at: {filepath}"
|
| 59 |
+
else:
|
| 60 |
+
return f"Unexpected image output: {type(image)}"
|
| 61 |
except Exception as e:
|
| 62 |
return f"Error generating comic: {str(e)}"
|
| 63 |
|
| 64 |
|
| 65 |
+
|
| 66 |
final_answer = FinalAnswerTool()
|
| 67 |
|
| 68 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|