import gradio as gr import random as rd rand = rd.randint(0,9) def guess(num): num = int(num) if num == rand: r = 'ถั่วโต้ม' else: r = 'เอาใหม่น้า' return r def answer(): return 'เลขที่ได้ก็คืออ !'+str(rand) 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="เฉลย") with gr.Column(scale=1): out = gr.Textbox(label='ผลลัพธ์') inp.change(guess,inp,out) btn.click(fn=answer,outputs=out) myApp.launch()