Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,11 +6,12 @@ import yaml
|
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
import os
|
8 |
from Gradio_UI import GradioUI
|
|
|
9 |
import requests
|
|
|
10 |
|
11 |
API_KEY = os.getenv("KEY")
|
12 |
|
13 |
-
|
14 |
@tool
|
15 |
def get_currency_rate(currency_pair: str) -> str:
|
16 |
"""Fetches the current exchange rate for a given currency pair (e.g., 'USD-EUR').
|
@@ -18,15 +19,12 @@ def get_currency_rate(currency_pair: str) -> str:
|
|
18 |
currency_pair: The currency pair to query, formatted as 'BASE-CURRENCY'.
|
19 |
"""
|
20 |
try:
|
21 |
-
# Use a free API like exchangerate-api.com
|
22 |
base, target = currency_pair.split("-")
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
else:
|
29 |
-
return f"Invalid currency pair: {currency_pair}"
|
30 |
except Exception as e:
|
31 |
return f"Error fetching rate: {str(e)}"
|
32 |
@tool
|
@@ -61,4 +59,27 @@ agent = CodeAgent(
|
|
61 |
verbosity_level=1
|
62 |
)
|
63 |
|
64 |
-
GradioUI(agent).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
import os
|
8 |
from Gradio_UI import GradioUI
|
9 |
+
import gradio as gr
|
10 |
import requests
|
11 |
+
import yfinance as yf
|
12 |
|
13 |
API_KEY = os.getenv("KEY")
|
14 |
|
|
|
15 |
@tool
|
16 |
def get_currency_rate(currency_pair: str) -> str:
|
17 |
"""Fetches the current exchange rate for a given currency pair (e.g., 'USD-EUR').
|
|
|
19 |
currency_pair: The currency pair to query, formatted as 'BASE-CURRENCY'.
|
20 |
"""
|
21 |
try:
|
|
|
22 |
base, target = currency_pair.split("-")
|
23 |
+
# Use yfinance to get the exchange rate
|
24 |
+
ticker = f"{base}{target}=X" # Format for yfinance (e.g., "USDEUR=X")
|
25 |
+
data = yf.Ticker(ticker)
|
26 |
+
rate = data.history(period="1d")["Close"].iloc[-1]
|
27 |
+
return f"Current {currency_pair} rate: {rate}"
|
|
|
|
|
28 |
except Exception as e:
|
29 |
return f"Error fetching rate: {str(e)}"
|
30 |
@tool
|
|
|
59 |
verbosity_level=1
|
60 |
)
|
61 |
|
62 |
+
#GradioUI(agent).launch()
|
63 |
+
|
64 |
+
# Add a Markdown section for example usage
|
65 |
+
examples = """
|
66 |
+
### Example Usage
|
67 |
+
1. **Currency Rate**: Ask for the exchange rate of a currency pair.
|
68 |
+
- Example: "What is the current exchange rate for USD to JPY?"
|
69 |
+
- Example: "Get the EUR to GBP rate."
|
70 |
+
|
71 |
+
2. **Current Time**: Ask for the current time in a specific timezone.
|
72 |
+
- Example: "What is the current time in America/New_York?"
|
73 |
+
- Example: "Get the time in Asia/Tokyo."
|
74 |
+
"""
|
75 |
+
|
76 |
+
# Modify the Gradio UI to include the examples
|
77 |
+
def launch_with_examples(agent):
|
78 |
+
with gr.Blocks() as demo:
|
79 |
+
gr.Markdown("# Currency Agent")
|
80 |
+
gr.Markdown(examples)
|
81 |
+
GradioUI(agent).render()
|
82 |
+
demo.launch()
|
83 |
+
|
84 |
+
# Launch the app
|
85 |
+
launch_with_examples(agent)
|