soojeongcrystal commited on
Commit
c3dd112
ยท
verified ยท
1 Parent(s): 67d55a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -64
app.py CHANGED
@@ -21,6 +21,7 @@ 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
  st.markdown("""
25
  <style>
26
  .header {
@@ -40,73 +41,40 @@ st.markdown("""
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("์ด๋ฏธ ์ œ์ถœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.") # ์ด๋ฏธ ์ œ์ถœ๋œ ๊ฒฝ์šฐ ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ
 
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 {
 
41
  </style>
42
  """, unsafe_allow_html=True)
43
 
44
+ # ํ—ค๋” ํ‘œ์‹œ
45
  st.markdown('<div class="header">๐Ÿ† ๋‹ค๋ฅธ ํŒ€์žฅ ๊ณ ๋ฏผํ•ด๊ฒฐ ๋„์™€์ฃผ๊ธฐ ๐Ÿ† </div>', unsafe_allow_html=True)
46
 
 
 
 
 
 
 
47
  # Load Excel file into DataFrame
48
  df = pd.read_excel("painpoint2.xlsx")
49
 
50
+ # Add radio button to select experience level and display concerns
51
+ experience_levels = ['์ €์—ฐ์ฐจ ํŒ€์žฅ', '์ค‘๊ฐ„์—ฐ์ฐจ ํŒ€์žฅ', '๊ณ ์—ฐ์ฐจ ํŒ€์žฅ']
52
+ selected_experience = st.radio("์กฐ์–ธํ•ด์ค„ ์—ฐ์ฐจ ์„ ํƒํ•˜๊ธฐ:", experience_levels)
53
+ submit_button = st.button(f"{selected_experience} ๊ณ ๋ฏผ ํ™•์ธ")
54
+
55
+ # Display random concern based on selected experience level
56
+ if submit_button:
57
+ if selected_experience in df.columns:
58
+ # ํ•ด๋‹น ์—ฐ์ฐจ ์—ด์—์„œ ๋ฌด์ž‘์œ„๋กœ ๊ณ ๋ฏผ์„ ์„ ํƒ
59
+ concerns = df[selected_experience].dropna()
60
+ if not concerns.empty:
61
+ selected_concern = concerns.sample(n=1).iloc[0]
62
+ st.session_state['selected_concern'] = selected_concern
63
+ st.markdown(f"### ์„ ํƒ๋œ ๊ณ ๋ฏผ: {selected_concern}")
64
+ else:
65
+ st.error(f"{selected_experience}์— ํ•ด๋‹นํ•˜๋Š” ๊ณ ๋ฏผ์ด ์—†์Šต๋‹ˆ๋‹ค.")
66
+ else:
67
+ st.error("์„ ํƒํ•œ ์—ฐ์ฐจ์— ํ•ด๋‹นํ•˜๋Š” ์—ด์ด ๋ฐ์ดํ„ฐ์— ์—†์Šต๋‹ˆ๋‹ค.")
68
+
69
+ # ์กฐ์–ธ ์ œ์ถœ ์„น์…˜
70
+ if 'selected_concern' in st.session_state:
71
+ advice = st.text_area("๊ณ ๋ฏผ์— ๋Œ€ํ•œ ์กฐ์–ธ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”:", height=100)
72
+ submit_advice_button = st.button("์กฐ์–ธ ์ œ์ถœํ•˜๊ธฐ")
73
+
74
+ if submit_advice_button:
75
+ if advice.strip(): # ์กฐ์–ธ์ด ๋น„์–ด์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ
76
+ record_advice(st.session_state['selected_concern'], advice.strip())
77
+ st.success("์กฐ์–ธ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ œ์ถœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!")
78
+ del st.session_state['selected_concern'] # ์ œ์ถœ ํ›„ ์„ ํƒ๋œ ๊ณ ๋ฏผ ์ดˆ๊ธฐํ™”
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  else:
80
+ st.error("์กฐ์–ธ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.")