Spaces:
Sleeping
Sleeping
Update app.py
#2
by
mnreddy7
- opened
app.py
CHANGED
@@ -44,6 +44,41 @@ def analyze_text_sentiment(text: str) -> str:
|
|
44 |
except Exception as e:
|
45 |
return f"Error analyzing sentiment: {str(e)}"
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
@tool
|
48 |
def get_current_time_in_timezone(timezone: str) -> str:
|
49 |
"""A tool that fetches the current local time in a specified timezone.
|
@@ -81,7 +116,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
81 |
|
82 |
agent = CodeAgent(
|
83 |
model=model,
|
84 |
-
tools=[final_answer,analyze_text_sentiment], ## add your tools here (don't remove final answer)
|
85 |
max_steps=6,
|
86 |
verbosity_level=1,
|
87 |
grammar=None,
|
|
|
44 |
except Exception as e:
|
45 |
return f"Error analyzing sentiment: {str(e)}"
|
46 |
|
47 |
+
@tool
|
48 |
+
def generate_dream_sequence(theme: str, intensity: int) -> str:
|
49 |
+
"""Generates a surreal dream sequence based on a theme and intensity level.
|
50 |
+
Args:
|
51 |
+
theme: A word or phrase to inspire the dream (e.g., 'forest', 'space')
|
52 |
+
intensity: Dream weirdness level (1-10)
|
53 |
+
"""
|
54 |
+
try:
|
55 |
+
if not 1 <= intensity <= 10:
|
56 |
+
return "Intensity must be between 1 and 10"
|
57 |
+
|
58 |
+
# Dream elements
|
59 |
+
entities = ["whispering trees", "floating clocks", "velvet whales", "mirrored shadows",
|
60 |
+
"singing stones", "dancing galaxies", "liquid mirrors", "feathered serpents"]
|
61 |
+
actions = ["melted into", "chased", "wove through", "echoed across", "dissolved into",
|
62 |
+
"spiraled around", "painted", "whispered to"]
|
63 |
+
sensations = ["a hum of static", "a taste of rain", "a shimmer of gold",
|
64 |
+
"a scent of forgotten time", "a pull of gravity", "a flicker of warmth"]
|
65 |
+
|
66 |
+
import random
|
67 |
+
random.seed(intensity + hash(theme))
|
68 |
+
dream_length = intensity // 2 + 1
|
69 |
+
|
70 |
+
dream = f"In a dream of {theme}, "
|
71 |
+
for _ in range(dream_length):
|
72 |
+
entity = random.choice(entities)
|
73 |
+
action = random.choice(actions)
|
74 |
+
next_entity = random.choice(entities)
|
75 |
+
sensation = random.choice(sensations)
|
76 |
+
dream += f"the {entity} {action} the {next_entity}, leaving {sensation}. "
|
77 |
+
|
78 |
+
return dream.strip()
|
79 |
+
except Exception as e:
|
80 |
+
return f"Dream disrupted: {str(e)}"
|
81 |
+
|
82 |
@tool
|
83 |
def get_current_time_in_timezone(timezone: str) -> str:
|
84 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
116 |
|
117 |
agent = CodeAgent(
|
118 |
model=model,
|
119 |
+
tools=[final_answer, analyze_text_sentiment, generate_dream_sequence], ## add your tools here (don't remove final answer)
|
120 |
max_steps=6,
|
121 |
verbosity_level=1,
|
122 |
grammar=None,
|