soojeongcrystal commited on
Commit
8dfc2e8
ยท
verified ยท
1 Parent(s): 068abb2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -30
app.py CHANGED
@@ -10,7 +10,7 @@ st.set_page_config(page_title="๊ณ ๋ฏผ ํ•ด๊ฒฐ์‚ฌ", page_icon=":sunglasses:")
10
  # Google Sheets ์ธ์ฆ ์„ค์ •
11
  scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/spreadsheets",
12
  "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]
13
- creds = ServiceAccountCredentials.from_json_keyfile_name("analog-marking-416002-e369840763fa.json", scope)
14
  client = gspread.authorize(creds)
15
 
16
  # Google Sheets ๋ฌธ์„œ ์—ด๊ธฐ
@@ -21,19 +21,18 @@ def record_advice(concern, advice):
21
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
22
  sheet.append_row([timestamp, concern, advice])
23
 
24
- # ์Šคํƒ€์ผ๋ง์„ ์œ„ํ•œ CSS
25
  st.markdown("""
26
  <style>
27
  .header {
28
  font-size: 30px;
29
  font-weight: bold;
30
  margin-bottom: 20px;
31
- color: #333;
32
  padding: 10px;
33
  border-radius: 10px;
34
  }
35
  .description-box {
36
- background-color: #f0f0f0;
37
  padding: 10px;
38
  border-radius: 10px;
39
  margin-bottom: 10px;
@@ -41,48 +40,73 @@ st.markdown("""
41
  </style>
42
  """, unsafe_allow_html=True)
43
 
44
- # ํ—ค๋” ํ‘œ์‹œ
45
  st.markdown('<div class="header">๐Ÿ† ๋‹ค๋ฅธ ํŒ€์žฅ ๊ณ ๋ฏผํ•ด๊ฒฐ ๋„์™€์ฃผ๊ธฐ ๐Ÿ† </div>', unsafe_allow_html=True)
46
 
47
- # ์„ค๋ช… ํ‘œ์‹œ
48
  st.markdown("""
49
  <div class="description-box">
50
- <p> How to use </br> 1. ์•„๋ž˜์—์„œ ์กฐ์–ธ์„ ์ œ๊ณตํ•  ํŒ€์žฅ์˜ ์—ฐ์ฐจ๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”. </br> 2. [๊ณ ๋ฏผ ํ™•์ธ]๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์•„๋ž˜์— ๊ณ ๋ฏผ ๋‚ด์šฉ๊ณผ ์กฐ์–ธ ์ž‘์„ฑ์ฐฝ์ด ๋œน๋‹ˆ๋‹ค. </br> 3. ๋‹ค์‹œ ํ•œ๋ฒˆ [๊ณ ๋ฏผ ํ™•์ธ]๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์ƒˆ๋กœ์šด ๊ณ ๋ฏผ์ด ๋‚˜์˜ต๋‹ˆ๋‹ค </br> </p>
51
  </div>
52
  """, unsafe_allow_html=True)
53
 
54
- # Excel ํŒŒ์ผ์„ DataFrame์œผ๋กœ ๋กœ๋“œ
55
  df = pd.read_excel("painpoint2.xlsx")
56
 
57
- # ์—ฐ์ฐจ ์„ ํƒ ์˜ต์…˜ ์ •์˜
58
  seniority_options = ['์ €์—ฐ์ฐจ ํŒ€์žฅ', '์ค‘๊ฐ„์—ฐ์ฐจ ํŒ€์žฅ', '๊ณ ์—ฐ์ฐจ ํŒ€์žฅ']
59
 
60
- # ์—ฐ์ฐจ ์„ ํƒ ๋“œ๋กญ๋‹ค์šด ์ถ”๊ฐ€
61
- st.subheader("์กฐ์–ธํ•ด์ค„ ์—ฐ์ฐจ ์„ ํƒํ•˜๊ธฐ:")
62
- selected_experience = st.selectbox(" ", seniority_options)
 
 
 
 
 
 
 
 
 
63
 
64
- # ๊ณ ๋ฏผ ํ™•์ธ ๋ฒ„ํŠผ ์ถ”๊ฐ€
65
- submit_button_left = st.button("๊ณ ๋ฏผ ํ™•์ธ")
66
 
67
- # ๊ณ ๋ฏผ ํ‘œ์‹œ ๋ฐ ์กฐ์–ธ ์„น์…˜
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  if submit_button_left:
69
  st.subheader("์„ ํƒ๋œ ๊ณ ๋ฏผ์€?")
70
- selected_row = df[df['์—ฐ์ฐจ'] == selected_experience].sample(n=1).iloc[0] # ์—ฐ์ฐจ์— ๋”ฐ๋ฅธ ๊ณ ๋ฏผ ํ•„ํ„ฐ๋ง
71
- st.session_state['selected_concern'] = selected_row['๊ณ ๋ฏผ']
72
  with st.expander("๊ณ ๋ฏผ ๋‚ด์šฉ๋ณด๊ธฐ", expanded=True):
73
- st.markdown(selected_row['๊ณ ๋ฏผ'])
74
 
75
- # ์กฐ์–ธ ์ถ”๊ฐ€ ์„น์…˜
76
  st.subheader("๊ณ ๋ฏผ ์กฐ์–ธํ•ด์ฃผ๊ธฐ")
77
- advice = st.text_area("์—ฌ๊ธฐ์— ์กฐ์–ธ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”", height=100)
78
-
79
- # ์กฐ์–ธ ์ œ์ถœ ๋ฒ„ํŠผ ์ฒ˜๋ฆฌ
80
- submit_button_right = st.button("์กฐ์–ธ ์ œ์ถœํ•˜๊ธฐ")
81
- if submit_button_right and 'selected_concern' in st.session_state:
82
- concern = st.session_state['selected_concern']
83
- if advice.strip(): # ์กฐ์–ธ์ด ๋น„์–ด์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ
84
- record_advice(concern, advice.strip())
85
- st.success("์กฐ์–ธ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ œ์ถœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!")
86
- del st.session_state['selected_concern'] # ์ œ์ถœ ํ›„ ์„ ํƒ๋œ ๊ณ ๋ฏผ ์ดˆ๊ธฐํ™”
 
 
 
 
 
87
  else:
88
- st.error("์กฐ์–ธ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.")
 
10
  # Google Sheets ์ธ์ฆ ์„ค์ •
11
  scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/spreadsheets",
12
  "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]
13
+ creds = ServiceAccountCredentials.from_json_keyfile_name("/Users/crystal/generation/analog-marking-416002-e369840763fa.json", scope)
14
  client = gspread.authorize(creds)
15
 
16
  # Google Sheets ๋ฌธ์„œ ์—ด๊ธฐ
 
21
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
22
  sheet.append_row([timestamp, concern, advice])
23
 
 
24
  st.markdown("""
25
  <style>
26
  .header {
27
  font-size: 30px;
28
  font-weight: bold;
29
  margin-bottom: 20px;
30
+ color: #333; /* Dark gray color */
31
  padding: 10px;
32
  border-radius: 10px;
33
  }
34
  .description-box {
35
+ background-color: #f0f0f0; /* Light gray background */
36
  padding: 10px;
37
  border-radius: 10px;
38
  margin-bottom: 10px;
 
40
  </style>
41
  """, unsafe_allow_html=True)
42
 
43
+ # Display the header
44
  st.markdown('<div class="header">๐Ÿ† ๋‹ค๋ฅธ ํŒ€์žฅ ๊ณ ๋ฏผํ•ด๊ฒฐ ๋„์™€์ฃผ๊ธฐ ๐Ÿ† </div>', unsafe_allow_html=True)
45
 
 
46
  st.markdown("""
47
  <div class="description-box">
48
+ <p> How to use </br> 1. ์ขŒ์ธก์—์„œ ์กฐ์–ธ์„ ์ œ๊ณตํ•  ํŒ€์žฅ์˜ ์—ฐ์ฐจ๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”. </br> 2. [๊ณ ๋ฏผ ํ™•์ธ]๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์•„๋ž˜์— ๊ณ ๋ฏผ ๋‚ด์šฉ๊ณผ ์กฐ์–ธ ์ž‘์„ฑ์ฐฝ์ด ๋œน๋‹ˆ๋‹ค. </br> 3. ๋‹ค์‹œ ํ•œ๋ฒˆ [๊ณ ๋ฏผ ํ™•์ธ]๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์ƒˆ๋กœ์šด ๊ณ ๋ฏผ์ด ๋‚˜์˜ต๋‹ˆ๋‹ค </br> </p>
49
  </div>
50
  """, unsafe_allow_html=True)
51
 
52
+ # Load Excel file into DataFrame
53
  df = pd.read_excel("painpoint2.xlsx")
54
 
55
+ # Define experience level options
56
  seniority_options = ['์ €์—ฐ์ฐจ ํŒ€์žฅ', '์ค‘๊ฐ„์—ฐ์ฐจ ํŒ€์žฅ', '๊ณ ์—ฐ์ฐจ ํŒ€์žฅ']
57
 
58
+ def set_background():
59
+ st.markdown(
60
+ """
61
+ <style>
62
+ .stApp {
63
+ background-image: url('URL_TO_YOUR_BACKGROUND_IMAGE');
64
+ background-size: cover;
65
+ }
66
+ </style>
67
+ """,
68
+ unsafe_allow_html=True
69
+ )
70
 
71
+ set_background()
 
72
 
73
+ st.sidebar.markdown("#\n" * 5)
74
+ # Add radio button to select experience level
75
+ st.sidebar.subheader("์กฐ์–ธํ•ด์ค„ ์—ฐ์ฐจ ์„ ํƒํ•˜๊ธฐ:")
76
+ selected_experience = st.sidebar.radio(" ", seniority_options)
77
+ submit_button_left = st.sidebar.button("๊ณ ๋ฏผ ํ™•์ธ")
78
+ # Initialize session state for button click
79
+ if 'button_clicked' not in st.session_state:
80
+ st.session_state['button_clicked'] = False
81
+
82
+ # Modify the button click to update session state
83
+ if submit_button_left:
84
+ st.session_state['button_clicked'] = True
85
+
86
+ # Display random rows based on selected experience level
87
  if submit_button_left:
88
  st.subheader("์„ ํƒ๋œ ๊ณ ๋ฏผ์€?")
89
+ selected_row = df[selected_experience].sample(n=1).iloc[0]
90
+ st.session_state['selected_concern'] = selected_row['๊ณ ๋ฏผ'] # ์—ฌ๊ธฐ์„œ '๊ณ ๋ฏผ'์€ DataFrame์˜ ํ•ด๋‹น ์—ด ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
91
  with st.expander("๊ณ ๋ฏผ ๋‚ด์šฉ๋ณด๊ธฐ", expanded=True):
92
+ st.markdown(selected_row['๊ณ ๋ฏผ']) # ์„ธ์…˜ ์ƒํƒœ์— ์ €์žฅ๋œ ๊ณ ๋ฏผ ๋‚ด์šฉ์„ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.
93
 
94
+ # Add advice section
95
  st.subheader("๊ณ ๋ฏผ ์กฐ์–ธํ•ด์ฃผ๊ธฐ")
96
+ st.write("๋‹ค๋ฅธ ํŒ€์žฅ๋‹˜๋“ค์˜ ๊ณ ๋ฏผ์— ๋Œ€ํ•ด ์กฐ์–ธํ•ด์ฃผ์‹œ๊ฒ ์–ด์š”?")
97
+ advice = st.text_area(" ", height=100)
98
+ submit_button_right = st.button("์กฐ์–ธ ์ œ์ถœํ•˜๊ธฐ")
99
+
100
+ # ์กฐ์–ธ ์ œ์ถœ ๋ฒ„ํŠผ ์ฒ˜๋ฆฌ
101
+ if submit_button_right:
102
+ if not st.session_state.get('submitted', False): # 'submitted' ์ƒํƒœ๊ฐ€ False์ธ ๊ฒฝ์šฐ์—๋งŒ ์‹คํ–‰
103
+ user_advice = advice.strip() # ์‚ฌ์šฉ์ž ์ž…๋ ฅ์—์„œ ๊ณต๋ฐฑ ์ œ๊ฑฐ
104
+ if user_advice: # ์‚ฌ์šฉ์ž๊ฐ€ ์‹ค์ œ๋กœ ์กฐ์–ธ์„ ์ž…๋ ฅํ–ˆ๋Š”์ง€ ํ™•์ธ
105
+ selected_concern = st.session_state.get('selected_concern', '๊ณ ๋ฏผ ์—†์Œ') # ์„ธ์…˜ ์ƒํƒœ์—์„œ ์„ ํƒ๋œ ๊ณ ๋ฏผ ๋‚ด์šฉ์„ ๊ฐ€์ ธ์˜ด
106
+ record_advice(selected_concern, user_advice) # Google Sheets์— ๊ธฐ๋ก
107
+ st.session_state['submitted'] = True # 'submitted' ์ƒํƒœ๋ฅผ True๋กœ ์„ค์ •ํ•˜์—ฌ ์ค‘๋ณต ์ œ์ถœ ๋ฐฉ์ง€
108
+ st.success("์กฐ์–ธ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ œ์ถœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!")
109
+ else:
110
+ st.error("์กฐ์–ธ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.") # ์‚ฌ์šฉ์ž๊ฐ€ ์กฐ์–ธ์„ ์ž…๋ ฅํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ
111
  else:
112
+ st.warning("์ด๋ฏธ ์ œ์ถœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.") # ์ด๋ฏธ ์ œ์ถœ๋œ ๊ฒฝ์šฐ ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ