gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
33.41k stars 2.52k forks source link

RTL support in `gr.Textbox` #4325

Closed MohamedAliRashad closed 1 year ago

MohamedAliRashad commented 1 year ago

Is your feature request related to a problem? Please describe.
I want to build Arabic demo websites.

Describe the solution you'd like
I want a toggle to switch the web app from LTR to RTL

abidlabs commented 1 year ago

Hi @MohamedAliRashad can you elaborate more on what the desired behavior is? Is it just that the Textbox component should support text written from RTL, or something more?

MohamedAliRashad commented 1 year ago

@abidlabs I was talking more about the whole UI. An option that i can flip from False to True that transforms the whole web page from LTR to RTL.

zaidalyafeai commented 1 year ago

It seems the current Textbox doesn't support rtl languages like Arabic, correct me if I am wrong?

MohamedAliRashad commented 1 year ago

@zaidalyafeai No, Nothing support RTL out of the box.

(BTW, Thanks for the whisper-ar model (and space) on huggingface.)

abidlabs commented 1 year ago

In what sense are they not supported? I tested right now and the text is written from RTL as expected, although it is not right-aligned. Is that the concern?

image
MohamedAliRashad commented 1 year ago

@abidlabs The Arabic text itself is supported. I am talking about the right-alignment using a flag in the gradio interface.

gr.interface(rtl=True)
# or
gr.Blocks(rtl=True)

(It's possible to force something like this using global css i think).

abidlabs commented 1 year ago

Yes understood @MohamedAliRashad. I was referring to @zaidalyafeai's comment about gr.Textbox specifically

zaidalyafeai commented 1 year ago

Yeah, I meant the alignment, something like html dir will be cool

<input dir="rtl"/>
zaidalyafeai commented 1 year ago

@abidlabs I am releasing a demo soon, is there any way we can add dir='rtl' to textarea? I have modified it using inspect and it works.

zaidalyafeai commented 1 year ago

Also, allowing more freedom in passing styles will be awesome!

gr.inputs.Textbox().style({'text-align': 'right'})
abidlabs commented 1 year ago

Hi @zaidalyafeai we probably won't be able to have it in time for your demo, but this is something we can look into the future.

In the meantime, you could apply custom CSS to your demo to get the desired effect. It would look like this:

css = """
#rtl-textbox{
  text-align: right;
}
"""

with gr.Blocks(css=css)
   ...
   gr.Textbox(elem_id="rtl-textbox")

You can read more about custom css here: https://gradio.app/custom-CSS-and-JS/

abidlabs commented 1 year ago

I'll also switch the focus of this issue from RTL across all of Gradio Blocks (since that's not something we're likely to implement -- too complex with all of the layouts people can create with Blocks) to just the Textbox component, which we can probably support in the future

zaidalyafeai commented 1 year ago

Hi @zaidalyafeai we probably won't be able to have it in time for your demo, but this is something we can look into the future.

In the meantime, you could apply custom CSS to your demo to get the desired effect. It would look like this:

css = """
#rtl-textbox{
  text-align: right;
}
"""

with gr.Blocks(css=css)
   ...
   gr.Textbox(elem_id="rtl-textbox")

You can read more about custom css here: https://gradio.app/custom-CSS-and-JS/

That is exactly what I needed, thank you.