Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,29 +11,14 @@ transliterator = pipeline(task="translation", model="guymorlan/DialectTransliter
|
|
11 |
|
12 |
speech_config = speechsdk.SpeechConfig(subscription=os.environ.get('SPEECH_KEY'), region=os.environ.get('SPEECH_REGION'))
|
13 |
|
14 |
-
def translate_english(input_text
|
15 |
if not input_text:
|
16 |
return "", "", "", ""
|
17 |
|
18 |
inputs = [f"{val} {input_text}" for val in dialects.values()]
|
19 |
-
|
20 |
-
sy, lb, eg = "Syrian" in include, "Lebanese" in include, "Egyptian" in include
|
21 |
-
# remove 2nd element if sy is false
|
22 |
-
if not eg:
|
23 |
-
inputs.pop()
|
24 |
-
if not lb:
|
25 |
-
inputs.pop()
|
26 |
-
if not sy:
|
27 |
-
inputs.pop()
|
28 |
-
|
29 |
result = translator_en2ar(inputs)
|
30 |
|
31 |
-
|
32 |
-
sy_out = result[1]["translation_text"] if sy else ""
|
33 |
-
lb_out = result[1 + sy]["translation_text"] if lb else ""
|
34 |
-
eg_out = result[1 + sy + lb]["translation_text"] if eg else ""
|
35 |
-
|
36 |
-
return pal_out, sy_out, lb_out, eg_out
|
37 |
|
38 |
def translate_arabic(input_text):
|
39 |
if not input_text:
|
@@ -50,9 +35,10 @@ def get_audio(input_text):
|
|
50 |
speech_synthesis_result = speech_synthesizer.speak_text_async(input_text).get()
|
51 |
return f"{input_text}.wav"
|
52 |
|
53 |
-
def get_transliteration(input_text
|
54 |
-
if
|
55 |
return ""
|
|
|
56 |
result = transliterator([input_text])
|
57 |
return result[0]["translation_text"]
|
58 |
|
@@ -70,10 +56,6 @@ with gr.Blocks(title = "English to Levantine Arabic", css=css, theme="default")
|
|
70 |
input_text = gr.Textbox(label="Input", placeholder="Enter English text", lines=1)
|
71 |
gr.Examples(["I wanted to go to the store yesterday, but it rained", "How are you feeling today?", "Let's go to your place"], input_text)
|
72 |
btn = gr.Button("Translate", label="Translate")
|
73 |
-
with gr.Row():
|
74 |
-
include = gr.CheckboxGroup(["Transliteration", "Syrian", "Lebanese", "Egyptian"],
|
75 |
-
label="Disable features to speed up translation",
|
76 |
-
value=["Transliteration", "Syrian", "Lebanese", "Egyptian"])
|
77 |
gr.Markdown("Built by [Guy Mor-Lan](mailto:[email protected]). Pronunciation model is specifically tailored to urban Palestinian Arabic. Text-to-speech uses Microsoft Azure's API and may provide different result from the transliterated pronunciation.")
|
78 |
|
79 |
with gr.Column():
|
@@ -86,9 +68,9 @@ with gr.Blocks(title = "English to Levantine Arabic", css=css, theme="default")
|
|
86 |
audio = gr.Audio(label="Audio - Palestinian", interactive=False)
|
87 |
audio_button = gr.Button("Get Audio", label="Click Here to Get Audio")
|
88 |
audio_button.click(get_audio, inputs=[pal], outputs=[audio])
|
89 |
-
btn.click(translate_english,inputs=[input_text
|
90 |
-
input_text.submit(translate_english, inputs=[input_text
|
91 |
-
pal.change(get_transliteration, inputs=[pal,
|
92 |
with gr.Tab('From Levantine Arabic to English'):
|
93 |
with gr.Row():
|
94 |
with gr.Column():
|
@@ -111,5 +93,9 @@ with gr.Blocks(title = "English to Levantine Arabic", css=css, theme="default")
|
|
111 |
btn.click(get_transliteration, inputs=input_text, outputs=[translit])
|
112 |
|
113 |
|
|
|
|
|
|
|
114 |
demo.launch()
|
115 |
|
|
|
|
11 |
|
12 |
speech_config = speechsdk.SpeechConfig(subscription=os.environ.get('SPEECH_KEY'), region=os.environ.get('SPEECH_REGION'))
|
13 |
|
14 |
+
def translate_english(input_text):
|
15 |
if not input_text:
|
16 |
return "", "", "", ""
|
17 |
|
18 |
inputs = [f"{val} {input_text}" for val in dialects.values()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
result = translator_en2ar(inputs)
|
20 |
|
21 |
+
return result[0]["translation_text"], result[1]["translation_text"], result[2]["translation_text"], result[3]["translation_text"]
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def translate_arabic(input_text):
|
24 |
if not input_text:
|
|
|
35 |
speech_synthesis_result = speech_synthesizer.speak_text_async(input_text).get()
|
36 |
return f"{input_text}.wav"
|
37 |
|
38 |
+
def get_transliteration(input_text):
|
39 |
+
if not input_text:
|
40 |
return ""
|
41 |
+
|
42 |
result = transliterator([input_text])
|
43 |
return result[0]["translation_text"]
|
44 |
|
|
|
56 |
input_text = gr.Textbox(label="Input", placeholder="Enter English text", lines=1)
|
57 |
gr.Examples(["I wanted to go to the store yesterday, but it rained", "How are you feeling today?", "Let's go to your place"], input_text)
|
58 |
btn = gr.Button("Translate", label="Translate")
|
|
|
|
|
|
|
|
|
59 |
gr.Markdown("Built by [Guy Mor-Lan](mailto:[email protected]). Pronunciation model is specifically tailored to urban Palestinian Arabic. Text-to-speech uses Microsoft Azure's API and may provide different result from the transliterated pronunciation.")
|
60 |
|
61 |
with gr.Column():
|
|
|
68 |
audio = gr.Audio(label="Audio - Palestinian", interactive=False)
|
69 |
audio_button = gr.Button("Get Audio", label="Click Here to Get Audio")
|
70 |
audio_button.click(get_audio, inputs=[pal], outputs=[audio])
|
71 |
+
btn.click(translate_english,inputs=[input_text], outputs=[pal, sy, lb, eg])
|
72 |
+
input_text.submit(translate_english, inputs=[input_text], outputs=[pal, sy, lb, eg])
|
73 |
+
pal.change(get_transliteration, inputs=[pal,], outputs=[pal_translit])
|
74 |
with gr.Tab('From Levantine Arabic to English'):
|
75 |
with gr.Row():
|
76 |
with gr.Column():
|
|
|
93 |
btn.click(get_transliteration, inputs=input_text, outputs=[translit])
|
94 |
|
95 |
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
demo.launch()
|
100 |
|
101 |
+
|