Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,22 @@ import datetime
|
|
| 4 |
import pytz
|
| 5 |
import math
|
| 6 |
import os
|
|
|
|
| 7 |
|
| 8 |
# ============ TOOLS ============
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
@tool
|
| 11 |
def web_search_tool(query: str) -> str:
|
|
@@ -116,9 +130,9 @@ model = InferenceClientModel(
|
|
| 116 |
|
| 117 |
agent = CodeAgent(
|
| 118 |
model=model,
|
| 119 |
-
tools=[web_search_tool, time_tool, calculator_tool],
|
| 120 |
max_steps=5,
|
| 121 |
-
additional_authorized_imports=['math', 'datetime', 'pytz']
|
| 122 |
)
|
| 123 |
|
| 124 |
# ============ GRADIO UI ============
|
|
@@ -141,6 +155,7 @@ demo = gr.ChatInterface(
|
|
| 141 |
"What time is it in Tokyo?",
|
| 142 |
"Convert 150 pounds to kg",
|
| 143 |
"Calculate the square root of 144 plus 50",
|
|
|
|
| 144 |
"Search for the latest news on AI agents"
|
| 145 |
],
|
| 146 |
)
|
|
|
|
| 4 |
import pytz
|
| 5 |
import math
|
| 6 |
import os
|
| 7 |
+
from deep_translator import GoogleTranslator
|
| 8 |
|
| 9 |
# ============ TOOLS ============
|
| 10 |
+
@tool
|
| 11 |
+
def translator_tool(text: str, target_language: str) -> str:
|
| 12 |
+
"""Translates text into a specified language.
|
| 13 |
+
Args:
|
| 14 |
+
text: The text or phrase to translate.
|
| 15 |
+
target_language: The destination language (e.g., 'french', 'german', 'japanese', 'hindi').
|
| 16 |
+
"""
|
| 17 |
+
try:
|
| 18 |
+
# GoogleTranslator handles full language names or ISO codes
|
| 19 |
+
translation = GoogleTranslator(source='auto', target=target_language).translate(text)
|
| 20 |
+
return f"Translated to {target_language.title()}: {translation}"
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return f"Translation error: {str(e)}. Make sure the language name is correct."
|
| 23 |
|
| 24 |
@tool
|
| 25 |
def web_search_tool(query: str) -> str:
|
|
|
|
| 130 |
|
| 131 |
agent = CodeAgent(
|
| 132 |
model=model,
|
| 133 |
+
tools=[web_search_tool, time_tool, calculator_tool, translator_tool],
|
| 134 |
max_steps=5,
|
| 135 |
+
additional_authorized_imports=['math', 'datetime', 'pytz', 'deep_translator']
|
| 136 |
)
|
| 137 |
|
| 138 |
# ============ GRADIO UI ============
|
|
|
|
| 155 |
"What time is it in Tokyo?",
|
| 156 |
"Convert 150 pounds to kg",
|
| 157 |
"Calculate the square root of 144 plus 50",
|
| 158 |
+
"Translate 'Hello, how are you today?' into Japanese",
|
| 159 |
"Search for the latest news on AI agents"
|
| 160 |
],
|
| 161 |
)
|