gradio/demo/code/run.py
pngwn 11bb732f5d
add code component (#3421)
* add code component

* changes

* changes

* code

* add code to all_demos

* change remove prefix

* changes

* notebooks

* fix pythong types

* changelog

* cleanup

* Apply suggestions from code review

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* add interactive kwarg

* fix focus

* changelog

* fix demo

* tests

* cleanup

* Update gradio/components.py

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* change padding to compute from block label styles

* use neutral colours for sucess animation

* cleanup

* update document

* add changelog for fix

* fix documentation

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-03-10 17:52:17 +00:00

40 lines
958 B
Python

import gradio as gr
import os
from time import sleep
css_file = os.path.join(os.path.dirname(__file__), "file.css")
def set_lang(language):
print(language)
return gr.Code.update(language=language)
def set_lang_from_path():
sleep(1)
return gr.Code.update(css_file, language="css")
def code(language, code):
return gr.Code.update(code, language=language)
io = gr.Interface(lambda x: x, "code", "code")
with gr.Blocks() as demo:
lang = gr.Dropdown(value="python", choices=gr.Code.languages)
with gr.Row():
code_in = gr.Code(language="python", label="Input")
code_out = gr.Code(label="Ouput")
btn = gr.Button("Run")
btn_two = gr.Button("Load File")
lang.change(set_lang, inputs=lang, outputs=code_in)
btn.click(code, inputs=[lang, code_in], outputs=code_out)
btn_two.click(set_lang_from_path, inputs=None, outputs=code_out)
io.render()
if __name__ == "__main__":
demo.launch()