File size: 1,019 Bytes
877a1b7 b42f749 6030c90 b42f749 6030c90 72f7576 b3fea0d 6030c90 b3fea0d b42f749 6030c90 ee31fe4 b42f749 ee31fe4 b42f749 877a1b7 b42f749 eb81dee 40e77d6 6030c90 b42f749 40e77d6 b42f749 6030c90 ca5342f 6030c90 |
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 gradio as gr
import random as rd
rand = []
rand = rd.randint(0,9)
def guess(num):
num = int(num)
if num == rand[0]:
r = 'ทายถูกเเล้ว'
else:
r = 'ลองกดใหม่นะ'
return r
def answer():
return 'เลขที่สุ่มได้ คือ'+str(rand[0])
def newRand():
rand[0]= rd.randint(0,9)
return "สุ่มใหม่เรียบร้อยเเล้ว"
with gr.Blocks() as myApp:
with gr.Row():
with gr.Column(scale=1):
inp = gr.Radio(choices=list(range(10)),ladel='เลือก 1 หมายเลข')
btn = gr.Button(value='เฉลย')
btn2 = gr.Button(value='สุ่มใหม่')
with gr.Column(scale=1):
out = gr.Textbox(label='ผลลัพธ์')
inp.change(guess,inp,out)
btn.click(fn=answer,outputs=out)
btn2.click(fn=newRand,outputs=out)
myApp.launch() |