Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
import random as rd
|
|
|
|
|
3 |
rand = rd.randint(0,9)
|
|
|
4 |
def guess(num):
|
5 |
num = int(num)
|
6 |
if num == rand:
|
@@ -8,15 +11,24 @@ def guess(num):
|
|
8 |
else:
|
9 |
r = 'ลองกดใหม่นะ'
|
10 |
return r
|
|
|
11 |
def answer():
|
12 |
return 'เลขที่สุ่มได้ คือ '+str(rand)
|
|
|
|
|
|
|
|
|
|
|
13 |
with gr.Blocks() as myApp:
|
14 |
with gr.Row():
|
15 |
with gr.Column(scale=1):
|
16 |
inp = gr.Radio(choices=list(range(10)),label='เลือก 1 หมายเลข')
|
17 |
btn = gr.Button(value="เฉลย")
|
|
|
18 |
with gr.Column(scale=1):
|
19 |
out = gr.Textbox(label='ผลลัพธ์')
|
|
|
20 |
inp.change(guess,inp,out)
|
21 |
btn.click(fn=answer,outputs=out)
|
|
|
22 |
myApp.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import random as rd
|
3 |
+
|
4 |
+
rand = []
|
5 |
rand = rd.randint(0,9)
|
6 |
+
|
7 |
def guess(num):
|
8 |
num = int(num)
|
9 |
if num == rand:
|
|
|
11 |
else:
|
12 |
r = 'ลองกดใหม่นะ'
|
13 |
return r
|
14 |
+
|
15 |
def answer():
|
16 |
return 'เลขที่สุ่มได้ คือ '+str(rand)
|
17 |
+
|
18 |
+
def newRand():
|
19 |
+
rand[0]= rd.randint(0.9)
|
20 |
+
return str(rand)
|
21 |
+
|
22 |
with gr.Blocks() as myApp:
|
23 |
with gr.Row():
|
24 |
with gr.Column(scale=1):
|
25 |
inp = gr.Radio(choices=list(range(10)),label='เลือก 1 หมายเลข')
|
26 |
btn = gr.Button(value="เฉลย")
|
27 |
+
btn2 = gr.Button(value="สุ่มใหม่")
|
28 |
with gr.Column(scale=1):
|
29 |
out = gr.Textbox(label='ผลลัพธ์')
|
30 |
+
|
31 |
inp.change(guess,inp,out)
|
32 |
btn.click(fn=answer,outputs=out)
|
33 |
+
btn2.click(fn=newRand,outputs=out)
|
34 |
myApp.launch()
|