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.42k stars 2.53k forks source link

gr.Code support for user defined syntax #7532

Closed thiswillbeyourgithub closed 8 months ago

thiswillbeyourgithub commented 8 months ago

Is your feature request related to a problem? Please describe.
I use gradio for an app where an LLM outputs a formatted string to the user. I would like to highlight words with low logprob while still making the text editable and also highlight some specific symbols. Using gr.HighlightedText sounded promissing but interactive=True only allows me to modify the spans of highlight and not the text. gr.Code seems perfect but only supports predefined langauges.

Describe the solution you'd like
Allowing to pass user defined syntax for language syntaxic highlighting. This would allow much flexibility and allow many use case.

Additional context

abidlabs commented 8 months ago

Thanks @thiswillbeyourgithub -- I think this would be a great case for a custom component, you can use gr.Code or gr.HighlightedText as a template! https://www.gradio.app/guides/five-minute-guide (we're happy to help).

abidlabs commented 8 months ago

I think this is outside of the scope of gr.Code itself (I'm not sure if codemirror, which we use internally, supports custom syntaxes anyways) so I'll go ahead and close this. However, if you do decide to create a custom component, we're happy to help @thiswillbeyourgithub!

pngwn commented 8 months ago

Codemirror does support custom syntaxes but it does so via lezer, a parser generator that has a build step. The generated parsers also need to be registered via JavaScript which poses a logistical problem as well.

This is definitely better suited as a custom component. The Code component might be a good thing to work from if you wanted to write a grammar for the custom syntax.

thiswillbeyourgithub commented 7 months ago

Alright. I'll keep it in the back of my mind but there's a low prob I'll get to it : I'm less than novice at js and won't have time for a while