完成西元農曆轉換
Browse files
app.py
CHANGED
@@ -3,6 +3,25 @@
|
|
3 |
import os
|
4 |
import openai
|
5 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
## AI 建議
|
8 |
def get_advice(bmi,temp, API_KEY, model="gpt-3.5-turbo"):
|
@@ -33,21 +52,18 @@ def get_gym(bmi,slide, temp, API_KEY, model="gpt-3.5-turbo"):
|
|
33 |
)
|
34 |
return response.choices[0].message.content
|
35 |
|
36 |
-
def BMI(year, month) ->
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
return str(bmi)[:5], "過重"
|
45 |
-
elif bmi < 30:
|
46 |
-
return str(bmi)[:5], "輕度肥胖"
|
47 |
-
elif bmi < 35:
|
48 |
-
return str(bmi)[:5], "中度肥胖"
|
49 |
else:
|
50 |
-
|
|
|
|
|
51 |
|
52 |
|
53 |
|
@@ -67,9 +83,9 @@ day = gr.Textbox(
|
|
67 |
info="輸入你的出生日子",
|
68 |
placeholder="Input your birthday day here...",)
|
69 |
|
70 |
-
|
71 |
label="生時",
|
72 |
-
info="輸入你的出生時間",
|
73 |
placeholder="Input your birth time here...",)
|
74 |
|
75 |
sex = gr.Textbox(
|
@@ -132,15 +148,15 @@ temperature = gr.Slider(
|
|
132 |
|
133 |
with gr.Blocks() as demo:
|
134 |
gr.Markdown("""
|
135 |
-
#
|
136 |
-
|
137 |
""")
|
138 |
with gr.Column():
|
139 |
with gr.Row():
|
140 |
year.render() # 顯示年
|
141 |
month.render() # 顯示月
|
142 |
day.render() # 顯示日
|
143 |
-
|
144 |
sex.render() # 顯示性別
|
145 |
|
146 |
with gr.Row():
|
@@ -148,7 +164,7 @@ with gr.Blocks() as demo:
|
|
148 |
|
149 |
btn.render() # 顯示計算BMI值按鈕
|
150 |
btn.click(fn=BMI,
|
151 |
-
inputs=[year, month],
|
152 |
outputs=[output_bmi])
|
153 |
|
154 |
advice.render() # 顯示AI建議結果的文字框
|
|
|
3 |
import os
|
4 |
import openai
|
5 |
import gradio as gr
|
6 |
+
from zhdate import ZhDate
|
7 |
+
from datetime import datetime
|
8 |
+
|
9 |
+
# 定義地支對應的時間區間
|
10 |
+
z_mapping = {
|
11 |
+
"1": "子",
|
12 |
+
"2": "丑",
|
13 |
+
"3": "寅",
|
14 |
+
"4": "卯",
|
15 |
+
"5": "辰",
|
16 |
+
"6": "巳",
|
17 |
+
"7": "午",
|
18 |
+
"8": "未",
|
19 |
+
"9": "申",
|
20 |
+
"10": "酉",
|
21 |
+
"11": "戌",
|
22 |
+
"12": "亥",
|
23 |
+
"0": "夜子"
|
24 |
+
}
|
25 |
|
26 |
## AI 建議
|
27 |
def get_advice(bmi,temp, API_KEY, model="gpt-3.5-turbo"):
|
|
|
52 |
)
|
53 |
return response.choices[0].message.content
|
54 |
|
55 |
+
def BMI(year, month, day, btime) -> datetime:
|
56 |
+
dt_date1 = datetime(int(year), int(month), int(day))
|
57 |
+
date_lunar = ZhDate.from_datetime(dt_date1)
|
58 |
+
bstr = str(date_lunar)
|
59 |
+
|
60 |
+
hour = int(btime.split(":")[0])
|
61 |
+
if hour >= 23:
|
62 |
+
z = 0
|
|
|
|
|
|
|
|
|
|
|
63 |
else:
|
64 |
+
z = int(hour / 2) + 1
|
65 |
+
result=z_mapping[str(z)]
|
66 |
+
return bstr.replace('农历','農曆') + " " + result + "時"
|
67 |
|
68 |
|
69 |
|
|
|
83 |
info="輸入你的出生日子",
|
84 |
placeholder="Input your birthday day here...",)
|
85 |
|
86 |
+
btime = gr.Textbox(
|
87 |
label="生時",
|
88 |
+
info="輸入你的出生時間 HH:MM (幾點及約略幾分即可,請用24小時制)",
|
89 |
placeholder="Input your birth time here...",)
|
90 |
|
91 |
sex = gr.Textbox(
|
|
|
148 |
|
149 |
with gr.Blocks() as demo:
|
150 |
gr.Markdown("""
|
151 |
+
# AI 紫微
|
152 |
+
起手式 - 轉換西元生日到農曆出生時辰
|
153 |
""")
|
154 |
with gr.Column():
|
155 |
with gr.Row():
|
156 |
year.render() # 顯示年
|
157 |
month.render() # 顯示月
|
158 |
day.render() # 顯示日
|
159 |
+
btime.render() # 顯示時
|
160 |
sex.render() # 顯示性別
|
161 |
|
162 |
with gr.Row():
|
|
|
164 |
|
165 |
btn.render() # 顯示計算BMI值按鈕
|
166 |
btn.click(fn=BMI,
|
167 |
+
inputs=[year, month, day, btime],
|
168 |
outputs=[output_bmi])
|
169 |
|
170 |
advice.render() # 顯示AI建議結果的文字框
|