Spaces:
Runtime error
Runtime error
File size: 764 Bytes
57c271c e32cf58 57c271c e32cf58 57c271c e32cf58 57c271c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import time
import gradio as gr
from gradio_highlightedcode import HighlightedCode
example = HighlightedCode().example_inputs()
initial_value = """import random
def scramble_name(name):
name_list = list(name)
"""
completion = """ random.shuffle(name_list)
return ''.join(name_list)
# Example usage:
print(scramble_name("Python"))
"""
def generate_code():
for i in range(len(completion)):
time.sleep(0.03)
yield HighlightedCode(initial_value + completion[:i], highlights=[(5, "rgb(255 254 213)")])
with gr.Blocks() as demo:
code = HighlightedCode(initial_value, language="python")
btn = gr.Button("Generate", variant="primary")
btn.click(generate_code, outputs=code)
if __name__ == "__main__":
demo.launch()
|