yaraa11 commited on
Commit
4f5daf5
·
verified ·
1 Parent(s): 7f61a62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -7
app.py CHANGED
@@ -7,16 +7,36 @@ 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:
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ import requests
11
+
12
  @tool
13
+ def convert_currency(amount: float, from_currency: str, to_currency: str) -> str:
14
+ """A tool that converts one currency to another based on real-time exchange rates.
 
15
  Args:
16
+ amount: The amount of money to convert.
17
+ from_currency: The currency code of the input currency (e.g., 'USD').
18
+ to_currency: The currency code of the target currency (e.g., 'EUR').
19
+ Returns:
20
+ A string indicating the converted amount.
21
  """
22
+ try:
23
+ # Fetch real-time exchange rates from a free API
24
+ url = f"https://api.exchangerate-api.com/v4/latest/{from_currency}"
25
+ response = requests.get(url).json()
26
+
27
+ if 'error' in response:
28
+ return f"Error fetching exchange rates for {from_currency}."
29
+
30
+ exchange_rate = response['rates'].get(to_currency)
31
+ if exchange_rate:
32
+ converted_amount = amount * exchange_rate
33
+ return f"{amount} {from_currency} = {converted_amount:.2f} {to_currency}"
34
+ else:
35
+ return f"Currency conversion from {from_currency} to {to_currency} not supported."
36
+
37
+ except Exception as e:
38
+ return f"Error converting currency: {str(e)}"
39
+
40
 
41
  @tool
42
  def get_current_time_in_timezone(timezone: str) -> str: