Image generator
Browse files
app.py
CHANGED
|
@@ -4,52 +4,25 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
from Gradio_UI import GradioUI
|
| 8 |
-
|
| 9 |
-
# API Endpoint
|
| 10 |
-
CURRENCY_API_URL = "https://api.exchangerate-api.com/v4/latest/"
|
| 11 |
-
|
| 12 |
-
@tool
|
| 13 |
-
def get_current_time_in_timezone(timezone: str) -> str:
|
| 14 |
-
"""Fetches the current local time in a specified timezone."""
|
| 15 |
-
try:
|
| 16 |
-
tz = pytz.timezone(timezone)
|
| 17 |
-
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 18 |
-
return f"The current local time in {timezone} is: {local_time}"
|
| 19 |
-
except Exception as e:
|
| 20 |
-
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 21 |
-
|
| 22 |
-
@tool
|
| 23 |
-
def convert_currency(amount: float, from_currency: str, to_currency: str) -> str:
|
| 24 |
-
"""Converts an amount from one currency to another using real-time exchange rates."""
|
| 25 |
-
try:
|
| 26 |
-
response = requests.get(f"{CURRENCY_API_URL}{from_currency}")
|
| 27 |
-
|
| 28 |
-
# Handle API failure
|
| 29 |
-
if response.status_code != 200:
|
| 30 |
-
return f"Error fetching exchange rates: {response.status_code}"
|
| 31 |
-
|
| 32 |
-
data = response.json()
|
| 33 |
|
| 34 |
-
|
| 35 |
-
return f"Invalid currency code: {from_currency} or {to_currency}."
|
| 36 |
-
|
| 37 |
-
rate = data["rates"][to_currency]
|
| 38 |
-
converted_amount = round(amount * rate, 2)
|
| 39 |
-
|
| 40 |
-
return f"{amount} {from_currency} is equal to {converted_amount} {to_currency} at the rate of {rate}."
|
| 41 |
-
|
| 42 |
-
except Exception as e:
|
| 43 |
-
return f"Error: {str(e)}"
|
| 44 |
|
| 45 |
-
|
| 46 |
|
|
|
|
|
|
|
|
|
|
| 47 |
agent = CodeAgent(
|
| 48 |
-
model=
|
| 49 |
-
tools=[final_answer,
|
| 50 |
-
max_steps=
|
| 51 |
verbosity_level=1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
)
|
| 53 |
|
| 54 |
-
|
| 55 |
-
GradioUI(agent).launch()
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
from Gradio_UI import GradioUI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 11 |
|
| 12 |
+
with open("prompts.yaml", 'r') as stream:
|
| 13 |
+
prompt_templates = yaml.safe_load(stream)
|
| 14 |
+
|
| 15 |
agent = CodeAgent(
|
| 16 |
+
model=model,
|
| 17 |
+
tools=[final_answer], # add your tools here (don't remove final_answer)
|
| 18 |
+
max_steps=6,
|
| 19 |
verbosity_level=1,
|
| 20 |
+
grammar=None,
|
| 21 |
+
planning_interval=None,
|
| 22 |
+
name=None,
|
| 23 |
+
description=None,
|
| 24 |
+
prompt_templates=prompt_templates
|
| 25 |
)
|
| 26 |
|
| 27 |
+
|
| 28 |
+
GradioUI(agent).launch()
|