Spaces:
Sleeping
Sleeping
Update main.py
Browse files
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 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
cols = st.columns(6)
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 52 |
is_picked = i in st.session_state.picked_indices
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
for idx, card in enumerate(st.session_state.picked_cards):
|
| 64 |
-
with
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
with st.chat_message("user"): st.write(prompt)
|
| 87 |
with st.chat_message("assistant"):
|
| 88 |
-
with st.spinner(TXT["analyzing"]):
|
|
|
|
|
|
|
| 89 |
|
|
|
|
|
|
|
|
|
|
| 90 |
elif selected_mode == "shaman":
|
| 91 |
-
with st.expander("
|
| 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,
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
with st.chat_message("assistant"):
|
| 104 |
-
with st.spinner(TXT["loading"]):
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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']}")
|