Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,8 @@ import pytz
|
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from tools.visit_webpage import VisitWebpageTool
|
|
|
|
|
|
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
@@ -34,6 +36,59 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
except Exception as e:
|
| 35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
search_web = DuckDuckGoSearchTool()
|
| 38 |
visit_page = VisitWebpageTool()
|
| 39 |
final_answer = FinalAnswerTool()
|
|
@@ -57,7 +112,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 57 |
|
| 58 |
agent = CodeAgent(
|
| 59 |
model=model,
|
| 60 |
-
tools=[final_answer, get_current_time_in_timezone, image_generation_tool, search_web, visit_page], ## add your tools here (don't remove final answer)
|
| 61 |
max_steps=6,
|
| 62 |
verbosity_level=1,
|
| 63 |
grammar=None,
|
|
|
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from tools.visit_webpage import VisitWebpageTool
|
| 8 |
+
import os
|
| 9 |
+
from urllib.parse import quote
|
| 10 |
|
| 11 |
from Gradio_UI import GradioUI
|
| 12 |
|
|
|
|
| 36 |
except Exception as e:
|
| 37 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 38 |
|
| 39 |
+
@tool
|
| 40 |
+
def dicebear_pixel_avatar(seed: str,
|
| 41 |
+
size: int = 256,
|
| 42 |
+
background: str = "transparent",
|
| 43 |
+
rounded: bool = True,
|
| 44 |
+
fmt: str = "png") -> str:
|
| 45 |
+
"""
|
| 46 |
+
Fetch a pixel-art avatar from the DiceBear API and save it to disk.
|
| 47 |
+
Args:
|
| 48 |
+
seed: String used to deterministically generate the avatar.
|
| 49 |
+
size: Image size in pixels (10–1024).
|
| 50 |
+
background: "transparent" or a hex color without the '#', e.g. "b6e3f4".
|
| 51 |
+
rounded: If True, applies radius=50 for rounded corners.
|
| 52 |
+
fmt: One of: "png", "svg", "jpg", "jpeg", "webp".
|
| 53 |
+
Returns:
|
| 54 |
+
Local file path to the saved image, or an error string.
|
| 55 |
+
"""
|
| 56 |
+
try:
|
| 57 |
+
if fmt not in ("png", "svg", "jpg", "jpeg", "webp"):
|
| 58 |
+
fmt = "png"
|
| 59 |
+
|
| 60 |
+
# DiceBear v9 pixel-art endpoint
|
| 61 |
+
base = f"https://api.dicebear.com/9.x/pixel-art/{fmt}"
|
| 62 |
+
params = [f"seed={quote(seed)}", f"size={size}"]
|
| 63 |
+
|
| 64 |
+
# Background handling
|
| 65 |
+
if background and background.lower() != "transparent":
|
| 66 |
+
# solid background color (omit '#' in hex)
|
| 67 |
+
params.append(f"backgroundColor={quote(background)}")
|
| 68 |
+
params.append("backgroundType=solid")
|
| 69 |
+
|
| 70 |
+
# Rounded corners
|
| 71 |
+
if rounded:
|
| 72 |
+
params.append("radius=50")
|
| 73 |
+
|
| 74 |
+
url = base + "?" + "&".join(params)
|
| 75 |
+
|
| 76 |
+
resp = requests.get(url, timeout=20)
|
| 77 |
+
resp.raise_for_status()
|
| 78 |
+
|
| 79 |
+
out_dir = "outputs"
|
| 80 |
+
os.makedirs(out_dir, exist_ok=True)
|
| 81 |
+
safe_seed = "".join(c for c in seed if c.isalnum() or c in ("-", "_"))[:40] or "seed"
|
| 82 |
+
filename = os.path.join(out_dir, f"dicebear_pixel_{safe_seed}_{size}.{fmt}")
|
| 83 |
+
|
| 84 |
+
with open(filename, "wb") as f:
|
| 85 |
+
f.write(resp.content)
|
| 86 |
+
|
| 87 |
+
return filename
|
| 88 |
+
except Exception as e:
|
| 89 |
+
return f"Error generating avatar: {e}"
|
| 90 |
+
|
| 91 |
+
|
| 92 |
search_web = DuckDuckGoSearchTool()
|
| 93 |
visit_page = VisitWebpageTool()
|
| 94 |
final_answer = FinalAnswerTool()
|
|
|
|
| 112 |
|
| 113 |
agent = CodeAgent(
|
| 114 |
model=model,
|
| 115 |
+
tools=[final_answer, get_current_time_in_timezone, image_generation_tool, search_web, visit_page, dicebear_pixel_avatar], ## add your tools here (don't remove final answer)
|
| 116 |
max_steps=6,
|
| 117 |
verbosity_level=1,
|
| 118 |
grammar=None,
|