Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,21 @@ 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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
@@ -55,7 +70,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,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
# Translation tool
|
| 11 |
+
@tool
|
| 12 |
+
def translate_text(sentence: str, target_language: str) -> str:
|
| 13 |
+
"""A tool that translates a given sentence into the specified target language.
|
| 14 |
+
Args:
|
| 15 |
+
sentence: The sentence to translate.
|
| 16 |
+
target_language: The language to translate the sentence into (e.g., 'fr' for French, 'es' for Spanish).
|
| 17 |
+
"""
|
| 18 |
+
try:
|
| 19 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-{target_language}")
|
| 20 |
+
translation = translator(sentence)[0]['translation_text']
|
| 21 |
+
return f"Translated text ({target_language}): {translation}"
|
| 22 |
+
except Exception as e:
|
| 23 |
+
return f"Error in translation: {str(e)}"
|
| 24 |
+
|
| 25 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 26 |
@tool
|
| 27 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 70 |
|
| 71 |
agent = CodeAgent(
|
| 72 |
model=model,
|
| 73 |
+
tools=[final_answer, translate_text], ## add your tools here (don't remove final answer)
|
| 74 |
max_steps=6,
|
| 75 |
verbosity_level=1,
|
| 76 |
grammar=None,
|