deniyoz commited on
Commit
0440146
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -9,14 +9,35 @@ 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:
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def convert_currency(amount: float, from_currency: str, to_currency: str) -> str:
13
+ """
14
+ Converts an amount from one currency to another using a static exchange rate list.
15
+
16
  Args:
17
+ amount: The amount of money to convert.
18
+ from_currency: The currency code of the original amount.
19
+ to_currency: The currency code to convert to.
20
+
21
+ Returns:
22
+ A string representing the converted amount or an error message if the currency is invalid.
23
  """
24
+ exchange_rates = {
25
+ "USD": 1.0,
26
+ "EUR": 0.92,
27
+ "GBP": 0.78,
28
+ "TRY": 32.0
29
+ }
30
+
31
+ try:
32
+ if from_currency not in exchange_rates or to_currency not in exchange_rates:
33
+ return f"Error: Invalid currency '{from_currency}' or '{to_currency}'"
34
+
35
+ # Convert to USD first, then to target currency
36
+ amount_in_usd = amount / exchange_rates[from_currency]
37
+ converted_amount = amount_in_usd * exchange_rates[to_currency]
38
+ return f"{amount} {from_currency} = {round(converted_amount, 2)} {to_currency}"
39
+ except Exception as e:
40
+ return f"Error converting currency: {str(e)}"
41
 
42
  @tool
43
  def get_current_time_in_timezone(timezone: str) -> str: