adamtobegreat commited on
Commit
962c80f
·
verified ·
1 Parent(s): 205879d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def bmi(height, weight):
4
+ try:
5
+ h = float(height)
6
+ w = float(weight)
7
+ if h > 10:
8
+ h = h / 100
9
+ bmi = w / (h**2)
10
+ except:
11
+ return "身高或體重的輸入格式錯誤!"
12
+ return f"BMI = {bmi:.2f}!"
13
+
14
+ # 建立 Gradio 介面
15
+ demo = gr.Interface(fn=bmi,
16
+ inputs=[
17
+ gr.Textbox(label="身高", placeholder="這裡輸入身高(單位:公尺或公分)"),
18
+ gr.Textbox(label="體重", placeholder="這裡輸入體重(單位:公斤)")
19
+ ], #使用gr.Textbox物件的方式可以設定更多的細節參數
20
+ outputs=gr.Textbox(label="BMI", value=""),
21
+ title="BMI計算機",
22
+ description="輸入身高跟體重,可以幫你計算BMI值")
23
+
24
+ # 啟動 Web 應用
25
+ demo.launch()
26
+
27
+
28
+
29
+
30
+ # %%
31
+