lukecurtin32 commited on
Commit
5f80acb
1 Parent(s): 0f25099

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -4,11 +4,14 @@ import torch
4
  from transformers import pipeline
5
 
6
  # Initialize the translation pipeline
7
- translator = pipeline(
8
- "translation",
9
- model="Helsinki-NLP/opus-mt-tc-big-en-es",
10
- device=0 if torch.cuda.is_available() else -1, # Use GPU if available, otherwise CPU
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
+