soojeongcrystal commited on
Commit
b610dd6
ยท
verified ยท
1 Parent(s): e2c6a54

Update app.py

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