petfol commited on
Commit
60c1cd6
·
verified ·
1 Parent(s): 543ca4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -1
app.py CHANGED
@@ -3,9 +3,63 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
 
 
6
  from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # Tool to suggest a menu based on the occasion
11
  @tool
@@ -75,7 +129,7 @@ with open("prompts.yaml", 'r') as stream:
75
 
76
  agent = CodeAgent(
77
  model=model,
78
- tools=[final_answer, suggest_menu], ## add your tools here (don't remove final answer)
79
  max_steps=6,
80
  verbosity_level=1,
81
  grammar=None,
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ import math
7
+ from typing import Optional, Tuple
8
  from tools.final_answer import FinalAnswerTool
9
 
10
  from Gradio_UI import GradioUI
11
+ @tool
12
+ def calculate_cargo_travel_time(
13
+ origin_coords: Tuple[float, float],
14
+ destination_coords: Tuple[float, float],
15
+ cruising_speed_kmh: Optional[float] = 750.0, # Average speed for cargo planes
16
+ ) -> float:
17
+ """
18
+ Calculate the travel time for a cargo plane between two points on Earth using great-circle distance.
19
+
20
+ Args:
21
+ origin_coords: Tuple of (latitude, longitude) for the starting point
22
+ destination_coords: Tuple of (latitude, longitude) for the destination
23
+ cruising_speed_kmh: Optional cruising speed in km/h (defaults to 750 km/h for typical cargo planes)
24
+
25
+ Returns:
26
+ float: The estimated travel time in hours
27
+
28
+ Example:
29
+ >>> # Chicago (41.8781° N, 87.6298° W) to Sydney (33.8688° S, 151.2093° E)
30
+ >>> result = calculate_cargo_travel_time((41.8781, -87.6298), (-33.8688, 151.2093))
31
+ """
32
+
33
+ def to_radians(degrees: float) -> float:
34
+ return degrees * (math.pi / 180)
35
+
36
+ # Extract coordinates
37
+ lat1, lon1 = map(to_radians, origin_coords)
38
+ lat2, lon2 = map(to_radians, destination_coords)
39
+
40
+ # Earth's radius in kilometers
41
+ EARTH_RADIUS_KM = 6371.0
42
+
43
+ # Calculate great-circle distance using the haversine formula
44
+ dlon = lon2 - lon1
45
+ dlat = lat2 - lat1
46
+
47
+ a = (
48
+ math.sin(dlat / 2) ** 2
49
+ + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2) ** 2
50
+ )
51
+ c = 2 * math.asin(math.sqrt(a))
52
+ distance = EARTH_RADIUS_KM * c
53
+
54
+ # Add 10% to account for non-direct routes and air traffic controls
55
+ actual_distance = distance * 1.1
56
+
57
+ # Calculate flight time
58
+ # Add 1 hour for takeoff and landing procedures
59
+ flight_time = (actual_distance / cruising_speed_kmh) + 1.0
60
+
61
+ # Format the results
62
+ return round(flight_time, 2)
63
 
64
  # Tool to suggest a menu based on the occasion
65
  @tool
 
129
 
130
  agent = CodeAgent(
131
  model=model,
132
+ tools=[final_answer, GoogleSearchTool("serper"), VisitWebpageTool(), calculate_cargo_travel_time], ## add your tools here (don't remove final answer)
133
  max_steps=6,
134
  verbosity_level=1,
135
  grammar=None,