Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -222,6 +222,23 @@ class HuggingFaceImageQATool(Tool):
|
|
222 |
return self.processor.decode(out[0], skip_special_tokens=True)
|
223 |
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
# ===== Code Execution =====
|
226 |
class PythonCodeExecutionTool:
|
227 |
def __init__(self):
|
|
|
222 |
return self.processor.decode(out[0], skip_special_tokens=True)
|
223 |
|
224 |
|
225 |
+
from transformers import pipeline
|
226 |
+
|
227 |
+
class HuggingFaceTranslationTool(Tool):
|
228 |
+
name = "translate"
|
229 |
+
description = "Translate text from English to another language."
|
230 |
+
inputs = {
|
231 |
+
"text": {"type": "string", "description": "Text to translate"}
|
232 |
+
}
|
233 |
+
output_type = "string"
|
234 |
+
|
235 |
+
def __init__(self):
|
236 |
+
self.translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr")
|
237 |
+
|
238 |
+
def forward(self, text: str) -> str:
|
239 |
+
return self.translator(text)[0]["translation_text"]
|
240 |
+
|
241 |
+
|
242 |
# ===== Code Execution =====
|
243 |
class PythonCodeExecutionTool:
|
244 |
def __init__(self):
|