Spaces:
Sleeping
Sleeping
File size: 4,712 Bytes
0baff67 e241071 0baff67 b610dd6 0baff67 b610dd6 e241071 afd04e2 e241071 b610dd6 e241071 b610dd6 199a182 e241071 199a182 e241071 de0e046 0baff67 8dfc2e8 0baff67 8dfc2e8 0baff67 ce377b0 0baff67 c3dd112 80fb948 0baff67 ce377b0 d112adc 7faf694 ce377b0 8dfc2e8 c1b4841 199a182 dd4b7a2 78d7075 2268456 c3dd112 70bd8b2 199a182 78d7075 dd4b7a2 78d7075 00d30a4 dd4b7a2 c3dd112 dd4b7a2 2268456 6c57520 d112adc 4edbb90 b4aa3b2 0f4b1a1 84b39ac b4aa3b2 7faf694 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
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("์๋ก์ด ๊ณ ๋ฏผ์ ์ดํด๋ณด๋ ค๋ฉด, ํ์ด์ง๋ฅผ ์๋ก๊ณ ์นจํด์ฃผ์ธ์.")
|