Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -20,28 +20,26 @@ def print_results(results):
|
|
20 |
result_string += pprint.pformat(hit, indent=4) + "\n"
|
21 |
return result_string.strip()
|
22 |
|
23 |
-
async def
|
24 |
"""
|
25 |
-
Translate the given text to English
|
26 |
|
27 |
Args:
|
28 |
-
-
|
29 |
|
30 |
Returns:
|
31 |
-
-
|
32 |
"""
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
print(f"Translation failed: {e}")
|
44 |
-
translated_bulk.append(original_text.lower().strip()) # Add placeholder for failed translation
|
45 |
return translated_bulk
|
46 |
|
47 |
async def encode_document(document: str):
|
@@ -103,7 +101,7 @@ async def predict(query):
|
|
103 |
|
104 |
try:
|
105 |
translation_start_time = time.time()
|
106 |
-
representation_list = await
|
107 |
except Exception as e:
|
108 |
representation_list = tasks
|
109 |
print(f"An error occurred while translating: {e}")
|
|
|
20 |
result_string += pprint.pformat(hit, indent=4) + "\n"
|
21 |
return result_string.strip()
|
22 |
|
23 |
+
async def translate_bulk(bulk: list) -> list:
|
24 |
"""
|
25 |
+
Translate the given text to English and return the translated text.
|
26 |
|
27 |
Args:
|
28 |
+
- text (str): The text to translate.
|
29 |
|
30 |
Returns:
|
31 |
+
- str: The translated text.
|
32 |
"""
|
33 |
+
try:
|
34 |
+
translated_bulk = await translator.translate(bulk, dest="en")
|
35 |
+
translated_bulk = [
|
36 |
+
translated_text.text.lower().strip() for translated_text in translated_bulk
|
37 |
+
]
|
38 |
+
except Exception as e:
|
39 |
+
print(f"Bulk Translation failed: {e}")
|
40 |
+
translated_bulk = [
|
41 |
+
text.lower().strip() for text in bulk
|
42 |
+
] # Use original text if translation fails
|
|
|
|
|
43 |
return translated_bulk
|
44 |
|
45 |
async def encode_document(document: str):
|
|
|
101 |
|
102 |
try:
|
103 |
translation_start_time = time.time()
|
104 |
+
representation_list = await translate_bulk(tasks)
|
105 |
except Exception as e:
|
106 |
representation_list = tasks
|
107 |
print(f"An error occurred while translating: {e}")
|