Spaces:
Sleeping
Sleeping
Update main.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240import streamlit as stimport timefrom utils import tarot, prompts, llm, calculations# --- [1. ์ฑ ์ค์ ] ---st.set_page_config(page_title="AI ๋ง์ ์ ", page_icon="๐ฎ", layout="wide")# --- [2. ํ ๋ง ์คํ์ผ๋ง ์์ง] ---def apply_theme(mode):# ๊ตฌ๊ธ ํฐํธ ๋ก๋st.markdown("""<style>@import url('https://fonts.googleapis.com/css2?family=Nanum+Myeongjo:wght@700&family=Nanum+Pen+Script&family=Noto+Sans+KR:wght@400;700&display=swap');</style>""", unsafe_allow_html=True)themes = {"tarot": """/* ๐ฎ ํ๋ก ํ ๋ง */.stApp {background: linear-gradient(135deg, #1a0b2e 0%, #2d1b4e 100%);color: #e0d4fc;}h1, h2, h3 {font-family: 'Nanum Myeongjo', serif;color: #d4af37 !important;text-shadow: 0 0 10px #d4af37;}.stButton>button {background: linear-gradient(45deg, #4b0082, #8a2be2);color: white;border: 1px solid #d4af37;}.stTextInput>div>div>input, .stTextArea>div>div>textarea {background-color: #2d1b4e;color: white;border: 1px solid #d4af37;}""","fengshui": """/* ๐ก ํ์ ํ ๋ง */.stApp {background-color: #f5f5f0;background-image: url("https://www.transparenttextures.com/patterns/rice-paper.png");color: #3e2723;}h1, h2, h3 {font-family: 'Nanum Myeongjo', serif;color: #2e7d32 !important;}.stButton>button {background-color: #5d4037;color: #fff8e1;border-radius: 0px;}.stChatMessage {background-color: #ffffff;border: 1px solid #d7ccc8;}""","shaman": """/* ๐น ์ ์ง ํ ๋ง */.stApp {background-color: #1a0505;color: #ffcccc;}h1, h2, h3 {font-family: 'Nanum Pen Script', cursive;font-size: 3.5rem !important;color: #ff0000 !important;text-shadow: 2px 2px 0px #ffff00;}.stButton>button {background-color: #b71c1c;color: #ffff00;border: 2px solid #ffff00;font-family: 'Nanum Pen Script', cursive;font-size: 1.5rem;}.stTextInput>div>div>input {background-color: #330000;color: yellow;border: 2px solid red;}"""}style = themes.get(mode, themes["tarot"])st.markdown(f"<style>{style}</style>", unsafe_allow_html=True)# --- [3. ์ํ ์ด๊ธฐํ] ---if "messages" not in st.session_state:st.session_state.messages = []if "tarot_stage" not in st.session_state:st.session_state.tarot_stage = "input"if "picked_cards" not in st.session_state:st.session_state.picked_cards = []# --- [4. ์ฌ์ด๋๋ฐ UI] ---st.sidebar.title("โฉ๏ธ ๋ง์ ์ ์ ์ฅ")selected_mode = st.sidebar.radio("๋๊ตฌ๋ฅผ ์ฐพ์ผ์ จ์ต๋๊น?",("tarot", "fengshui", "shaman"),format_func=lambda x: prompts.get_persona(x)["name"])# ํ ๋ง ์ ์ฉ ๋ฐ ํ๋ฅด์๋ ๋ก๋apply_theme(selected_mode)current_persona = prompts.get_persona(selected_mode)st.sidebar.markdown("---")st.sidebar.success(f"ํ์ฌ ์ ์: **{current_persona['name']}**")st.sidebar.info(current_persona["description"])# --- [5. ๋ฉ์ธ UI ๋ก์ง] ---st.title(f"{current_persona['icon']} {current_persona['name']}")st.markdown("---")# ==========================================# ๐ ๋ชจ๋ A: ํ๋ก (Tarot)# ==========================================if selected_mode == "tarot":# 1๋จ๊ณ: ์ ๋ ฅif st.session_state.tarot_stage == "input":with st.form("tarot_form"):st.subheader("๋ฌด์์ด ๋น์ ์ ๋ฒ๋ํ๊ฒ ํฉ๋๊น?")topic = st.selectbox("๊ณ ๋ฏผ ์ฃผ์ ", ["๐ ์ฐ์ /์ฌ๋", "๐ฐ ๊ธ์ /์ฌ์ ", "๐ ํ์ /์ง๋ก", "๐ซ ์ธ๊ฐ๊ด๊ณ"])query = st.text_area("๊ตฌ์ฒด์ ์ธ ๊ณ ๋ฏผ์ ์ ์ด์ฃผ์ธ์", placeholder="์: ์ธํ๋ ์ฌ๋์ด ์๋๋ฐ ์ฐ๋ฝ์ด ์ ์์.")submitted = st.form_submit_button("์ด๋ช ์ ์นด๋ ๋ฝ์ผ๋ฌ ๊ฐ๊ธฐ")if submitted and query:st.session_state.user_query = f"[{topic}] {query}"st.session_state.tarot_stage = "picking"st.rerun()# 2๋จ๊ณ: ๋ฝ๊ธฐelif st.session_state.tarot_stage == "picking":st.info(f"๋น์ ์ ๊ณ ๋ฏผ: **{st.session_state.user_query}**")st.write("โผ ์๋ ๋ฒํผ์ ๋๋ฌ ์ด๋ช ์ ํ์ธํ์ธ์ โผ")if st.button("๐ด ์ ์คํ๊ฒ ์นด๋ 3์ฅ ๋ฝ๊ธฐ", type="primary", use_container_width=True):with st.spinner("์ด๋ช ์ ์ ์งํ๋ ์ค..."):time.sleep(1.5)st.session_state.picked_cards = tarot.draw_tarot_cards(3)st.session_state.tarot_stage = "result"st.rerun()# 3๋จ๊ณ: ๊ฒฐ๊ณผelif st.session_state.tarot_stage == "result":cols = st.columns(3)positions = ["๊ณผ๊ฑฐ", "ํ์ฌ", "๋ฏธ๋"]for idx, card in enumerate(st.session_state.picked_cards):with cols[idx]:st.caption(positions[idx])st.image(tarot.get_card_image(card["name"]), caption=card["name"])if "ai_response" not in st.session_state:with st.spinner("ํด์ ์ค..."):st.session_state.ai_response = llm.get_ai_response(st.session_state.user_query, current_persona, st.session_state.picked_cards)st.markdown(st.session_state.ai_response)if st.button("๐ ๋ค์ ํ๊ธฐ"):st.session_state.tarot_stage = "input"del st.session_state["ai_response"]st.rerun()# ==========================================# ๐ก ๋ชจ๋ B: ํ์์ง๋ฆฌ (Feng Shui)# ==========================================elif selected_mode == "fengshui":with st.container():st.info("์ ํต ๋ณธ๋ช ๊ถ๋ฒ(Life Gua)์ ์ํด ๊ทํ์ ๊ธธํ ๋ฐฉ์๋ฅผ ๊ณ์ฐํฉ๋๋ค.")c1, c2 = st.columns(2)with c1:birth_year = st.number_input("๊ฐ์ฅ(์ง์ฃผ์ธ) ์ถ์์ฐ๋", 1950, 2025, 1990)gender = st.radio("์ฑ๋ณ", ["๋จ์ฑ", "์ฌ์ฑ"])with c2:direction = st.selectbox("ํ์ฌ ํ๊ด ๋ฐฉํฅ", ["๋ถ", "๋ถ๋", "๋", "๋จ๋", "๋จ", "๋จ์", "์", "๋ถ์"])room_type = st.selectbox("์ง๋จํ ๊ณต๊ฐ", ["์นจ์ค", "๊ฑฐ์ค", "์์ฌ"])if prompt := st.chat_input("๊ตฌ์กฐ์ ๋ํด ๋ฌผ์ด๋ณด์ธ์ (์: ํ๊ด์ ๊ฑฐ์ธ์ด ์์ด)"):# 1. ๊ณ์ฐ ์คํfengshui_data = calculations.get_fengshui_info(birth_year, gender)# 2. AI์๊ฒ ๋๊ธธ ์ ๋ณด ๊ตฌ์ฑsys_msg = f"""[๋ฐ์ดํฐ ๋ถ์]- ๋ณธ๋ช ๊ถ: {fengshui_data['gua_number']} ({fengshui_data['group']})- ๊ธธ(Good) ๋ฐฉ์: {fengshui_data['good_direction']}- ํ(Bad) ๋ฐฉ์: {fengshui_data['bad_direction']}- ํ์ฌ ํ๊ด: {direction}์ชฝ"""full_query = f"{sys_msg}\n์ฌ์ฉ์ ์ง๋ฌธ: {prompt}\n\n์ ๋ฐ์ดํฐ๋ฅผ ๊ทผ๊ฑฐ๋ก ๋ ผ๋ฆฌ์ ์ผ๋ก ์กฐ์ธํด."with st.chat_message("user"): st.write(prompt)with st.chat_message("assistant"):with st.spinner("๋ฐฉ์๋ฅผ ๊ณ์ฐํ๋ ์ค..."):response = llm.get_ai_response(full_query, current_persona)st.write(response)# ๋ถ์ํ ์ถ๋ ฅwith st.expander("๐ ์ ๋ฐ ๋ถ์ํ ๋ณด๊ธฐ", expanded=True):st.success(f"โ ์ถ์ฒ ๋ฐฉํฅ: {fengshui_data['good_direction']}")st.error(f"๐ซ ํผํ ๋ฐฉํฅ: {fengshui_data['bad_direction']}")# ==========================================# ๐น ๋ชจ๋ C: ์ ์ (Shaman)# ==========================================elif selected_mode == "shaman":with st.container():st.warning("๊ฑฐ์ง์ผ๋ก ์ ์ผ๋ฉด ์ ๊ด ์ ๋์จ๋ค! ๋๋ฐ๋ก ์ ์ด๋ผ.")c1, c2 = st.columns(2)with c1:birth_year = st.number_input("ํ์ด๋ ์ฐ๋", 1960, 2025, 1995)with c2:prompt_input = st.text_input("๋ญ๊ฐ ๊ถ๊ธํ๋?", placeholder="์ฌํด ๊ฒฐํผ์ด ์ด๋?")if st.button("์ ๊ด ํ์ธ") and prompt_input:# 1. ์ฌ์ฃผ ๊ณ์ฐ ์คํsaju_data = calculations.get_ganji(birth_year)# 2. AI ํ๋กฌํํธ ๊ตฌ์ฑsys_msg = f"""[๋ด๋ด์ ์ฌ์ฃผ]- {saju_data['year_ganji']} ({saju_data['animal']}๋ )- ํ๊ณ ๋ ๊ธฐ์ด: {saju_data['element']} ({saju_data['color']}์)"""full_query = f"{sys_msg}\n๊ณ ๋ฏผ: {prompt_input}\n\n๋ด๋ด์๋ '{saju_data['element']}' ๊ธฐ์ด์ด๋ค. ์ด์ ๋น๋์ด ํธํต์น๋ฉฐ ์กฐ์ธํด๋ผ."st.divider()st.write(f"๐ฃ๏ธ **๋:** {prompt_input}")with st.spinner("๋ฐฉ์ธ ํ๋๋ ์ค... ๐"):response = llm.get_ai_response(full_query, current_persona)st.markdown(f"**๐น ๋ฌด๋น:** {response}")st.info(f"๐ ๋ช ์: **{saju_data['year_ganji']} ({saju_data['animal']})** - ๋๋ **{saju_data['element']}**์ ๊ธฐ์ด์ด์ผ!")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155import streamlit as stimport timefrom utils import tarot, prompts, llm, calculations, lang # <--- lang ์ถ๊ฐ# --- [1. ์ฑ ์ค์ ] ---st.set_page_config(page_title="Global AI Pantheon", page_icon="๐ฎ", layout="wide")# --- [2. ํ ๋ง ์คํ์ผ๋ง] (๊ธฐ์กด ์ฝ๋ ์ ์ง - ์๋ต) ---def apply_theme(mode):# (์ด์ ๋ต๋ณ์ CSS ์ฝ๋ ๊ทธ๋๋ก ์ฌ์ฉํ์ธ์)# ํฐํธ ๋ก๋ ๋ถ๋ถ๋ง ์กฐ๊ธ ๋ณด๊ฐํด์ ๋ค๊ตญ์ด ์ง์ํ๊ฒst.markdown("""<style>@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&display=swap');</style>""", unsafe_allow_html=True)# ... (๋๋จธ์ง CSS ํ ๋ง ์ฝ๋๋ ๋์ผํ๋ฏ๋ก ์๋ต) ...pass# --- [3. ์ํ ์ด๊ธฐํ] ---if "messages" not in st.session_state: st.session_state.messages = []if "tarot_stage" not in st.session_state: st.session_state.tarot_stage = "input"if "picked_cards" not in st.session_state: st.session_state.picked_cards = []# ==========================================# ๐ ์ธ์ด ์ ํ (์ฌ์ด๋๋ฐ ์ต์๋จ)# ==========================================st.sidebar.markdown("### ๐ Language")current_lang = st.sidebar.selectbox("Select Language",["ํ๊ตญ์ด", "English", "ไธญๆ", "ๆฅๆฌ่ช"],label_visibility="collapsed")# ์ ํ๋ ์ธ์ด ํฉ ๊ฐ์ ธ์ค๊ธฐTXT = lang.STRINGS[current_lang]# --- [4. ๋ชจ๋ ์ ํ UI] ---st.sidebar.title(TXT["sidebar_title"])# ํ๋ฅด์๋ ์ด๋ฆ๋ ์ธ์ด๋ณ๋ก ๋ณด์ฌ์ฃผ๊ธฐdef get_persona_name(key):return TXT["personas"][key]selected_mode = st.sidebar.radio(TXT["select_persona"],("tarot", "fengshui", "shaman"),format_func=get_persona_name)apply_theme(selected_mode)current_persona = prompts.get_persona(selected_mode)st.sidebar.markdown("---")# ์ค๋ช ๋ ๋ฒ์ญ๋ ๊ฑธ๋ก ํ์st.sidebar.info(TXT["desc"][selected_mode])# --- [5. ๋ฉ์ธ UI ๋ก์ง] ---st.title(f"{current_persona['icon']} {get_persona_name(selected_mode)}")st.markdown("---")# ==========================================# ๐ ๋ชจ๋ A: ํ๋ก# ==========================================if selected_mode == "tarot":if st.session_state.tarot_stage == "input":with st.form("tarot_form"):query = st.text_area(TXT["input_label"])submitted = st.form_submit_button(TXT["btn_submit"])if submitted and query:st.session_state.user_query = queryst.session_state.tarot_stage = "picking"st.rerun()elif st.session_state.tarot_stage == "picking":st.info(f"Your Worry: **{st.session_state.user_query}**")if st.button("๐ด Draw 3 Cards", type="primary", use_container_width=True):with st.spinner(TXT["loading"]):time.sleep(1.5)st.session_state.picked_cards = tarot.draw_tarot_cards(3)st.session_state.tarot_stage = "result"st.rerun()elif st.session_state.tarot_stage == "result":cols = st.columns(3)for idx, card in enumerate(st.session_state.picked_cards):with cols[idx]:st.image(tarot.get_card_image(card["name"]), caption=card["name"])if "ai_response" not in st.session_state:with st.spinner(TXT["analyzing"]):# ์ธ์ด ์ ๋ณด(current_lang)๋ฅผ ํจ๊ป ๋๊น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)st.subheader(TXT["result_title"])st.markdown(st.session_state.ai_response)if st.button("๐ Retry"):st.session_state.tarot_stage = "input"del st.session_state["ai_response"]st.rerun()# ==========================================# ๐ก ๋ชจ๋ B: ํ์์ง๋ฆฌ# ==========================================elif selected_mode == "fengshui":with st.container():c1, c2 = st.columns(2)with c1:birth_year = st.number_input("Year of Birth", 1950, 2025, 1990)gender = st.radio("Gender", ["๋จ์ฑ", "์ฌ์ฑ"]) # ๊ณ์ฐ์ ๋๋ฌธ์ ๊ฐ์ ํ๊ธ๋ก ์ ์งํ๋ ํ์๋ ๋ฐ๊ฟ ์ ์์with c2:direction = st.selectbox("Door Direction", ["๋ถ", "๋ถ๋", "๋", "๋จ๋", "๋จ", "๋จ์", "์", "๋ถ์"])if prompt := st.chat_input(TXT["input_label"]):fengshui_data = calculations.get_fengshui_info(birth_year, gender)# ์์คํ ํ๋กฌํํธ์ฉ ๋ฐ์ดํฐ ๊ตฌ์ฑsys_msg = f"[Data]: {fengshui_data}, Current Door: {direction}"full_query = f"{sys_msg}\nUser Question: {prompt}"with st.chat_message("user"): st.write(prompt)with st.chat_message("assistant"):with st.spinner(TXT["analyzing"]):response = llm.get_ai_response(full_query, current_persona, user_lang=current_lang)st.write(response)# ==========================================# ๐น ๋ชจ๋ C: ์ ์ # ==========================================elif selected_mode == "shaman":with st.container():c1, c2 = st.columns(2)with c1:birth_year = st.number_input("Birth Year", 1960, 2025, 1995)with c2:prompt_input = st.text_input(TXT["input_label"])if st.button(TXT["btn_submit"]) and prompt_input:saju_data = calculations.get_ganji(birth_year)sys_msg = f"[Saju Data]: Year {saju_data['year_ganji']}, Element {saju_data['element']}"full_query = f"{sys_msg}\nUser Worry: {prompt_input}"st.divider()with st.chat_message("user"): st.write(prompt_input)with st.chat_message("assistant"):with st.spinner(TXT["loading"]):response = llm.get_ai_response(full_query, current_persona, user_lang=current_lang)st.markdown(response)
main.py+73-158