rupeshs commited on
Commit
5a96d7e
·
1 Parent(s): fe4a180

Added moon phase

Browse files
Files changed (2) hide show
  1. app.py +44 -10
  2. requirements.txt +1 -0
app.py CHANGED
@@ -4,22 +4,55 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
 
8
  from Gradio_UI import GradioUI
9
 
10
 
11
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
- def my_cutom_tool(
14
- arg1: str, arg2: int
15
- ) -> str: # it's import to specify the return type
16
- # Keep this format for the description / args / args description but feel free to modify the tool
17
- """A tool that does nothing yet
18
  Args:
19
- arg1: the first argument
20
- arg2: the second argument
 
 
21
  """
22
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
 
25
  @tool
@@ -57,6 +90,7 @@ agent = CodeAgent(
57
  model=model,
58
  tools=[
59
  final_answer,
 
60
  get_current_time_in_timezone,
61
  ],
62
  max_steps=6,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ import datetime
8
+ import ephem
9
  from Gradio_UI import GradioUI
10
 
11
 
 
12
  @tool
13
+ def get_moon_phase(date=None) -> str:
14
+ """
15
+ Calculates and returns the current moon phase.
16
+
 
17
  Args:
18
+ date (datetime.date, optional): The date for which to calculate the moon phase. Defaults to today.
19
+
20
+ Returns:
21
+ str: A string describing the moon phase.
22
  """
23
+
24
+ if date is None:
25
+ date = datetime.date.today()
26
+
27
+ observer = ephem.Observer()
28
+ observer.lat = "0"
29
+ observer.lon = "0"
30
+ observer.elevation = 0
31
+ observer.date = date
32
+
33
+ moon = ephem.Moon(observer)
34
+ phase = moon.phase
35
+
36
+ if 0 <= phase < 12.5:
37
+ phase_name = "New Moon"
38
+ elif 12.5 <= phase < 25:
39
+ phase_name = "Waxing Crescent"
40
+ elif 25 <= phase < 37.5:
41
+ phase_name = "First Quarter"
42
+ elif 37.5 <= phase < 50:
43
+ phase_name = "Waxing Gibbous"
44
+ elif 50 <= phase < 62.5:
45
+ phase_name = "Full Moon"
46
+ elif 62.5 <= phase < 75:
47
+ phase_name = "Waning Gibbous"
48
+ elif 75 <= phase < 87.5:
49
+ phase_name = "Third Quarter"
50
+ elif 87.5 <= phase <= 100:
51
+ phase_name = "Waning Crescent"
52
+ else:
53
+ phase_name = "Unknown"
54
+
55
+ return f"{phase_name} ({phase:.2f}%) on {date}"
56
 
57
 
58
  @tool
 
90
  model=model,
91
  tools=[
92
  final_answer,
93
+ get_moon_phase,
94
  get_current_time_in_timezone,
95
  ],
96
  max_steps=6,
requirements.txt CHANGED
@@ -3,3 +3,4 @@ smolagents
3
  requests
4
  duckduckgo_search
5
  pandas
 
 
3
  requests
4
  duckduckgo_search
5
  pandas
6
+ ephem