Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -16,10 +16,16 @@ def daily_fortune(name: str) -> str:
|
|
16 |
Args:
|
17 |
name: The name of the person receiving the fortune.
|
18 |
"""
|
|
|
|
|
19 |
try:
|
20 |
-
#
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Random fortunes
|
25 |
fortunes = [
|
@@ -33,18 +39,25 @@ def daily_fortune(name: str) -> str:
|
|
33 |
# Pick a random fortune
|
34 |
fortune = random.choice(fortunes)
|
35 |
|
36 |
-
# Generate image
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
39 |
|
40 |
return (
|
41 |
f"🌞 Hello {name}!\n"
|
42 |
f"📰 Top News Today: {headline}\n"
|
43 |
f"🔮 Your Fortune: {fortune}\n"
|
44 |
-
f"🖼️ Fortune Vibes Image: {
|
45 |
)
|
|
|
46 |
except Exception as e:
|
47 |
return f"Error generating your fortune: {str(e)}"
|
|
|
|
|
48 |
|
49 |
|
50 |
@tool
|
|
|
16 |
Args:
|
17 |
name: The name of the person receiving the fortune.
|
18 |
"""
|
19 |
+
import random
|
20 |
+
|
21 |
try:
|
22 |
+
# Invoke DuckDuckGoSearchTool via agent
|
23 |
+
search_result = agent.invoke_tool(
|
24 |
+
"DuckDuckGoSearchTool",
|
25 |
+
{"query": "top news today", "max_results": 1}
|
26 |
+
)
|
27 |
+
|
28 |
+
headline = search_result.get('results', [{}])[0].get('snippet', 'No news found today.')
|
29 |
|
30 |
# Random fortunes
|
31 |
fortunes = [
|
|
|
39 |
# Pick a random fortune
|
40 |
fortune = random.choice(fortunes)
|
41 |
|
42 |
+
# Generate image using the image_generation_tool
|
43 |
+
image = agent.invoke_tool(
|
44 |
+
"agents-course/text-to-image",
|
45 |
+
{"prompt": f"A digital painting representing '{fortune}' with a whimsical style"}
|
46 |
+
)
|
47 |
+
|
48 |
+
image_url = image.get('url', 'No image generated.')
|
49 |
|
50 |
return (
|
51 |
f"🌞 Hello {name}!\n"
|
52 |
f"📰 Top News Today: {headline}\n"
|
53 |
f"🔮 Your Fortune: {fortune}\n"
|
54 |
+
f"🖼️ Fortune Vibes Image: {image_url}\n"
|
55 |
)
|
56 |
+
|
57 |
except Exception as e:
|
58 |
return f"Error generating your fortune: {str(e)}"
|
59 |
+
|
60 |
+
|
61 |
|
62 |
|
63 |
@tool
|