Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,30 +9,35 @@ 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 |
-
|
| 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
|
| 23 |
-
"""A tool that
|
| 24 |
Args:
|
| 25 |
-
|
| 26 |
"""
|
|
|
|
|
|
|
|
|
|
| 27 |
try:
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
-
return f"Error
|
| 35 |
-
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
|
@@ -42,11 +47,10 @@ final_answer = FinalAnswerTool()
|
|
| 42 |
model = HfApiModel(
|
| 43 |
max_tokens=2096,
|
| 44 |
temperature=0.5,
|
| 45 |
-
model_id='
|
| 46 |
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
| 49 |
-
|
| 50 |
# Import tool from Hub
|
| 51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 52 |
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
@tool
|
| 14 |
+
def translate_japanese_to_english(text: str) -> str:
|
| 15 |
+
"""A tool that translates any Japanese text written in Hiragana or Kanji to English.
|
| 16 |
Args:
|
| 17 |
+
text: The Japanese word or sentence to translate.
|
| 18 |
"""
|
| 19 |
+
if not text.strip():
|
| 20 |
+
return "No text provided for translation."
|
| 21 |
+
|
| 22 |
try:
|
| 23 |
+
# Use LibreTranslate's API to perform the translation.
|
| 24 |
+
response = requests.post(
|
| 25 |
+
"https://libretranslate.de/translate",
|
| 26 |
+
data={
|
| 27 |
+
"q": text,
|
| 28 |
+
"source": "ja",
|
| 29 |
+
"target": "en",
|
| 30 |
+
"format": "text"
|
| 31 |
+
},
|
| 32 |
+
timeout=10 # seconds
|
| 33 |
+
)
|
| 34 |
+
response.raise_for_status() # Raise an exception for HTTP errors
|
| 35 |
+
translated_text = response.json().get("translatedText", "")
|
| 36 |
+
if not translated_text:
|
| 37 |
+
return "Translation failed: No translated text received."
|
| 38 |
+
return translated_text
|
| 39 |
except Exception as e:
|
| 40 |
+
return f"Error translating text: {str(e)}"
|
|
|
|
| 41 |
|
| 42 |
final_answer = FinalAnswerTool()
|
| 43 |
|
|
|
|
| 47 |
model = HfApiModel(
|
| 48 |
max_tokens=2096,
|
| 49 |
temperature=0.5,
|
| 50 |
+
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 51 |
custom_role_conversions=None,
|
| 52 |
)
|
| 53 |
|
|
|
|
| 54 |
# Import tool from Hub
|
| 55 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 56 |
|