gradio/demo/code/run.py
aliabid94 da05e59a53
Removing .update and get_config, attempt 2 (#5240)
* changes

* add changeset

* changes

* changes

* Update many-tips-create.md

* notebooks

* chanegs

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changew

* changes

* changes

* changes

* changes

* chanegs

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* Revert "changes"

This reverts commit 0868c25c56.

* changes

* changes

* changes

* changes

* changes

* changes

* change

* changes

* chaneges

* changes

* chagnes

* changes

* changes

* changes

* changes

* changes

* fix typing

* changes

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
2023-09-18 21:17:06 -07:00

44 lines
1.1 KiB
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(language=language)
def set_lang_from_path():
sleep(1)
return gr.Code((css_file,), language="css")
def code(language, code):
return gr.Code(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",
value='def all_odd_elements(sequence):\n """Returns every odd element of the sequence."""',
)
code_out = gr.Code(label="Output")
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()