soojeongcrystal commited on
Commit
199a182
ยท
verified ยท
1 Parent(s): 70bd8b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -18
app.py CHANGED
@@ -17,9 +17,9 @@ client = gspread.authorize(creds)
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("""
@@ -46,30 +46,40 @@ st.markdown('<div class="header">๐Ÿ† ๋‹ค๋ฅธ ํŒ€์žฅ ๊ณ ๋ฏผํ•ด๊ฒฐ ๋„์™€์ฃผ๊ธฐ
46
 
47
  # Load Excel file into DataFrame
48
  df = pd.read_excel("painpoint2.xlsx")
49
-
50
- # ๋ฒ„ํŠผ์„ ํ†ตํ•œ ์—ฐ์ฐจ ์„ ํƒ ๋ฐ ๊ณ ๋ฏผ ํ‘œ์‹œ
51
  experience_levels = ['์ €์—ฐ์ฐจ ํŒ€์žฅ', '์ค‘๊ฐ„์—ฐ์ฐจ ํŒ€์žฅ', '๊ณ ์—ฐ์ฐจ ํŒ€์žฅ']
52
- concerns = {experience: df[experience].dropna() for experience in experience_levels}
 
 
 
 
53
 
54
  # ๋ฒ„ํŠผ ์ƒ์„ฑ ๋ฐ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ
55
- for experience in experience_levels:
56
- if st.button(experience):
57
- if not concerns[experience].empty:
58
- selected_concern = concerns[experience].sample(n=1).iloc[0]
59
- st.session_state['selected_concern'] = selected_concern
60
- st.session_state['experience'] = experience # ๊ฒฝํ—˜ ๋ ˆ๋ฒจ ์ €์žฅ
61
- st.markdown(f"### ์„ ํƒ๋œ ๊ณ ๋ฏผ: {selected_concern}")
62
- else:
63
- st.error(f"{experience}์— ํ•ด๋‹นํ•˜๋Š” ๊ณ ๋ฏผ์ด ์—†์Šต๋‹ˆ๋‹ค.")
 
 
 
 
64
 
65
  # ์กฐ์–ธ ์ œ์ถœ ์„น์…˜
66
- if 'selected_concern' in st.session_state:
67
- st.subheader(f"{st.session_state['experience']}์˜ ๊ณ ๋ฏผ์— ๋Œ€ํ•œ ์กฐ์–ธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.")
68
  advice = st.text_area("์กฐ์–ธ:", height=100)
69
  if st.button("์กฐ์–ธ ์ œ์ถœํ•˜๊ธฐ"):
70
  if advice.strip(): # ์กฐ์–ธ์ด ๋น„์–ด์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ
71
- record_advice(st.session_state['selected_concern'], advice.strip())
72
  st.success("์กฐ์–ธ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ œ์ถœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!")
73
- del st.session_state['selected_concern'] # ์ œ์ถœ ํ›„ ์„ ํƒ๋œ ๊ณ ๋ฏผ ์ดˆ๊ธฐํ™”
 
 
74
  else:
75
  st.error("์กฐ์–ธ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.")
 
17
  sheet = client.open("generation_streamlit_0302").sheet1
18
 
19
  # ์‚ฌ์šฉ์ž ์กฐ์–ธ ๋ฐ์ดํ„ฐ๋ฅผ Google Sheets ๋ฌธ์„œ์— ์ถ”๊ฐ€ํ•˜๋Š” ํ•จ์ˆ˜
20
+ def record_advice(experience, concern, advice):
21
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
22
+ sheet.append_row([timestamp, experience, concern, advice])
23
 
24
  # ์Šคํƒ€์ผ๋ง์„ ์œ„ํ•œ CSS
25
  st.markdown("""
 
46
 
47
  # Load Excel file into DataFrame
48
  df = pd.read_excel("painpoint2.xlsx")
49
+ # ๋ฒ„ํŠผ์„ ๊ฐ€๋กœ๋กœ ๋‚˜์—ดํ•˜๊ธฐ ์œ„ํ•œ ์ปจํ…Œ์ด๋„ˆ
50
+ buttons = st.columns(3)
51
  experience_levels = ['์ €์—ฐ์ฐจ ํŒ€์žฅ', '์ค‘๊ฐ„์—ฐ์ฐจ ํŒ€์žฅ', '๊ณ ์—ฐ์ฐจ ํŒ€์žฅ']
52
+ button_state = {"active": None} # ์–ด๋–ค ๋ฒ„ํŠผ์ด ํ™œ์„ฑํ™”๋˜์—ˆ๋Š”์ง€ ์ถ”์ 
53
+
54
+ # ์„ธ์…˜ ์ƒํƒœ ์ดˆ๊ธฐํ™”
55
+ if 'active_button' not in st.session_state:
56
+ st.session_state['active_button'] = None
57
 
58
  # ๋ฒ„ํŠผ ์ƒ์„ฑ ๋ฐ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ
59
+ for i, experience_level in enumerate(experience_levels):
60
+ with buttons[i]:
61
+ if st.session_state['active_button'] == experience_level:
62
+ st.button(experience_level, disabled=True) # ํ™œ์„ฑํ™”๋œ ๋ฒ„ํŠผ ๋น„ํ™œ์„ฑํ™” ํ‘œ์‹œ
63
+ elif st.button(experience_level):
64
+ st.session_state['active_button'] = experience_level # ์„ ํƒ๋œ ๋ฒ„ํŠผ ์ €์žฅ
65
+ concerns = df[experience_level].dropna()
66
+ if not concerns.empty:
67
+ selected_concern = concerns.sample(n=1).iloc[0]
68
+ st.session_state['selected_concern'] = selected_concern
69
+ st.markdown(f"### ์„ ํƒ๋œ ๊ณ ๋ฏผ: {selected_concern}")
70
+ else:
71
+ st.error(f"{experience_level}์— ํ•ด๋‹นํ•˜๋Š” ๊ณ ๋ฏผ์ด ์—†์Šต๋‹ˆ๋‹ค.")
72
 
73
  # ์กฐ์–ธ ์ œ์ถœ ์„น์…˜
74
+ if 'selected_concern' in st.session_state and st.session_state['active_button']:
75
+ st.subheader(f"{st.session_state['active_button']}์˜ ๊ณ ๋ฏผ์— ๋Œ€ํ•œ ์กฐ์–ธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.")
76
  advice = st.text_area("์กฐ์–ธ:", height=100)
77
  if st.button("์กฐ์–ธ ์ œ์ถœํ•˜๊ธฐ"):
78
  if advice.strip(): # ์กฐ์–ธ์ด ๋น„์–ด์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ
79
+ record_advice(st.session_state['active_button'], st.session_state['selected_concern'], advice.strip())
80
  st.success("์กฐ์–ธ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ œ์ถœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!")
81
+ # ์ œ์ถœ ํ›„ ์„ธ์…˜ ์ƒํƒœ ์ดˆ๊ธฐํ™”
82
+ st.session_state['selected_concern'] = None
83
+ st.session_state['active_button'] = None
84
  else:
85
  st.error("์กฐ์–ธ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.")