Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
import random as rd
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
with gr.Blocks() as myApp:
|
5 |
with gr.Row():
|
6 |
with gr.Column(scale=1):
|
7 |
inp = gr.Radio(choices=list(range(10)),label='เลือก 1 หมายเลข')
|
|
|
8 |
with gr.Column(scale=1):
|
9 |
out = gr.Textbox(label='ผลลัพธ์')
|
|
|
|
|
10 |
myApp.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import random as rd
|
3 |
+
def guess ( num ) :
|
4 |
+
num = int ( num )
|
5 |
+
if num == rand :
|
6 |
+
r = 'ทายถูกเเล้ว'
|
7 |
+
else :
|
8 |
+
r = 'ลองกดใหม่นะ'
|
9 |
+
return r
|
10 |
+
def answer():
|
11 |
+
return 'เลขที่สุ่มได้ คือ'+str(rand)
|
12 |
with gr.Blocks() as myApp:
|
13 |
with gr.Row():
|
14 |
with gr.Column(scale=1):
|
15 |
inp = gr.Radio(choices=list(range(10)),label='เลือก 1 หมายเลข')
|
16 |
+
btn = gr.button(value='เฉลย')
|
17 |
with gr.Column(scale=1):
|
18 |
out = gr.Textbox(label='ผลลัพธ์')
|
19 |
+
inp.change(guess,inp,out)
|
20 |
+
btn.click(fn=answer,output=out)
|
21 |
myApp.launch()
|