benjamin5607 commited on
Commit
c6e608a
ยท
verified ยท
1 Parent(s): 0a861bc

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +150 -38
main.py CHANGED
@@ -3,103 +3,215 @@ import time
3
  import datetime
4
  from utils import tarot, prompts, llm, calculations, lang
5
 
 
6
  st.set_page_config(page_title="AI Pantheon Pro", page_icon="๐Ÿ”ฎ", layout="wide")
7
 
 
8
  def apply_theme(mode):
9
- st.markdown("""<style>@import url('https://fonts.googleapis.com/css2?family=Nanum+Myeongjo:wght@700&display=swap');
10
- div[data-testid="stGrid"] button { height: 100px; background-color: #2d1b4e; border: 2px dashed #d4af37; color: transparent; }
11
- div[data-testid="stGrid"] button:hover { background-color: #4b0082; border: 2px solid #fff; }
12
- </style>""", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  themes = {
14
  "tarot": ".stApp { background: linear-gradient(135deg, #1a0b2e 0%, #2d1b4e 100%); color: #e0d4fc; }",
15
- "fengshui": ".stApp { background-color: #f5f5f0; color: #3e2723; }",
16
- "shaman": ".stApp { background-color: #1a0505; color: #ffcccc; } .stTextInput>div>div>input { background-color: #330000; color: yellow; }"
17
  }
18
- st.markdown(f"<style>{themes.get(mode, themes['tarot'])}</style>", unsafe_allow_html=True)
 
19
 
 
20
  if "tarot_stage" not in st.session_state: st.session_state.tarot_stage = "input"
21
- if "picked_indices" not in st.session_state: st.session_state.picked_indices = []
22
  if "picked_cards" not in st.session_state: st.session_state.picked_cards = []
23
 
 
24
  st.sidebar.markdown("### ๐ŸŒ Language")
25
- current_lang = st.sidebar.selectbox("Language", ["ํ•œ๊ตญ์–ด", "English", "ไธญๆ–‡", "ๆ—ฅๆœฌ่ชž"], label_visibility="collapsed")
26
- TXT = lang.STRINGS[current_lang]
27
 
28
  st.sidebar.title(TXT["sidebar_title"])
29
- selected_mode = st.sidebar.radio(TXT["select_persona"], ("tarot", "fengshui", "shaman"), format_func=lambda x: TXT["personas"][x])
 
 
 
 
 
 
 
 
30
  apply_theme(selected_mode)
31
  current_persona = prompts.get_persona(selected_mode)
 
 
32
  st.sidebar.info(TXT["desc"][selected_mode])
33
 
 
34
  st.title(f"{current_persona['icon']} {TXT['personas'][selected_mode]}")
35
  st.markdown("---")
36
 
 
 
 
37
  if selected_mode == "tarot":
 
38
  if st.session_state.tarot_stage == "input":
39
  with st.form("tarot_form"):
40
- topic = st.selectbox(TXT["tarot_topic"], ["Love", "Money", "Career", "Health"])
41
  query = st.text_area(TXT["input_label"], placeholder=TXT["tarot_placeholder"])
 
42
  if st.form_submit_button(TXT["btn_submit"]) and query:
43
  st.session_state.user_query = f"[{topic}] {query}"
44
  st.session_state.tarot_stage = "picking"
45
- st.session_state.picked_indices = []
46
  st.rerun()
 
 
47
  elif st.session_state.tarot_stage == "picking":
48
- st.subheader(TXT["tarot_pick_inst"])
49
- st.write(f"{TXT['tarot_selected']}: **{len(st.session_state.picked_indices)} / 3**")
 
 
 
 
 
50
  cols = st.columns(6)
51
- for i in range(22):
 
 
 
52
  is_picked = i in st.session_state.picked_indices
53
- if cols[i % 6].button("โœ…" if is_picked else "๐ŸŽด", key=f"c{i}", disabled=is_picked):
54
- st.session_state.picked_indices.append(i)
55
- st.rerun()
56
- if len(st.session_state.picked_indices) >= 3:
57
- if st.button(TXT["btn_submit"], type="primary"):
 
 
 
 
 
 
 
 
 
58
  st.session_state.picked_cards = [tarot.MAJOR_ARCANA[i] for i in st.session_state.picked_indices[:3]]
59
  st.session_state.tarot_stage = "result"
60
  st.rerun()
 
 
61
  elif st.session_state.tarot_stage == "result":
62
- cols = st.columns(3)
 
 
 
63
  for idx, card in enumerate(st.session_state.picked_cards):
64
- with cols[idx]: st.image(tarot.get_card_image(card["name"]), caption=card["name"])
 
 
 
 
 
 
65
  if "ai_response" not in st.session_state:
66
  with st.spinner(TXT["analyzing"]):
67
- st.session_state.ai_response = llm.get_ai_response(st.session_state.user_query, current_persona, st.session_state.picked_cards, user_lang=current_lang)
 
 
 
 
 
 
68
  st.markdown(st.session_state.ai_response)
 
 
69
  if st.button(TXT["retry_btn"]):
70
  st.session_state.tarot_stage = "input"
71
  del st.session_state["ai_response"]
72
  st.rerun()
73
 
 
 
 
74
  elif selected_mode == "fengshui":
75
- with st.expander("โ„น๏ธ Input", expanded=True):
 
76
  c1, c2 = st.columns(2)
77
  with c1:
78
  birth_year = st.number_input(TXT["birth_year"], 1950, 2025, 1990)
79
- gender = "Male" if st.radio(TXT["gender"], ["Male", "Female"]) == "Male" else "Female"
 
 
80
  with c2:
81
  door_dir = st.selectbox(TXT["door_dir"], ["N", "NE", "E", "SE", "S", "SW", "W", "NW"])
82
  head_dir = st.selectbox(TXT["head_dir"], ["N", "NE", "E", "SE", "S", "SW", "W", "NW"])
 
83
  if prompt := st.chat_input(TXT["input_label"]):
84
- fs_data = calculations.get_fengshui_advanced(birth_year, gender, door_dir, head_dir)
85
- full_query = f"[FengShui]: {fs_data}\nQuery: {prompt}"
 
 
 
 
 
 
86
  with st.chat_message("user"): st.write(prompt)
87
  with st.chat_message("assistant"):
88
- with st.spinner(TXT["analyzing"]): st.write(llm.get_ai_response(full_query, current_persona, user_lang=current_lang))
 
 
89
 
 
 
 
90
  elif selected_mode == "shaman":
91
- with st.expander("โ„น๏ธ Saju", expanded=True):
92
  st.caption(TXT["shaman_warn"])
93
  c1, c2 = st.columns(2)
94
  with c1:
95
- b_date = st.date_input(TXT["birth_date"], datetime.date(1990,1,1))
96
  cal_type = st.radio(TXT["calendar_type"], ["Solar", "Lunar"])
97
  with c2:
98
- b_time = st.time_input(TXT["birth_time"], datetime.time(12,0))
99
- if prompt := st.chat_input(TXT["input_label"]):
100
- saju = calculations.get_ganji_full(b_date, b_time, cal_type)
101
- full_query = f"[Saju]: {saju}\nQuery: {prompt}"
102
- with st.chat_message("user"): st.write(prompt)
 
 
 
 
 
 
 
103
  with st.chat_message("assistant"):
104
- with st.spinner(TXT["loading"]): st.markdown(llm.get_ai_response(full_query, current_persona, user_lang=current_lang))
105
- st.info(f"{TXT['saju_result']}: {saju['year_ganji']} ({saju['animal']})")
 
 
 
 
 
3
  import datetime
4
  from utils import tarot, prompts, llm, calculations, lang
5
 
6
+ # --- [1. ์•ฑ ์„ค์ •] ---
7
  st.set_page_config(page_title="AI Pantheon Pro", page_icon="๐Ÿ”ฎ", layout="wide")
8
 
9
+ # --- [2. ์Šคํƒ€์ผ & ํ…Œ๋งˆ ์—”์ง„] ---
10
  def apply_theme(mode):
11
+ # 1. ํฐํŠธ ๋กœ๋“œ
12
+ st.markdown("""
13
+ <style>
14
+ @import url('https://fonts.googleapis.com/css2?family=Nanum+Myeongjo:wght@700&family=Noto+Serif+SC:wght@600&family=Noto+Serif+JP:wght@600&family=Nanum+Pen+Script&family=Noto+Sans+KR:wght@400;700&display=swap');
15
+
16
+ /* ๐Ÿƒ ํƒ€๋กœ ์นด๋“œ ์„ ํƒ ๊ทธ๋ฆฌ๋“œ ์Šคํƒ€์ผ๋ง (์นด๋“œ ๋’ท๋ฉด ํšจ๊ณผ) */
17
+ div[data-testid="stGrid"] button {
18
+ height: 120px;
19
+ background-color: #2d1b4e; /* ์นด๋“œ ๋’ท๋ฉด ์ƒ‰ */
20
+ border: 2px dashed #d4af37; /* ๊ธˆ์ƒ‰ ํ…Œ๋‘๋ฆฌ */
21
+ color: transparent; /* ๊ธ€์ž ์ˆจ๊น€ */
22
+ border-radius: 8px;
23
+ transition: all 0.3s;
24
+ }
25
+ div[data-testid="stGrid"] button:hover {
26
+ background-color: #4b0082;
27
+ border: 2px solid #fff;
28
+ transform: scale(1.05);
29
+ }
30
+ div[data-testid="stGrid"] button:disabled {
31
+ background-color: #d4af37; /* ์„ ํƒ๋œ ์นด๋“œ๋Š” ๊ธˆ์ƒ‰์œผ๋กœ ๋ณ€๊ฒฝ */
32
+ border: 2px solid #fff;
33
+ opacity: 1.0;
34
+ }
35
+ </style>
36
+ """, unsafe_allow_html=True)
37
+
38
+ # 2. ๋ชจ๋“œ๋ณ„ ๋ฐฐ๊ฒฝ ํ…Œ๋งˆ ์ ์šฉ
39
  themes = {
40
  "tarot": ".stApp { background: linear-gradient(135deg, #1a0b2e 0%, #2d1b4e 100%); color: #e0d4fc; }",
41
+ "fengshui": ".stApp { background-color: #f5f5f0; background-image: url('https://www.transparenttextures.com/patterns/rice-paper.png'); color: #3e2723; }",
42
+ "shaman": ".stApp { background-color: #1a0505; color: #ffcccc; } .stTextInput>div>div>input { background-color: #330000; color: yellow; border: 1px solid red; }"
43
  }
44
+ css = themes.get(mode, themes["tarot"])
45
+ st.markdown(f"<style>{css}</style>", unsafe_allow_html=True)
46
 
47
+ # --- [3. ์ƒํƒœ ๊ด€๋ฆฌ ์ดˆ๊ธฐํ™”] ---
48
  if "tarot_stage" not in st.session_state: st.session_state.tarot_stage = "input"
49
+ if "picked_indices" not in st.session_state: st.session_state.picked_indices = [] # ์„ ํƒํ•œ ์นด๋“œ ๋ฒˆํ˜ธ ์ €์žฅ
50
  if "picked_cards" not in st.session_state: st.session_state.picked_cards = []
51
 
52
+ # --- [4. ์–ธ์–ด ๋ฐ ์‚ฌ์ด๋“œ๋ฐ” ์„ค์ •] ---
53
  st.sidebar.markdown("### ๐ŸŒ Language")
54
+ current_lang = st.sidebar.selectbox("Select Language", ["ํ•œ๊ตญ์–ด", "English", "ไธญๆ–‡", "ๆ—ฅๆœฌ่ชž"], label_visibility="collapsed")
55
+ TXT = lang.STRINGS[current_lang] # ์–ธ์–ดํŒฉ ๋กœ๋“œ
56
 
57
  st.sidebar.title(TXT["sidebar_title"])
58
+
59
+ # ํŽ˜๋ฅด์†Œ๋‚˜ ์„ ํƒ
60
+ selected_mode = st.sidebar.radio(
61
+ TXT["select_persona"],
62
+ ("tarot", "fengshui", "shaman"),
63
+ format_func=lambda x: TXT["personas"][x]
64
+ )
65
+
66
+ # ํ…Œ๋งˆ ๋ฐ ํŽ˜๋ฅด์†Œ๋‚˜ ์ ์šฉ
67
  apply_theme(selected_mode)
68
  current_persona = prompts.get_persona(selected_mode)
69
+
70
+ st.sidebar.markdown("---")
71
  st.sidebar.info(TXT["desc"][selected_mode])
72
 
73
+ # ๋ฉ”์ธ ํƒ€์ดํ‹€
74
  st.title(f"{current_persona['icon']} {TXT['personas'][selected_mode]}")
75
  st.markdown("---")
76
 
77
+ # =========================================================
78
+ # ๐Ÿƒ [๋ชจ๋“œ A] ํƒ€๋กœ: ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ ๊ทธ๋ฆฌ๋“œ ์„ ํƒ ์‹œ์Šคํ…œ
79
+ # =========================================================
80
  if selected_mode == "tarot":
81
+ # Step 1: ๊ณ ๋ฏผ ์ž…๋ ฅ
82
  if st.session_state.tarot_stage == "input":
83
  with st.form("tarot_form"):
84
+ topic = st.selectbox(TXT["tarot_topic"], ["Love", "Money", "Career", "Health", "Relationship"])
85
  query = st.text_area(TXT["input_label"], placeholder=TXT["tarot_placeholder"])
86
+
87
  if st.form_submit_button(TXT["btn_submit"]) and query:
88
  st.session_state.user_query = f"[{topic}] {query}"
89
  st.session_state.tarot_stage = "picking"
90
+ st.session_state.picked_indices = [] # ์„ ํƒ ์ดˆ๊ธฐํ™”
91
  st.rerun()
92
+
93
+ # Step 2: ์นด๋“œ ์ง์ ‘ ๊ณ ๋ฅด๊ธฐ (ํ•ต์‹ฌ ๊ธฐ๋Šฅ)
94
  elif st.session_state.tarot_stage == "picking":
95
+ st.subheader(TXT["tarot_pick_inst"]) # "์นด๋“œ 3์žฅ์„ ์„ ํƒํ•˜์„ธ์š”"
96
+
97
+ # ํ˜„์žฌ ์„ ํƒ๋œ ๊ฐฏ์ˆ˜ ํ‘œ์‹œ
98
+ count = len(st.session_state.picked_indices)
99
+ st.progress(count / 3, text=f"{TXT['tarot_selected']}: {count} / 3")
100
+
101
+ # 22์žฅ์˜ ์นด๋“œ๋ฅผ 6์—ด ๊ทธ๋ฆฌ๋“œ๋กœ ๋ฐฐ์น˜
102
  cols = st.columns(6)
103
+ deck_size = 22
104
+
105
+ for i in range(deck_size):
106
+ # ์ด๋ฏธ ์„ ํƒ๋œ ์นด๋“œ๋Š” ๋น„ํ™œ์„ฑํ™”(disabled) ์ฒ˜๋ฆฌ
107
  is_picked = i in st.session_state.picked_indices
108
+ label = "โœ…" if is_picked else "๐ŸŽด"
109
+
110
+ # ๋ฒ„ํŠผ ์ƒ์„ฑ (CSS๋กœ ์นด๋“œ ๋’ท๋ฉด์ฒ˜๋Ÿผ ๋ณด์ž„)
111
+ if cols[i % 6].button(label, key=f"card_{i}", disabled=is_picked):
112
+ if count < 3:
113
+ st.session_state.picked_indices.append(i)
114
+ st.rerun() # ํด๋ฆญ ์‹œ ์ฆ‰์‹œ ํ™”๋ฉด ๊ฐฑ์‹ 
115
+
116
+ # 3์žฅ์„ ๋‹ค ๊ณจ๋ž์„ ๋•Œ๋งŒ '๊ฒฐ๊ณผ ๋ณด๊ธฐ' ๋ฒ„ํŠผ ๋“ฑ์žฅ
117
+ if count >= 3:
118
+ st.success("โœจ ์šด๋ช…์˜ ์„ ํƒ์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
119
+ if st.button(TXT["btn_submit"], type="primary", use_container_width=True):
120
+ # ์ธ๋ฑ์Šค๋ฅผ ์‹ค์ œ ์นด๋“œ ๋ฐ์ดํ„ฐ๋กœ ๋ณ€ํ™˜
121
+ # (utils/tarot.py์˜ MAJOR_ARCANA ๋ฆฌ์ŠคํŠธ ์‚ฌ์šฉ)
122
  st.session_state.picked_cards = [tarot.MAJOR_ARCANA[i] for i in st.session_state.picked_indices[:3]]
123
  st.session_state.tarot_stage = "result"
124
  st.rerun()
125
+
126
+ # Step 3: ๊ฒฐ๊ณผ ๋ฐ AI ํ•ด์„
127
  elif st.session_state.tarot_stage == "result":
128
+ # 3๋‹จ ์ปฌ๋Ÿผ์œผ๋กœ ์นด๋“œ ์ด๋ฏธ์ง€ ํ‘œ์‹œ
129
+ c1, c2, c3 = st.columns(3)
130
+ positions = ["Past/Cause", "Present/Situation", "Future/Result"]
131
+
132
  for idx, card in enumerate(st.session_state.picked_cards):
133
+ with [c1, c2, c3][idx]:
134
+ st.caption(f"๐Ÿ“Œ {positions[idx]}")
135
+ st.image(tarot.get_card_image(card["name"]), caption=card["name"])
136
+
137
+ st.divider()
138
+
139
+ # AI ๋ฆฌ๋”ฉ (ํ•œ ๋ฒˆ๋งŒ ํ˜ธ์ถœํ•˜๊ณ  ์บ์‹ฑ)
140
  if "ai_response" not in st.session_state:
141
  with st.spinner(TXT["analyzing"]):
142
+ st.session_state.ai_response = llm.get_ai_response(
143
+ st.session_state.user_query,
144
+ current_persona,
145
+ st.session_state.picked_cards,
146
+ user_lang=current_lang
147
+ )
148
+
149
  st.markdown(st.session_state.ai_response)
150
+
151
+ # ๋‹ค์‹œํ•˜๊ธฐ ๋ฒ„ํŠผ
152
  if st.button(TXT["retry_btn"]):
153
  st.session_state.tarot_stage = "input"
154
  del st.session_state["ai_response"]
155
  st.rerun()
156
 
157
+ # =========================================================
158
+ # ๐Ÿก [๋ชจ๋“œ B] ํ’์ˆ˜์ง€๋ฆฌ: ์ •๋ฐ€ ์ง„๋‹จ ํผ
159
+ # =========================================================
160
  elif selected_mode == "fengshui":
161
+ with st.expander("โ„น๏ธ Input Data", expanded=True):
162
+ st.caption(TXT["fengshui_info"])
163
  c1, c2 = st.columns(2)
164
  with c1:
165
  birth_year = st.number_input(TXT["birth_year"], 1950, 2025, 1990)
166
+ # ์„ฑ๋ณ„ ์„ ํƒ (๊ณ„์‚ฐ ๋กœ์ง์„ ์œ„ํ•ด ๊ฐ’ ๋ณ€ํ™˜)
167
+ gender_input = st.radio(TXT["gender"], ["Male", "Female"])
168
+ gender_val = "๋‚จ์„ฑ" if gender_input == "Male" else "์—ฌ์„ฑ"
169
  with c2:
170
  door_dir = st.selectbox(TXT["door_dir"], ["N", "NE", "E", "SE", "S", "SW", "W", "NW"])
171
  head_dir = st.selectbox(TXT["head_dir"], ["N", "NE", "E", "SE", "S", "SW", "W", "NW"])
172
+
173
  if prompt := st.chat_input(TXT["input_label"]):
174
+ # 1. ๊ณ ๊ธ‰ ํ’์ˆ˜ ๊ณ„์‚ฐ
175
+ fs_data = calculations.get_fengshui_advanced(birth_year, gender_val, door_dir, head_dir)
176
+
177
+ # 2. ํ”„๋กฌํ”„ํŠธ ์กฐํ•ฉ
178
+ sys_msg = f"[FengShui Analysis]: {fs_data}"
179
+ full_query = f"{sys_msg}\nUser Question: {prompt}"
180
+
181
+ # 3. UI ํ‘œ์‹œ & AI ์š”์ฒญ
182
  with st.chat_message("user"): st.write(prompt)
183
  with st.chat_message("assistant"):
184
+ with st.spinner(TXT["analyzing"]):
185
+ response = llm.get_ai_response(full_query, current_persona, user_lang=current_lang)
186
+ st.write(response)
187
 
188
+ # =========================================================
189
+ # ๐Ÿ‘น [๋ชจ๋“œ C] ์‹ ์ : ์ •๋ฐ€ ์‚ฌ์ฃผ ์ž…๋ ฅ
190
+ # =========================================================
191
  elif selected_mode == "shaman":
192
+ with st.expander("๐Ÿ•ฏ๏ธ Saju Data", expanded=True):
193
  st.caption(TXT["shaman_warn"])
194
  c1, c2 = st.columns(2)
195
  with c1:
196
+ b_date = st.date_input(TXT["birth_date"], datetime.date(1990, 1, 1))
197
  cal_type = st.radio(TXT["calendar_type"], ["Solar", "Lunar"])
198
  with c2:
199
+ b_time = st.time_input(TXT["birth_time"], datetime.time(12, 00))
200
+
201
+ if prompt_input := st.chat_input(TXT["input_label"]):
202
+ # 1. ๊ณ ๊ธ‰ ์‚ฌ์ฃผ ๊ณ„์‚ฐ
203
+ saju_data = calculations.get_ganji_full(b_date, b_time, cal_type)
204
+
205
+ # 2. ํ”„๋กฌํ”„ํŠธ ์กฐํ•ฉ
206
+ sys_msg = f"[Detailed Saju]: {saju_data['text_data']}\nGanji: {saju_data['year_ganji']}\nElement: {saju_data['element']}"
207
+ full_query = f"{sys_msg}\nUser Worry: {prompt_input}"
208
+
209
+ # 3. UI ํ‘œ์‹œ & AI ์š”์ฒญ
210
+ with st.chat_message("user"): st.write(prompt_input)
211
  with st.chat_message("assistant"):
212
+ with st.spinner(TXT["loading"]):
213
+ response = llm.get_ai_response(full_query, current_persona, user_lang=current_lang)
214
+ st.markdown(response)
215
+
216
+ # ๋ช…์‹ํ‘œ ์นด๋“œ ์ถœ๋ ฅ
217
+ st.info(f"{TXT['saju_result']}: {saju_data['desc']}")