Spaces:
Sleeping
Sleeping
Add "Happiness Score Calculator" tool.
Browse filesCreative calculation function that simulates a "Happiness Score" based on various life factors.
app.py
CHANGED
@@ -7,16 +7,39 @@ from tools.final_answer import FinalAnswerTool
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
#
|
11 |
@tool
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -42,7 +65,7 @@ final_answer = FinalAnswerTool()
|
|
42 |
model = HfApiModel(
|
43 |
max_tokens=2096,
|
44 |
temperature=0.5,
|
45 |
-
model_id='
|
46 |
custom_role_conversions=None,
|
47 |
)
|
48 |
|
@@ -55,13 +78,13 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
62 |
planning_interval=None,
|
63 |
-
name=
|
64 |
-
description=
|
65 |
prompt_templates=prompt_templates
|
66 |
)
|
67 |
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
# Tool that simulates a "Happiness Score" based on various life factors
|
11 |
@tool
|
12 |
+
def calculate_happiness(sleep_hours: float, exercise_minutes: int, social_interactions: int, stress_level: int) -> str:
|
13 |
+
"""Calculates a fun 'Happiness Score' based on lifestyle factors.
|
14 |
+
|
15 |
Args:
|
16 |
+
sleep_hours: Hours of sleep (0-12)
|
17 |
+
exercise_minutes: Minutes of exercise per day (0-180)
|
18 |
+
social_interactions: Number of meaningful conversations per day (0-20)
|
19 |
+
stress_level: Stress level from 1 (low) to 10 (high)
|
20 |
+
|
21 |
+
Returns:
|
22 |
+
A string with the calculated happiness score and a fun message.
|
23 |
"""
|
24 |
+
# Normalize the inputs into a score (out of 100)
|
25 |
+
sleep_score = min(sleep_hours / 8 * 30, 30) # Max 30 points
|
26 |
+
exercise_score = min(exercise_minutes / 60 * 20, 20) # Max 20 points
|
27 |
+
social_score = min(social_interactions / 5 * 20, 20) # Max 20 points
|
28 |
+
stress_penalty = (10 - stress_level) * 3 # Lower stress gives higher score (Max 30 points)
|
29 |
+
|
30 |
+
happiness_score = round(sleep_score + exercise_score + social_score + stress_penalty)
|
31 |
+
|
32 |
+
# Fun messages based on happiness level
|
33 |
+
if happiness_score > 80:
|
34 |
+
message = "😃 You're living your best life! Keep it up!"
|
35 |
+
elif happiness_score > 60:
|
36 |
+
message = "😊 You're doing well! A few tweaks can boost your happiness even more."
|
37 |
+
elif happiness_score > 40:
|
38 |
+
message = "😐 Things are okay, but there's room for improvement."
|
39 |
+
else:
|
40 |
+
message = "😟 You might need to make some changes. Try adding more sleep or reducing stress."
|
41 |
+
|
42 |
+
return f"Your Happiness Score: {happiness_score}/100. {message}"
|
43 |
|
44 |
@tool
|
45 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
65 |
model = HfApiModel(
|
66 |
max_tokens=2096,
|
67 |
temperature=0.5,
|
68 |
+
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud/',# it is possible that this model may be overloaded
|
69 |
custom_role_conversions=None,
|
70 |
)
|
71 |
|
|
|
78 |
|
79 |
agent = CodeAgent(
|
80 |
model=model,
|
81 |
+
tools=[final_answer, get_current_time_in_timezone, calculate_happiness], ## add your tools here (don't remove final answer)
|
82 |
max_steps=6,
|
83 |
verbosity_level=1,
|
84 |
grammar=None,
|
85 |
planning_interval=None,
|
86 |
+
name="Happiness Score Calculator",
|
87 |
+
description="Creative calculation function that simulates a \"Happiness Score\" based on various life factors.",
|
88 |
prompt_templates=prompt_templates
|
89 |
)
|
90 |
|