BaselMousi commited on
Commit
d1060c8
ยท
1 Parent(s): 856bb78

fixed translation text direction

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -17,6 +17,12 @@ def translate_text(text, direction):
17
  else:
18
  return translator_ar_to_en.translate(text)
19
 
 
 
 
 
 
 
20
  with gr.Blocks() as demo:
21
  gr.Markdown("# ๐ŸŒ Fanar Translation Demo")
22
  gr.Markdown("## Select the translation direction, enter your text, and get the translation !")
@@ -28,11 +34,20 @@ with gr.Blocks() as demo:
28
  interactive=True,
29
  )
30
 
 
 
31
  input_box = gr.Textbox(label="Input Text", placeholder="Enter text to translate here...", lines=4)
32
- output_box = gr.Textbox(label="Output Text", placeholder="Translated text will appear here...", lines=4, interactive=False)
33
 
 
 
34
  translate_button = gr.Button("Translate")
35
 
 
 
 
 
 
 
36
  translate_button.click(
37
  fn=translate_text,
38
  inputs=[input_box, direction_dropdown],
 
17
  else:
18
  return translator_ar_to_en.translate(text)
19
 
20
+
21
+ def update_output_alignment(direction):
22
+ if direction == "English to Arabic":
23
+ return gr.Textbox(label="Output Text", placeholder="ุงู„ู†ุต ุงู„ู…ุชุฑุฌู… ุณูŠุธู‡ุฑ ู‡ู†ุง...", lines=4, interactive=False, text_align="right")
24
+ else:
25
+ return gr.Textbox(label="Output Text", placeholder="The translated text will appear here...", lines=4, interactive=False, text_align="left")
26
  with gr.Blocks() as demo:
27
  gr.Markdown("# ๐ŸŒ Fanar Translation Demo")
28
  gr.Markdown("## Select the translation direction, enter your text, and get the translation !")
 
34
  interactive=True,
35
  )
36
 
37
+ # I want to change the directionality of the output text depending on the direction selected
38
+
39
  input_box = gr.Textbox(label="Input Text", placeholder="Enter text to translate here...", lines=4)
 
40
 
41
+ output_box = gr.Textbox(label="Output Text", placeholder="ุงู„ู†ุต ุงู„ู…ุชุฑุฌู… ุณูŠุธู‡ุฑ ู‡ู†ุง...", lines=4, interactive=False, text_align="right")
42
+
43
  translate_button = gr.Button("Translate")
44
 
45
+
46
+ direction_dropdown.change(
47
+ fn = update_output_alignment,
48
+ inputs=direction_dropdown,
49
+ outputs = output_box
50
+ )
51
  translate_button.click(
52
  fn=translate_text,
53
  inputs=[input_box, direction_dropdown],