Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,11 +4,14 @@ import torch
|
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
# Initialize the translation pipeline
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Define the custom glossary
|
| 14 |
custom_glossary = {
|
|
@@ -151,3 +154,4 @@ iface = gr.Interface(
|
|
| 151 |
# Launch the interface
|
| 152 |
if __name__ == "__main__":
|
| 153 |
iface.launch()
|
|
|
|
|
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
# Initialize the translation pipeline
|
| 7 |
+
def initialize_translator():
|
| 8 |
+
try:
|
| 9 |
+
device = 0 if torch.cuda.is_available() else -1 # Use GPU if available, otherwise CPU
|
| 10 |
+
return pipeline("translation", model="Helsinki-NLP/opus-mt-tc-big-en-es", device=device)
|
| 11 |
+
except Exception as e:
|
| 12 |
+
raise RuntimeError(f"Failed to initialize translation pipeline: {e}")
|
| 13 |
+
|
| 14 |
+
translator = initialize_translator()
|
| 15 |
|
| 16 |
# Define the custom glossary
|
| 17 |
custom_glossary = {
|
|
|
|
| 154 |
# Launch the interface
|
| 155 |
if __name__ == "__main__":
|
| 156 |
iface.launch()
|
| 157 |
+
|