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("์ƒˆ๋กœ์šด ๊ณ ๋ฏผ์„ ์‚ดํŽด๋ณด๋ ค๋ฉด, ํŽ˜์ด์ง€๋ฅผ ์ƒˆ๋กœ๊ณ ์นจํ•ด์ฃผ์„ธ์š”.")