oddadmix commited on
Commit
4610d7d
·
verified ·
1 Parent(s): 8ec5566

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -1,19 +1,27 @@
1
  import spaces
2
  from transformers import AutoModelForSeq2SeqLM,AutoTokenizer, pipeline
3
  import gradio as grad
4
- mdl_name = "oddadmix/bi-msa-egyptian-translator-masrawy"
5
  pipe = pipeline("translation", model=mdl_name, device = 'cuda')
6
 
7
  @spaces.GPU
8
- def translate(text):
9
  # inputs = my_tkn(text, return_tensors="pt")
10
  # trans_output = mdl.generate(**inputs)
11
-
12
- response = pipe(text)[0]['translation_text']
 
 
 
13
 
14
  #response = opus_translator(text)
15
  return response
16
 
17
- input_textbox = grad.Textbox(lines=5, placeholder="Enter Modern Standard Arabic text to translate", label="Input Text")
18
- output_textbox = grad.Textbox(lines=5, label="Egyptian Arabic Translation")
19
- grad.Interface(translate, inputs=[input_textbox], outputs=output_textbox).launch()
 
 
 
 
 
 
1
  import spaces
2
  from transformers import AutoModelForSeq2SeqLM,AutoTokenizer, pipeline
3
  import gradio as grad
4
+ mdl_name = "oddadmix/Masrawy-BiLingual-v1"
5
  pipe = pipeline("translation", model=mdl_name, device = 'cuda')
6
 
7
  @spaces.GPU
8
+ def translate(text, direction):
9
  # inputs = my_tkn(text, return_tensors="pt")
10
  # trans_output = mdl.generate(**inputs)
11
+ if direction == "MSA → Egyptian":
12
+ prompt = text + " <msa_to_egy>"
13
+ else:
14
+ prompt = text + " <egy_to_msa>"
15
+ response = pipe(prompt)[0]['translation_text']
16
 
17
  #response = opus_translator(text)
18
  return response
19
 
20
+ input_textbox = grad.Textbox(lines=5, placeholder="اكتب النص هنا بالعربية الفصحى أو باللهجة المصرية...", label="Input Text")
21
+ output_textbox = grad.Textbox(lines=5, label="النص المترجم")
22
+ grad.Interface(translate, inputs=[input_textbox, grad.Radio(
23
+ choices=["MSA → Egyptian", "Egyptian → MSA"],
24
+ value="MSA → Egyptian",
25
+ label="اتجاه الترجمة"
26
+ )], outputs=output_textbox, title="Masrawy: MSA ↔ Egyptian Translator",
27
+ description="اختر اتجاه الترجمة وأدخل النص بالعربية الفصحى أو باللهجة المصرية.").launch()