Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,18 +5,49 @@ import pytz
|
|
| 5 |
import yaml
|
| 6 |
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
|
| 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:
|
|
@@ -55,7 +86,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
| 8 |
+
from transformers import pipelines
|
| 9 |
+
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
@tool
|
| 14 |
+
def get_random_fact()-> str: #it's import to specify the return type
|
| 15 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 16 |
+
|
| 17 |
+
url="https://uselessfacts.jsph.pl/random.json?language=en"
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
response=requests.get(url)
|
| 21 |
+
response.raise_for_status()
|
| 22 |
+
|
| 23 |
+
data=response.json()
|
| 24 |
+
title=data["title"]
|
| 25 |
+
extract=data["extract"]
|
| 26 |
+
|
| 27 |
+
return f"Summary for {title}:{extract}"
|
| 28 |
+
|
| 29 |
+
except requests.exceptions.RequestException as e:
|
| 30 |
+
return f"Error fetching Wikipedia data: {str(e)}"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
"""A tool that does nothing yet
|
| 34 |
Args:
|
| 35 |
arg1: the first argument
|
| 36 |
arg2: the second argument
|
| 37 |
"""
|
| 38 |
+
#return "What magic will you build ?"
|
| 39 |
+
@tool
|
| 40 |
+
def translation(text,target_language)->str:
|
| 41 |
+
try:
|
| 42 |
+
translator=pipeline("translation",model="facebook/m2m100_418M")
|
| 43 |
+
translation=translator(text,src_lang="en",target_lang="target_language")[0]['translation_text']
|
| 44 |
+
|
| 45 |
+
except Exception as e:
|
| 46 |
+
print(f"Error:{e}")
|
| 47 |
+
return "Translation failed."
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
|
| 52 |
@tool
|
| 53 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 86 |
|
| 87 |
agent = CodeAgent(
|
| 88 |
model=model,
|
| 89 |
+
tools=[get_random_fact,translation,get_current_time_in_timezone,final_answer], ## add your tools here (don't remove final answer)
|
| 90 |
max_steps=6,
|
| 91 |
verbosity_level=1,
|
| 92 |
grammar=None,
|