Mgolo commited on
Commit
3e4c2e2
·
verified ·
1 Parent(s): e665d05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -24,10 +24,10 @@ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
24
  translator = None
25
  whisper_model = None
26
 
27
- def load_wolof_model():
28
  global translator
29
  if translator is None:
30
- model_name = "LocaleNLP/eng_wolof"
31
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name).to(device)
32
  tokenizer = MarianTokenizer.from_pretrained(model_name)
33
  translator = pipeline("translation", model=model, tokenizer=tokenizer, device=0 if device.type == 'cuda' else -1)
@@ -91,7 +91,7 @@ def extract_text_from_file(uploaded_file):
91
  raise ValueError("Unsupported file type")
92
 
93
  def translate(text):
94
- translator = load_wolof_model()
95
  lang_tag = ">>wol<<"
96
 
97
  paragraphs = text.split("\n")
@@ -137,7 +137,7 @@ def translate_and_return(text):
137
  # Gradio UI components
138
  with gr.Blocks() as demo:
139
  gr.Markdown("## LocaleNLP English-to-Wolof Translator")
140
- gr.Markdown("Upload English text, audio, or document to translate to Wolof using Localenlp Model.")
141
 
142
  with gr.Row():
143
  input_mode = gr.Radio(choices=["Text", "Audio", "File"], label="Select input mode", value="Text")
 
24
  translator = None
25
  whisper_model = None
26
 
27
+ def load_darija_model():
28
  global translator
29
  if translator is None:
30
+ model_name = "LocaleNLP/english_wolof"
31
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name).to(device)
32
  tokenizer = MarianTokenizer.from_pretrained(model_name)
33
  translator = pipeline("translation", model=model, tokenizer=tokenizer, device=0 if device.type == 'cuda' else -1)
 
91
  raise ValueError("Unsupported file type")
92
 
93
  def translate(text):
94
+ translator = load_darija_model()
95
  lang_tag = ">>wol<<"
96
 
97
  paragraphs = text.split("\n")
 
137
  # Gradio UI components
138
  with gr.Blocks() as demo:
139
  gr.Markdown("## LocaleNLP English-to-Wolof Translator")
140
+ gr.Markdown("Upload English text, audio, or document to translate to Wolof using Localenlp model.")
141
 
142
  with gr.Row():
143
  input_mode = gr.Radio(choices=["Text", "Audio", "File"], label="Select input mode", value="Text")