ilyass31 commited on
Commit
fe66ab6
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -43
app.py CHANGED
@@ -1,69 +1,88 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  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
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
20
 
 
21
  @tool
22
- def get_current_time_in_timezone(timezone: str) -> str:
23
- """A tool that fetches the current local time in a specified timezone.
24
  Args:
25
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
26
  """
27
- try:
28
- # Create timezone object
29
- tz = pytz.timezone(timezone)
30
- # Get current time in that timezone
31
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
- return f"The current local time in {timezone} is: {local_time}"
33
- except Exception as e:
34
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
 
 
 
 
 
 
 
 
 
 
36
 
37
- final_answer = FinalAnswerTool()
38
-
39
- # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
40
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
 
 
42
  model = HfApiModel(
43
- max_tokens=2096,
44
- temperature=0.5,
45
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
46
- custom_role_conversions=None,
47
  )
48
 
49
-
50
- # Import tool from Hub
51
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
52
-
53
- with open("prompts.yaml", 'r') as stream:
54
- prompt_templates = yaml.safe_load(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=None,
64
- description=None,
65
- prompt_templates=prompt_templates
66
  )
67
 
68
-
69
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
  from Gradio_UI import GradioUI
8
 
9
+ # Fetch METAR/TAF aviation weather data
10
  @tool
11
+ def get_aviation_weather(icao_code: str) -> str:
12
+ """Fetches the METAR and TAF weather reports for a given airport ICAO code.
 
13
  Args:
14
+ icao_code: The ICAO airport code (e.g., 'JFK' for John F. Kennedy International).
 
15
  """
16
+ try:
17
+ url = f"https://aviationweather.gov/metar/data?ids={icao_code}&format=raw&taf=on"
18
+ response = requests.get(url)
19
+ if response.status_code == 200:
20
+ return response.text
21
+ else:
22
+ return f"Error fetching aviation weather for {icao_code}"
23
+ except Exception as e:
24
+ return f"Failed to retrieve data: {str(e)}"
25
 
26
+ # Flight time estimation tool
27
  @tool
28
+ def estimate_flight_time(distance_nm: float, speed_kts: float) -> str:
29
+ """Estimates flight time based on distance (nautical miles) and speed (knots).
30
  Args:
31
+ distance_nm: Distance in nautical miles.
32
+ speed_kts: Speed in knots.
33
  """
34
+ if speed_kts <= 0:
35
+ return "Invalid speed. Must be greater than zero."
36
+ time_hours = distance_nm / speed_kts
37
+ return f"Estimated flight time: {time_hours:.2f} hours."
 
 
 
 
38
 
39
+ # Fuel consumption estimator
40
+ @tool
41
+ def estimate_fuel_burn(rate_gph: float, time_hours: float) -> str:
42
+ """Estimates total fuel consumption for a flight.
43
+ Args:
44
+ rate_gph: Fuel burn rate in gallons per hour.
45
+ time_hours: Estimated flight duration in hours.
46
+ """
47
+ fuel_needed = rate_gph * time_hours
48
+ return f"Estimated fuel needed: {fuel_needed:.2f} gallons."
49
 
50
+ # Current time in major aviation hubs
51
+ @tool
52
+ def get_airport_local_time(icao_code: str) -> str:
53
+ """Gets the local time of an airport using its ICAO code.
54
+ Args:
55
+ icao_code: ICAO airport code (e.g., 'LHR' for London Heathrow).
56
+ """
57
+ airport_timezones = {
58
+ "JFK": "America/New_York",
59
+ "LAX": "America/Los_Angeles",
60
+ "LHR": "Europe/London",
61
+ "DXB": "Asia/Dubai",
62
+ "HND": "Asia/Tokyo"
63
+ }
64
+ if icao_code not in airport_timezones:
65
+ return "Airport timezone not available."
66
+
67
+ tz = pytz.timezone(airport_timezones[icao_code])
68
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
69
+ return f"Local time at {icao_code}: {local_time}"
70
 
71
+ # Finalizing agent setup
72
+ final_answer = FinalAnswerTool()
73
  model = HfApiModel(
74
+ max_tokens=2096,
75
+ temperature=0.5,
76
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
 
77
  )
78
 
 
 
 
 
 
 
 
79
  agent = CodeAgent(
80
  model=model,
81
+ tools=[final_answer, get_aviation_weather, estimate_flight_time, estimate_fuel_burn, get_airport_local_time],
82
  max_steps=6,
83
  verbosity_level=1,
84
+ name="AeroNavBot",
85
+ description="An AI assistant for aviation navigation, weather, and flight planning.",
 
 
 
86
  )
87
 
88
+ GradioUI(agent).launch()