Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,238 +1,105 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import time
|
|
|
|
| 3 |
from utils import tarot, prompts, llm, calculations, lang
|
| 4 |
|
| 5 |
-
|
| 6 |
-
st.set_page_config(page_title="AI Pantheon", page_icon="🔮", layout="wide")
|
| 7 |
|
| 8 |
-
# --- [2. 테마 스타일링 엔진 (CSS 완전체)] ---
|
| 9 |
def apply_theme(mode):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
</style>
|
| 15 |
-
""", unsafe_allow_html=True)
|
| 16 |
-
|
| 17 |
themes = {
|
| 18 |
-
"tarot": ""
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
background: linear-gradient(135deg, #1a0b2e 0%, #2d1b4e 100%);
|
| 22 |
-
color: #e0d4fc;
|
| 23 |
-
}
|
| 24 |
-
h1, h2, h3 {
|
| 25 |
-
font-family: 'Nanum Myeongjo', 'Noto Serif JP', serif;
|
| 26 |
-
color: #d4af37 !important;
|
| 27 |
-
text-shadow: 0 0 10px #d4af37;
|
| 28 |
-
}
|
| 29 |
-
.stButton>button {
|
| 30 |
-
background: linear-gradient(45deg, #4b0082, #8a2be2);
|
| 31 |
-
color: white;
|
| 32 |
-
border: 1px solid #d4af37;
|
| 33 |
-
border-radius: 8px;
|
| 34 |
-
}
|
| 35 |
-
.stTextInput>div>div>input, .stTextArea>div>div>textarea {
|
| 36 |
-
background-color: #2d1b4e;
|
| 37 |
-
color: white;
|
| 38 |
-
border: 1px solid #d4af37;
|
| 39 |
-
}
|
| 40 |
-
""",
|
| 41 |
-
"fengshui": """
|
| 42 |
-
/* 🏡 풍수: 한지와 나무 */
|
| 43 |
-
.stApp {
|
| 44 |
-
background-color: #f5f5f0;
|
| 45 |
-
background-image: url("https://www.transparenttextures.com/patterns/rice-paper.png");
|
| 46 |
-
color: #3e2723;
|
| 47 |
-
}
|
| 48 |
-
h1, h2, h3 {
|
| 49 |
-
font-family: 'Nanum Myeongjo', 'Noto Serif JP', serif;
|
| 50 |
-
color: #2e7d32 !important;
|
| 51 |
-
}
|
| 52 |
-
.stButton>button {
|
| 53 |
-
background-color: #5d4037;
|
| 54 |
-
color: #fff8e1;
|
| 55 |
-
border-radius: 0px;
|
| 56 |
-
}
|
| 57 |
-
.stChatMessage {
|
| 58 |
-
background-color: #ffffff;
|
| 59 |
-
border: 1px solid #d7ccc8;
|
| 60 |
-
}
|
| 61 |
-
""",
|
| 62 |
-
"shaman": """
|
| 63 |
-
/* 👹 점집: 강렬한 빨강/검정 */
|
| 64 |
-
.stApp {
|
| 65 |
-
background-color: #1a0505;
|
| 66 |
-
color: #ffcccc;
|
| 67 |
-
}
|
| 68 |
-
h1, h2, h3 {
|
| 69 |
-
font-family: 'Nanum Pen Script', cursive;
|
| 70 |
-
font-size: 3.5rem !important;
|
| 71 |
-
color: #ff0000 !important;
|
| 72 |
-
text-shadow: 2px 2px 0px #ffff00;
|
| 73 |
-
}
|
| 74 |
-
.stButton>button {
|
| 75 |
-
background-color: #b71c1c;
|
| 76 |
-
color: #ffff00;
|
| 77 |
-
border: 2px solid #ffff00;
|
| 78 |
-
font-family: 'Nanum Pen Script', cursive;
|
| 79 |
-
font-size: 1.5rem;
|
| 80 |
-
}
|
| 81 |
-
.stTextInput>div>div>input {
|
| 82 |
-
background-color: #330000;
|
| 83 |
-
color: yellow;
|
| 84 |
-
border: 2px solid red;
|
| 85 |
-
}
|
| 86 |
-
"""
|
| 87 |
}
|
| 88 |
-
|
| 89 |
-
style = themes.get(mode, themes["tarot"])
|
| 90 |
-
st.markdown(f"<style>{style}</style>", unsafe_allow_html=True)
|
| 91 |
|
| 92 |
-
# --- [3. 상태 초기화] ---
|
| 93 |
-
if "messages" not in st.session_state: st.session_state.messages = []
|
| 94 |
if "tarot_stage" not in st.session_state: st.session_state.tarot_stage = "input"
|
|
|
|
| 95 |
if "picked_cards" not in st.session_state: st.session_state.picked_cards = []
|
| 96 |
|
| 97 |
-
# ==========================================
|
| 98 |
-
# 🌐 언어 선택 (사이드바 최상단)
|
| 99 |
-
# ==========================================
|
| 100 |
st.sidebar.markdown("### 🌐 Language")
|
| 101 |
-
current_lang = st.sidebar.selectbox(
|
| 102 |
-
|
| 103 |
-
["한국어", "English", "中文", "日本語"],
|
| 104 |
-
label_visibility="collapsed"
|
| 105 |
-
)
|
| 106 |
-
TXT = lang.STRINGS[current_lang] # 언어 팩 로드
|
| 107 |
|
| 108 |
-
# --- [4. 페르소나 모드 선택] ---
|
| 109 |
st.sidebar.title(TXT["sidebar_title"])
|
| 110 |
-
|
| 111 |
-
def get_persona_name(key):
|
| 112 |
-
return TXT["personas"][key]
|
| 113 |
-
|
| 114 |
-
selected_mode = st.sidebar.radio(
|
| 115 |
-
TXT["select_persona"],
|
| 116 |
-
("tarot", "fengshui", "shaman"),
|
| 117 |
-
format_func=get_persona_name
|
| 118 |
-
)
|
| 119 |
-
|
| 120 |
-
# 테마 적용
|
| 121 |
apply_theme(selected_mode)
|
| 122 |
current_persona = prompts.get_persona(selected_mode)
|
| 123 |
-
|
| 124 |
-
st.sidebar.markdown("---")
|
| 125 |
st.sidebar.info(TXT["desc"][selected_mode])
|
| 126 |
|
| 127 |
-
|
| 128 |
-
st.title(f"{current_persona['icon']} {get_persona_name(selected_mode)}")
|
| 129 |
st.markdown("---")
|
| 130 |
|
| 131 |
-
# ==========================================
|
| 132 |
-
# 🃏 모드 A: 타로 (Tarot)
|
| 133 |
-
# ==========================================
|
| 134 |
if selected_mode == "tarot":
|
| 135 |
-
# 1단계: 입력
|
| 136 |
if st.session_state.tarot_stage == "input":
|
| 137 |
with st.form("tarot_form"):
|
| 138 |
topic = st.selectbox(TXT["tarot_topic"], ["Love", "Money", "Career", "Health"])
|
| 139 |
query = st.text_area(TXT["input_label"], placeholder=TXT["tarot_placeholder"])
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
if submitted and query:
|
| 143 |
st.session_state.user_query = f"[{topic}] {query}"
|
| 144 |
st.session_state.tarot_stage = "picking"
|
|
|
|
| 145 |
st.rerun()
|
| 146 |
-
|
| 147 |
-
# 2단계: 뽑기
|
| 148 |
elif st.session_state.tarot_stage == "picking":
|
| 149 |
-
st.
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
st.session_state.tarot_stage = "result"
|
| 155 |
st.rerun()
|
| 156 |
-
|
| 157 |
-
# 3단계: 결과
|
| 158 |
elif st.session_state.tarot_stage == "result":
|
| 159 |
cols = st.columns(3)
|
| 160 |
for idx, card in enumerate(st.session_state.picked_cards):
|
| 161 |
-
with cols[idx]:
|
| 162 |
-
st.image(tarot.get_card_image(card["name"]), caption=card["name"])
|
| 163 |
-
|
| 164 |
if "ai_response" not in st.session_state:
|
| 165 |
with st.spinner(TXT["analyzing"]):
|
| 166 |
-
st.session_state.ai_response = llm.get_ai_response(
|
| 167 |
-
st.session_state.user_query,
|
| 168 |
-
current_persona,
|
| 169 |
-
st.session_state.picked_cards,
|
| 170 |
-
user_lang=current_lang
|
| 171 |
-
)
|
| 172 |
-
|
| 173 |
-
st.subheader(TXT["result_title"])
|
| 174 |
st.markdown(st.session_state.ai_response)
|
| 175 |
-
|
| 176 |
if st.button(TXT["retry_btn"]):
|
| 177 |
st.session_state.tarot_stage = "input"
|
| 178 |
del st.session_state["ai_response"]
|
| 179 |
st.rerun()
|
| 180 |
|
| 181 |
-
# ==========================================
|
| 182 |
-
# 🏡 모드 B: 풍수지리 (Feng Shui)
|
| 183 |
-
# ==========================================
|
| 184 |
elif selected_mode == "fengshui":
|
| 185 |
-
with st.
|
| 186 |
-
st.caption(TXT["fengshui_info"])
|
| 187 |
c1, c2 = st.columns(2)
|
| 188 |
with c1:
|
| 189 |
birth_year = st.number_input(TXT["birth_year"], 1950, 2025, 1990)
|
| 190 |
-
|
| 191 |
-
gender_label = st.radio(TXT["gender"], ["Male", "Female"])
|
| 192 |
-
gender_val = "남성" if gender_label == "Male" else "여성"
|
| 193 |
with c2:
|
| 194 |
-
|
| 195 |
-
|
| 196 |
if prompt := st.chat_input(TXT["input_label"]):
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
# 2. AI 요청
|
| 201 |
-
sys_msg = f"[Data]: {fengshui_data}, Current Door: {direction}"
|
| 202 |
-
full_query = f"{sys_msg}\nUser Question: {prompt}"
|
| 203 |
-
|
| 204 |
with st.chat_message("user"): st.write(prompt)
|
| 205 |
with st.chat_message("assistant"):
|
| 206 |
-
with st.spinner(TXT["analyzing"]):
|
| 207 |
-
response = llm.get_ai_response(full_query, current_persona, user_lang=current_lang)
|
| 208 |
-
st.write(response)
|
| 209 |
|
| 210 |
-
# ==========================================
|
| 211 |
-
# 👹 모드 C: 신점 (Shaman)
|
| 212 |
-
# ==========================================
|
| 213 |
elif selected_mode == "shaman":
|
| 214 |
-
with st.
|
| 215 |
-
st.
|
| 216 |
c1, c2 = st.columns(2)
|
| 217 |
with c1:
|
| 218 |
-
|
|
|
|
| 219 |
with c2:
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
# 2. AI 요청
|
| 227 |
-
sys_msg = f"[Saju Data]: Year {saju_data['year_ganji']}, Element {saju_data['element']}"
|
| 228 |
-
full_query = f"{sys_msg}\nUser Worry: {prompt_input}"
|
| 229 |
-
|
| 230 |
-
st.divider()
|
| 231 |
-
with st.chat_message("user"): st.write(prompt_input)
|
| 232 |
with st.chat_message("assistant"):
|
| 233 |
-
with st.spinner(TXT["loading"]):
|
| 234 |
-
|
| 235 |
-
st.markdown(response)
|
| 236 |
-
|
| 237 |
-
# 명식표 출력
|
| 238 |
-
st.info(f"📜 {TXT['saju_result']}: {saju_data['year_ganji']} ({saju_data['animal']})")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
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']})")
|
|
|
|
|
|
|
|
|
|
|
|