mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-12 10:34:32 +08:00
ef3862e075
* Sort requirements.in * Switch flake8 + isort to ruff * Apply ruff import order fixes * Fix ruff complaints in demo/ * Fix ruff complaints in test/ * Use `x is not y`, not `not x is y` * Remove unused listdir from website generator * Clean up duplicate dict keys * Add changelog entry * Clean up unused imports (except in gradio/__init__.py) * add space --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
import gradio as gr
|
|
|
|
secret_word = "gradio"
|
|
|
|
with gr.Blocks() as demo:
|
|
used_letters_var = gr.State([])
|
|
with gr.Row() as row:
|
|
with gr.Column():
|
|
input_letter = gr.Textbox(label="Enter letter")
|
|
btn = gr.Button("Guess Letter")
|
|
with gr.Column():
|
|
hangman = gr.Textbox(
|
|
label="Hangman",
|
|
value="_"*len(secret_word)
|
|
)
|
|
used_letters_box = gr.Textbox(label="Used Letters")
|
|
|
|
def guess_letter(letter, used_letters):
|
|
used_letters.append(letter)
|
|
answer = "".join([
|
|
(letter if letter in used_letters else "_")
|
|
for letter in secret_word
|
|
])
|
|
return {
|
|
used_letters_var: used_letters,
|
|
used_letters_box: ", ".join(used_letters),
|
|
hangman: answer
|
|
}
|
|
btn.click(
|
|
guess_letter,
|
|
[input_letter, used_letters_var],
|
|
[used_letters_var, used_letters_box, hangman]
|
|
)
|
|
if __name__ == "__main__":
|
|
demo.launch() |