Spaces:
Sleeping
Sleeping
peterbonnesoeur
commited on
Commit
·
fae2fcb
1
Parent(s):
cbb18dd
new test
Browse files
tool.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
-
import asyncio
|
2 |
from smolagents import Tool
|
3 |
-
|
4 |
from typing import Optional
|
5 |
|
6 |
|
@@ -28,11 +27,13 @@ class TranslateTool(Tool):
|
|
28 |
output_type = "string"
|
29 |
|
30 |
async def translate_text(text: str, src: str, dest: str):
|
|
|
31 |
async with Translator() as translator:
|
32 |
res = await translator.translate(text, src, dest)
|
33 |
return res
|
34 |
|
35 |
def forward(self, text: str, source_language: str, target_language: str):
|
|
|
36 |
try:
|
37 |
translator = Translator()
|
38 |
translation = asyncio.run(translator.translate(text, src=source_language, dest=target_language))
|
|
|
|
|
1 |
from smolagents import Tool
|
2 |
+
|
3 |
from typing import Optional
|
4 |
|
5 |
|
|
|
27 |
output_type = "string"
|
28 |
|
29 |
async def translate_text(text: str, src: str, dest: str):
|
30 |
+
from googletrans import Translator
|
31 |
async with Translator() as translator:
|
32 |
res = await translator.translate(text, src, dest)
|
33 |
return res
|
34 |
|
35 |
def forward(self, text: str, source_language: str, target_language: str):
|
36 |
+
import asyncio
|
37 |
try:
|
38 |
translator = Translator()
|
39 |
translation = asyncio.run(translator.translate(text, src=source_language, dest=target_language))
|