Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import gspread | |
| from oauth2client.service_account import ServiceAccountCredentials | |
| from datetime import datetime | |
| # Set page title and favicon | |
| st.set_page_config(page_title="๊ณ ๋ฏผ ํด๊ฒฐ์ฌ", page_icon=":sunglasses:") | |
| # Google Sheets ์ธ์ฆ ์ค์ | |
| scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/spreadsheets", | |
| "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"] | |
| creds = ServiceAccountCredentials.from_json_keyfile_name("analog-marking-416002-e369840763fa.json", scope) | |
| client = gspread.authorize(creds) | |
| # Google Sheets ๋ฌธ์ ์ด๊ธฐ | |
| sheet = client.open("generation_streamlit_0302").sheet1 | |
| # ์ฌ์ฉ์ ์กฐ์ธ ๋ฐ์ดํฐ๋ฅผ Google Sheets ๋ฌธ์์ ์ถ๊ฐํ๋ ํจ์ | |
| def record_advice(experience, concern, advice): | |
| timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
| sheet.append_row([timestamp, experience, concern, advice]) | |
| # ์คํ์ผ๋ง์ ์ํ CSS | |
| st.markdown(""" | |
| <style> | |
| .header { | |
| font-size: 30px; | |
| font-weight: bold; | |
| margin-bottom: 20px; | |
| color: #333; /* Dark gray color */ | |
| padding: 10px; | |
| border-radius: 10px; | |
| } | |
| .description-box { | |
| background-color: #f0f0f0; /* Light gray background */ | |
| padding: 10px; | |
| border-radius: 10px; | |
| margin-bottom: 20px; /* ์กฐ์ ๋ ์ฌ๋ฐฑ */ | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # ํค๋ ํ์ | |
| st.markdown('<div class="header"> ํ์ฅ๋ค ๊ณ ๋ฏผ์ ์กฐ์ธ ํ๋ง๋ โ๐ป </div>', unsafe_allow_html=True) | |
| # ์ฌ์ฉ์ ์๋ด ๋ฌธ๊ตฌ ํ์ | |
| st.markdown(""" | |
| <div class="description-box"> | |
| <p> How to use </br> | |
| 1. ์กฐ์ธ์ ํด์ฃผ๊ณ ์ถ์ ํ์ฅ ์ฐ์ฐจ๋ฅผ ๊ณจ๋ผ์ฃผ์ธ์. </br> | |
| 2. ๋ฒํผ์ ํด๋ฆญํ๋ฉด ์ ํ๋ ์ฐ์ฐจ์ ๊ณ ๋ฏผ ์ค ํ๋๊ฐ ๋๋ค์ผ๋ก ํ์๋ฉ๋๋ค. </br> | |
| 3. ๊ณ ๋ฏผ ์๋์ ์์นํ ์ ๋ ฅ ์ฐฝ์ ์กฐ์ธ์ ์์ฑํ ํ, '์กฐ์ธ ์ ์ถํ๊ธฐ' ๋ฒํผ์ ๋๋ฌ์ฃผ์ธ์. </br> | |
| 4. ์๋์ ์ฑ๊ณต์ ์ผ๋ก ์ ์ถ๋์๋ค๋ ์ด๋ก์ ๋ฉ์์ง๊ฐ ๋จ๋ ๊ฒ์ ํ์ธํด์ฃผ์ธ์. </br> | |
| </p> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Load Excel file into DataFrame | |
| df = pd.read_excel("painpoint21.xlsx") | |
| # ๋ฒํผ ์ปจํ ์ด๋ ์์ฑ | |
| buttons = st.columns(3) | |
| experience_levels = ['์ ์ฐ์ฐจ ํ์ฅ', '์ค๊ฐ์ฐ์ฐจ ํ์ฅ', '๊ณ ์ฐ์ฐจ ํ์ฅ'] | |
| selected_concern = None | |
| # ๋ฒํผ ์์ฑ ๋ฐ ์ด๋ฒคํธ ์ฒ๋ฆฌ | |
| for i, experience_level in enumerate(experience_levels): | |
| with buttons[i]: | |
| if st.session_state.get(experience_level): | |
| st.button(experience_level, disabled=True) # ํ์ฑํ๋ ๋ฒํผ ๋นํ์ฑํ ํ์ | |
| elif st.button(experience_level): | |
| # ์ ํ๋ experience_level์ ์ ์ฅ | |
| st.session_state['experience'] = experience_level # ์ด ๋ถ๋ถ์ด ์ถ๊ฐ๋จ | |
| st.session_state[experience_level] = True | |
| with st.spinner("๊ณ ๋ฏผ์ ๋๋ค์ผ๋ก ๋ฝ๋ ์ค์ ๋๋ค. ์ ์ ๊ธฐ๋ค๋ ค์ฃผ์ธ์..."): | |
| concerns = df[experience_level].dropna() | |
| if not concerns.empty: | |
| selected_concern = concerns.sample(n=1).iloc[0] | |
| st.session_state['selected_concern'] = selected_concern | |
| else: | |
| st.error(f"{experience_level}์ ํด๋นํ๋ ๊ณ ๋ฏผ์ด ์์ต๋๋ค.") | |
| # ์ ํ๋ ๊ณ ๋ฏผ ๋ด์ฉ์ ์ ์ฒด ํ๋ฉด์ ํ์ | |
| if 'selected_concern' in st.session_state: | |
| st.markdown(f"<h3 style='font-size: 20px;'>์ ํ๋ ๊ณ ๋ฏผ:</h3>", unsafe_allow_html=True) | |
| st.markdown(f"<div style='white-space: pre-wrap; word-wrap: break-word; color: navy;'>{st.session_state['selected_concern']}</div>", unsafe_allow_html=True) | |
| # ๊ณ ๋ฏผ๊ณผ ์กฐ์ธ ์์ฒญ ์ฌ์ด์ ๊ณต๊ฐ ์ถ๊ฐ | |
| st.write("") | |
| if 'selected_concern' in st.session_state: | |
| advice = st.text_area(f"### ๊ณ ๋ฏผ์ ๋ํ ์กฐ์ธ์ ์ ๋ ฅํด์ฃผ์ธ์:", key="advice_input", value="", height=200) # text_area์ ๋์ด๋ฅผ ์กฐ์ ํฉ๋๋ค. | |
| st.write("<style>div[data-testid='stButton']>button {font-size: 18px;}</style>", unsafe_allow_html=True) # ๋ฒํผ์ ๊ธ์ ํฌ๊ธฐ๋ฅผ ์กฐ์ ํฉ๋๋ค. | |
| submit_advice_button = st.button("์กฐ์ธ ์ ์ถํ๊ธฐ") | |
| if submit_advice_button and advice.strip(): | |
| record_advice(st.session_state['experience'], st.session_state['selected_concern'], advice) | |
| st.success("์กฐ์ธ์ด ์ฑ๊ณต์ ์ผ๋ก ์ ์ถ๋์์ต๋๋ค!") | |
| # ์ฌ์ฉ์๊ฐ ์กฐ์ธ์ ์ ์ถํ ํ ์ ๋ ฅ ํ๋๋ฅผ ๋น์ฐ๋ ๋์ , ์ฌ์ฉ์์๊ฒ ํ์ด์ง ์๋ก๊ณ ์นจ์ ์ ๋ | |
| st.markdown("์๋ก์ด ๊ณ ๋ฏผ์ ์ดํด๋ณด๋ ค๋ฉด, ํ์ด์ง๋ฅผ ์๋ก๊ณ ์นจํด์ฃผ์ธ์.") | |