beta v1.00
Browse files把程式碼整理一下,並把授權等文字加上去
- app.py +49 -49
- savedata.db +0 -0
app.py
CHANGED
@@ -1,11 +1,25 @@
|
|
1 |
-
## 這是 TAIA x H.I.T LLM線上共學社群的專題實作
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
##
|
3 |
## AI 紫微
|
4 |
##
|
5 |
## 開發者:葉浩銘 Bob、蔡靜穎 Jinny 2024-03
|
6 |
##
|
7 |
-
##
|
8 |
-
##
|
|
|
|
|
|
|
|
|
|
|
9 |
import os
|
10 |
import openai
|
11 |
import gradio as gr
|
@@ -22,27 +36,11 @@ solar_month = 5
|
|
22 |
solar_day = 18
|
23 |
time_hour = 3
|
24 |
time_min = 14
|
25 |
-
gender =
|
26 |
|
27 |
#命宮主星是 ming_table[self_palace_epos]
|
28 |
-
|
29 |
zi_adjust = 2
|
30 |
|
31 |
-
'''
|
32 |
-
排盤有以下幾個步驟
|
33 |
-
|
34 |
-
1. 定命宮等十二宮
|
35 |
-
|
36 |
-
2. 起寅首、定納音五行局
|
37 |
-
|
38 |
-
3. 定紫微星、天府星
|
39 |
-
|
40 |
-
4. 安十四主星
|
41 |
-
|
42 |
-
5. 最好也能(安生年四化星)
|
43 |
-
|
44 |
-
'''
|
45 |
-
|
46 |
def gen_chart(solar_year, solar_month, solar_day, time_hour, time_min, gender):
|
47 |
from datetime import timedelta, datetime
|
48 |
|
@@ -159,28 +157,16 @@ def gen_chart(solar_year, solar_month, solar_day, time_hour, time_min, gender):
|
|
159 |
|
160 |
solar_birth_datetime = datetime(int(solar_year), int(solar_month), int(solar_day), time_hour, time_min)
|
161 |
|
162 |
-
|
163 |
if zi_adjust == 2 and time_hour >= 23 :
|
164 |
solar_birth_datetime = solar_birth_datetime + timedelta(days=1)
|
165 |
|
166 |
-
# 跳過 農曆轉換
|
167 |
-
#lunar = Zwbase.get_lunar_datetime(solar_birth_datetime)
|
168 |
-
#lunar_birth_datetime = LunarDatetime(lunar.lunarYear, lunar.lunarMonth, lunar.lunarDay, solar_birth_datetime.hour, solar_birth_datetime.minute, lunar.isleap)
|
169 |
-
|
170 |
# 取得生辰年干支位置
|
171 |
year_hepos = get_year_hepos(solar_birth_datetime)
|
172 |
-
|
173 |
-
# 取得陰陽性別位置
|
174 |
-
# 性別
|
175 |
-
if gender == 2:
|
176 |
-
gender_pos = 2
|
177 |
-
else:
|
178 |
-
gender_pos = 3
|
179 |
|
180 |
# 陰陽
|
181 |
yin_yang_pos = 0 if year_hepos[0] % 2 == 1 else 1
|
182 |
|
183 |
-
|
184 |
# 取得生辰地支位置
|
185 |
birth_time_epos = get_birth_time_epos(solar_birth_datetime)
|
186 |
|
@@ -322,7 +308,7 @@ def get_advice(API_KEY, model="gpt-3.5-turbo-16k"):
|
|
322 |
for i in range(0, 14):
|
323 |
if myData[i]['命宮星象'] == star_name:
|
324 |
msum = msum + myData[i]['整體描述']
|
325 |
-
print(msum)
|
326 |
#gw_main_star = gw_main_star + myData[i]['正面特質'] + myData[i]['負面特質']
|
327 |
gw_main_star = gw_main_star + myData[i]['正面特質']
|
328 |
gw_main_star = gw_main_star + myData[i]['負面特質']
|
@@ -364,20 +350,14 @@ def get_advice(API_KEY, model="gpt-3.5-turbo-16k"):
|
|
364 |
|
365 |
print(ming_star.value,"===",gw_main_star,"#####")
|
366 |
|
367 |
-
messages = [{"role": "system", "content": "
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
# 針對負向特質則以包容的態度,約1500字的長度,給予適當的建議,並鼓勵自發性地做出改變及經常自省,將負向特質轉化成自己的優勢。最後再給予約200字的總結。\
|
376 |
-
# 請你用 traditional Chinese 回答
|
377 |
-
# {"role": "user", "content": f'我的人格特質以紫微斗數星象來推論是“{gw_main_star}”. 請替我依照這些人格特質,並根據 Myers-Briggs Type Indicator (MBTI) 人格分析學說,一條一條的幫我解析?'},]
|
378 |
-
# {"role": "user", "content": f'我的人格特質以紫微斗數星象來推論是“{gw_main_star}”. 請替我依照這些人格特質,並根據 16 Personality Factors 人格分析工具,一條一條的幫我分析?'},]
|
379 |
-
# {"role": "user", "content": f'我的人格特質以紫微斗數星象來推論是“{gw_main_star}”. 請替我依照這些人格特質,並根據 OCEAN 五大人格分析系統,一條一條的幫我分析?'},]
|
380 |
-
{"role": "user", "content": f'此用戶是{pssex}性,依據生辰推測的人格特質是“{gw_main_star}“。\n\n請給他一些待人處事的建議?'},]
|
381 |
try:
|
382 |
response = openai.chat.completions.create(
|
383 |
model=model,
|
@@ -395,7 +375,6 @@ def get_advice(API_KEY, model="gpt-3.5-turbo-16k"):
|
|
395 |
ming_feedback.info = 'YES'
|
396 |
ming_feedback.value = returndata
|
397 |
|
398 |
-
print(f'此用戶是{pssex}性,人格特質是“{gw_main_star}“。請給他一些跟性別相關的待人處事的建議?')
|
399 |
return returndata
|
400 |
|
401 |
def GWAI(year, month, day, btime, sex) -> datetime:
|
@@ -443,6 +422,27 @@ def GWAI(year, month, day, btime, sex) -> datetime:
|
|
443 |
output2=gen_chart(int(my_year), int(my_month), int(my_day), hour, int(30), int(pssex))
|
444 |
return output,output2
|
445 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
def disp_prompt():
|
447 |
output = '''你是 ChatGPT, a large language model trained by OpenAI, based on the GPT-4 architecture.
|
448 |
我打算用傳統中文 traditional Chinese 給你一個叫“排龍珠”的任務,結果請你也用 traditional Chinese 回答。
|
|
|
1 |
+
## 這是 TAIA x H.I.T LLM線上共學社群的專題實作 6
|
2 |
+
#
|
3 |
+
# Copyright (C) 2023 Bob Yeh, Jinny Tsai
|
4 |
+
#
|
5 |
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6 |
+
#
|
7 |
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8 |
+
#
|
9 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
10 |
+
#
|
11 |
##
|
12 |
## AI 紫微
|
13 |
##
|
14 |
## 開發者:葉浩銘 Bob、蔡靜穎 Jinny 2024-03
|
15 |
##
|
16 |
+
## 利用在 TAIA x H.I.T 線上共學社群的 AI 課程學到的技術
|
17 |
+
##
|
18 |
+
## 希望能透過開源,拋磚引玉,讓紫微斗數這門古老學問,可以在 AI 浪潮中更加發揚光大
|
19 |
+
##
|
20 |
+
## Note:
|
21 |
+
## GPT model="gpt-3.5-turbo-16k"
|
22 |
+
## 可以在你 local 的資料夾新增 .env 檔案,並在裡面寫入 API_KEY=你的 OpenAI API 金鑰
|
23 |
import os
|
24 |
import openai
|
25 |
import gradio as gr
|
|
|
36 |
solar_day = 18
|
37 |
time_hour = 3
|
38 |
time_min = 14
|
39 |
+
gender = 2
|
40 |
|
41 |
#命宮主星是 ming_table[self_palace_epos]
|
|
|
42 |
zi_adjust = 2
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
def gen_chart(solar_year, solar_month, solar_day, time_hour, time_min, gender):
|
45 |
from datetime import timedelta, datetime
|
46 |
|
|
|
157 |
|
158 |
solar_birth_datetime = datetime(int(solar_year), int(solar_month), int(solar_day), time_hour, time_min)
|
159 |
|
160 |
+
# 夜子時設定檢查
|
161 |
if zi_adjust == 2 and time_hour >= 23 :
|
162 |
solar_birth_datetime = solar_birth_datetime + timedelta(days=1)
|
163 |
|
|
|
|
|
|
|
|
|
164 |
# 取得生辰年干支位置
|
165 |
year_hepos = get_year_hepos(solar_birth_datetime)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
# 陰陽
|
168 |
yin_yang_pos = 0 if year_hepos[0] % 2 == 1 else 1
|
169 |
|
|
|
170 |
# 取得生辰地支位置
|
171 |
birth_time_epos = get_birth_time_epos(solar_birth_datetime)
|
172 |
|
|
|
308 |
for i in range(0, 14):
|
309 |
if myData[i]['命宮星象'] == star_name:
|
310 |
msum = msum + myData[i]['整體描述']
|
311 |
+
#print(msum)
|
312 |
#gw_main_star = gw_main_star + myData[i]['正面特質'] + myData[i]['負面特質']
|
313 |
gw_main_star = gw_main_star + myData[i]['正面特質']
|
314 |
gw_main_star = gw_main_star + myData[i]['負面特質']
|
|
|
350 |
|
351 |
print(ming_star.value,"===",gw_main_star,"#####")
|
352 |
|
353 |
+
messages = [{"role": "system", "content": "你是一個心理學權威,當推測出一段關於人格特質的描述時,你會考慮對方的性別,並以一個專業的心理諮商師的身分進行以下回應。(但你不可以自稱是心理師或心理學權威) \
|
354 |
+
1. 選出3~4個正向特質給予肯定,帶領使用者欣賞自身優點 \
|
355 |
+
2. 選出2~3個負向特質,以包容的態度,給予適當的建議,點出問題核心。 \
|
356 |
+
3. 從正向特質中找尋可以改善負向特質的方法,提出有建設性的方案。 \
|
357 |
+
4. 鼓勵自發性地做出改變及經常自省,將負向特質轉化成優勢。同時強調不需操之過急,設定階段性目標,逐步實踐。 \
|
358 |
+
5. 提醒他是個獨特的人,就算無法改變也是相當珍貴的人。 \
|
359 |
+
6. 鼓勵對方如果內心仍有困擾,多與可信賴的重要他人商量、建立良好關係。"},
|
360 |
+
{"role": "user", "content": f'此用戶是{pssex}性,你事先依據生辰來推測他的人格特質是:\n\n“{gw_main_star}“。\n\n請給他一些待人處事的建議?'},]
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
try:
|
362 |
response = openai.chat.completions.create(
|
363 |
model=model,
|
|
|
375 |
ming_feedback.info = 'YES'
|
376 |
ming_feedback.value = returndata
|
377 |
|
|
|
378 |
return returndata
|
379 |
|
380 |
def GWAI(year, month, day, btime, sex) -> datetime:
|
|
|
422 |
output2=gen_chart(int(my_year), int(my_month), int(my_day), hour, int(30), int(pssex))
|
423 |
return output,output2
|
424 |
|
425 |
+
'''
|
426 |
+
排盤有以下幾個步驟
|
427 |
+
|
428 |
+
1. 定命宮等十二宮
|
429 |
+
|
430 |
+
2. 起寅首、定納音五行局
|
431 |
+
|
432 |
+
3. 定紫微星、天府星
|
433 |
+
|
434 |
+
4. 安十四主星
|
435 |
+
|
436 |
+
# 起紫微星訣算法
|
437 |
+
#
|
438 |
+
# - 六五四三二,酉午亥辰丑,
|
439 |
+
# - 局數除日數,商數宮前走;
|
440 |
+
# - 若見數無余,便要起虎口,
|
441 |
+
# - 日數小於局,還直宮中守。
|
442 |
+
|
443 |
+
'''
|
444 |
+
|
445 |
+
|
446 |
def disp_prompt():
|
447 |
output = '''你是 ChatGPT, a large language model trained by OpenAI, based on the GPT-4 architecture.
|
448 |
我打算用傳統中文 traditional Chinese 給你一個叫“排龍珠”的任務,結果請你也用 traditional Chinese 回答。
|
savedata.db
CHANGED
Binary files a/savedata.db and b/savedata.db differ
|
|