File size: 987 Bytes
c253985 3878517 e1cd620 3878517 c253985 7f154fc c253985 7f154fc baafde3 7f154fc c253985 a07dc5f 7f154fc c253985 5d9b1e7 c253985 |
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 |
import gradio as gr
import random as rd
rand = []
rand.append(rd.randint(0,9))
def guess(num):
num = int(num)
if num == rand[0]:
r = 'ทายถูกแล้ว'
else:
r = 'ลองกดใหม่ดู'
return r
def answer():
return 'เลขที่สุ่มได้คือ'+str(rand)
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)),label='เลือก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()
|