Spaces:
Sleeping
Sleeping
File size: 961 Bytes
62444e7 |
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 |
import gradio as gr
import random
# Variável global para armazenar o número alvo
target_number = random.randint(1, 100)
def check_guess(guess):
global target_number
if guess < target_number:
return "Try a higher number!"
elif guess > target_number:
return "Try a lower number!"
else:
target_number = random.randint(1, 100) # Reset the game with a new number
return "Congratulations! You guessed it! Let's play again."
# Interface do Gradio
with gr.Blocks() as demo:
gr.Markdown("### Guess the Number Game")
gr.Markdown("Guess a number between 1 and 100")
with gr.Row():
with gr.Column():
input_number = gr.Number(label="Your Guess", value=1, precision=0)
output_text = gr.Textbox(label="Result")
guess_button = gr.Button("Guess")
guess_button.click(fn=check_guess, inputs=input_number, outputs=output_text)
demo.launch() |