Spaces:
Runtime error
Runtime error
Update app.py
Browse filesadedd currency converter, website avaibility, text summarizer.
app.py
CHANGED
|
@@ -4,6 +4,11 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
@@ -18,6 +23,38 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 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.
|
|
@@ -49,6 +86,8 @@ custom_role_conversions=None,
|
|
| 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)
|
|
@@ -62,7 +101,14 @@ agent = CodeAgent(
|
|
| 62 |
planning_interval=None,
|
| 63 |
name=None,
|
| 64 |
description=None,
|
| 65 |
-
prompt_templates=prompt_templates
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
)
|
| 67 |
|
| 68 |
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from smolagents.tools import (
|
| 8 |
+
WebScrapingTool,
|
| 9 |
+
CalculatorTool,
|
| 10 |
+
FileReadTool
|
| 11 |
+
)
|
| 12 |
|
| 13 |
from Gradio_UI import GradioUI
|
| 14 |
|
|
|
|
| 23 |
"""
|
| 24 |
return "What magic will you build ?"
|
| 25 |
|
| 26 |
+
@tool
|
| 27 |
+
def currency_converter(amount:float, from_currency:str, to_currency:str) -> str:
|
| 28 |
+
"""Convert between currencies using real-time exchange rates"""
|
| 29 |
+
try:
|
| 30 |
+
url = f"https://api.exchangerate-api.com/v4/latest/{from_currency}"
|
| 31 |
+
response = requests.get(url)
|
| 32 |
+
rates = response.json()["rates"]
|
| 33 |
+
converted = amount * rates[to_currency]
|
| 34 |
+
return f"Convertion of {amount} {from_currency} = {converted:.2f} {to_currency}"
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Error converting {amount} {from_currency} to {to_currency}}"
|
| 37 |
+
|
| 38 |
+
@tool
|
| 39 |
+
def website_availability(url: str) -> str:
|
| 40 |
+
"""Check if a website is online and responsive"""
|
| 41 |
+
try:
|
| 42 |
+
response = requests.get(url, timeout=5)
|
| 43 |
+
return f"Website {url} is online (Status: {response.status_code})"
|
| 44 |
+
except requests.exceptions.RequestException:
|
| 45 |
+
return f"Website {url} is unreachable"
|
| 46 |
+
|
| 47 |
+
@tool
|
| 48 |
+
def text_summarizer(long_text: str) -> str:
|
| 49 |
+
"""Summarize long text documents (dummy implementation - replace with AI summarization)"""
|
| 50 |
+
try:
|
| 51 |
+
# For production: Integrate with Hugging Face summarization pipeline
|
| 52 |
+
sentences = long_text.split('.')
|
| 53 |
+
return '. '.join(sentences[:3]) + '...' # Simple first-3-sentences summary
|
| 54 |
+
except Exception as e:
|
| 55 |
+
return f"Error summarizing {sentences}"
|
| 56 |
+
|
| 57 |
+
|
| 58 |
@tool
|
| 59 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 60 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 86 |
|
| 87 |
# Import tool from Hub
|
| 88 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 89 |
+
weather_tool = load_tool("agents-course/weather-api", trust_remote_code=True)
|
| 90 |
+
wiki_tool = load_tool("agents-course/wiki-search", trust_remote_code=True)
|
| 91 |
|
| 92 |
with open("prompts.yaml", 'r') as stream:
|
| 93 |
prompt_templates = yaml.safe_load(stream)
|
|
|
|
| 101 |
planning_interval=None,
|
| 102 |
name=None,
|
| 103 |
description=None,
|
| 104 |
+
prompt_templates=prompt_templates,
|
| 105 |
+
image_generation_tool,
|
| 106 |
+
weather_tool,
|
| 107 |
+
wiki_tool,
|
| 108 |
+
get_current_time_in_timezone,
|
| 109 |
+
currency_converter,
|
| 110 |
+
website_availability,
|
| 111 |
+
text_summarizer
|
| 112 |
)
|
| 113 |
|
| 114 |
|