jonghhhh commited on
Commit
fc2a80f
Β·
verified Β·
1 Parent(s): 9c9228c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -21
app.py CHANGED
@@ -13,19 +13,31 @@ responses_file_path = "responses_data.csv"
13
  if user_type == "μ„€λ¬Έ μ„€μ •":
14
  st.title("μ„€λ¬Έ μ„€μ •")
15
  question = st.text_input("μ„€λ¬Έ μ§ˆλ¬Έμ„ μž…λ ₯ν•˜μ„Έμš”:")
16
- options = st.text_area("μ„ νƒν˜• λ‹΅λ³€ ν•­λͺ©μ„ μž…λ ₯ν•˜μ„Έμš” (각 ν•­λͺ©μ„ μƒˆ 쀄에 μž…λ ₯):").split('\n')
17
- options = [option.strip() for option in options if option.strip()] # 빈 μ˜΅μ…˜ 제거
 
 
 
 
18
  if st.button("μ„€λ¬Έ μ‹œμž‘"):
19
- if question and options:
20
  data = {
21
  'question': [question],
22
- 'options': [options]
 
23
  }
24
  df = pd.DataFrame(data)
25
  df.to_csv(survey_file_path, index=False)
26
  st.success("섀문이 μ„€μ •λ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
27
  else:
28
- st.error("λͺ¨λ“  ν•„λ“œλ₯Ό μž…λ ₯ν•˜μ„Έμš”.")
 
 
 
 
 
 
 
29
 
30
  # 학생 응닡 νŽ˜μ΄μ§€
31
  elif user_type == "학생 응닡":
@@ -33,22 +45,25 @@ elif user_type == "학생 응닡":
33
  if os.path.exists(survey_file_path):
34
  df = pd.read_csv(survey_file_path)
35
  question = df['question'][0]
36
- options = eval(df['options'][0]) # λ¬Έμžμ—΄μ„ 리슀트둜 λ³€ν™˜
37
- options.append("기타 (직접 μž…λ ₯)")
38
 
39
  st.write(f"### {question}")
40
- selected_option = st.radio("닡변을 μ„ νƒν•˜μ„Έμš”:", options)
41
 
42
- if selected_option == "기타 (직접 μž…λ ₯)":
43
- open_answer = st.text_area("주관식 닡변을 μž…λ ₯ν•˜μ„Έμš”:")
 
 
 
 
 
44
  else:
45
- open_answer = ""
46
 
47
  if st.button("λ‹΅λ³€ 제좜"):
48
  # 응닡 데이터 μ €μž₯
49
  response_data = {
50
- '선택': [selected_option if selected_option != "기타 (직접 μž…λ ₯)" else "기타"],
51
- '주관식': [open_answer if selected_option == "기타 (직접 μž…λ ₯)" else ""]
52
  }
53
  response_df = pd.DataFrame(response_data)
54
 
@@ -58,10 +73,9 @@ elif user_type == "학생 응닡":
58
  response_df.to_csv(responses_file_path, index=False)
59
 
60
  st.success("닡변이 μ œμΆœλ˜μ—ˆμŠ΅λ‹ˆλ‹€!")
 
 
61
 
62
- # ν™”λ©΄ μ΄ˆκΈ°ν™”λ₯Ό μœ„ν•œ λ³€μˆ˜ μž¬μ„€μ •
63
- st.session_state['submitted'] = True
64
- st.rerun() # experimental_rerun λŒ€μ‹  rerun μ‚¬μš©
65
  else:
66
  st.warning("섀문이 아직 μ„€μ •λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€. κ΅μ‚¬μ—κ²Œ λ¬Έμ˜ν•˜μ„Έμš”.")
67
 
@@ -70,10 +84,12 @@ elif user_type == "κ²°κ³Ό 확인":
70
  st.title("μ„€λ¬Έ κ²°κ³Ό 확인")
71
  if os.path.exists(responses_file_path):
72
  df = pd.read_csv(responses_file_path)
73
- st.write("### μ„ νƒν˜• λ‹΅λ³€ 뢄포")
74
- st.bar_chart(df['선택'].value_counts())
75
- if '주관식' in df.columns:
76
- st.write("### 주관식 λ‹΅λ³€")
77
- st.table(df['주관식'].dropna())
 
 
78
  else:
79
  st.warning("아직 제좜된 닡변이 μ—†μŠ΅λ‹ˆλ‹€.")
 
13
  if user_type == "μ„€λ¬Έ μ„€μ •":
14
  st.title("μ„€λ¬Έ μ„€μ •")
15
  question = st.text_input("μ„€λ¬Έ μ§ˆλ¬Έμ„ μž…λ ₯ν•˜μ„Έμš”:")
16
+ use_options = st.checkbox("객관식 μ˜΅μ…˜ μ‚¬μš©")
17
+ options = []
18
+ if use_options:
19
+ options = st.text_area("μ„ νƒν˜• λ‹΅λ³€ ν•­λͺ©μ„ μž…λ ₯ν•˜μ„Έμš” (각 ν•­λͺ©μ„ μƒˆ 쀄에 μž…λ ₯):").split('\n')
20
+ options = [option.strip() for option in options if option.strip()] # 빈 μ˜΅μ…˜ 제거
21
+
22
  if st.button("μ„€λ¬Έ μ‹œμž‘"):
23
+ if question:
24
  data = {
25
  'question': [question],
26
+ 'options': [options],
27
+ 'use_options': [use_options]
28
  }
29
  df = pd.DataFrame(data)
30
  df.to_csv(survey_file_path, index=False)
31
  st.success("섀문이 μ„€μ •λ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
32
  else:
33
+ st.error("μ§ˆλ¬Έμ„ μž…λ ₯ν•˜μ„Έμš”.")
34
+
35
+ if st.button("μ„€μ • μ΄ˆκΈ°ν™”"):
36
+ if os.path.exists(survey_file_path):
37
+ os.remove(survey_file_path)
38
+ if os.path.exists(responses_file_path):
39
+ os.remove(responses_file_path)
40
+ st.success("λͺ¨λ“  μ„€μ •κ³Ό 응닡이 μ΄ˆκΈ°ν™”λ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
41
 
42
  # 학생 응닡 νŽ˜μ΄μ§€
43
  elif user_type == "학생 응닡":
 
45
  if os.path.exists(survey_file_path):
46
  df = pd.read_csv(survey_file_path)
47
  question = df['question'][0]
48
+ use_options = df['use_options'][0]
49
+ options = eval(df['options'][0]) if use_options else []
50
 
51
  st.write(f"### {question}")
 
52
 
53
+ if use_options and options:
54
+ options.append("기타 (직접 μž…λ ₯)")
55
+ selected_option = st.radio("닡변을 μ„ νƒν•˜μ„Έμš”:", options)
56
+ if selected_option == "기타 (직접 μž…λ ₯)":
57
+ answer = st.text_area("주관식 닡변을 μž…λ ₯ν•˜μ„Έμš”:")
58
+ else:
59
+ answer = selected_option
60
  else:
61
+ answer = st.text_area("주관식 닡변을 μž…λ ₯ν•˜μ„Έμš”:")
62
 
63
  if st.button("λ‹΅λ³€ 제좜"):
64
  # 응닡 데이터 μ €μž₯
65
  response_data = {
66
+ '응닡': [answer]
 
67
  }
68
  response_df = pd.DataFrame(response_data)
69
 
 
73
  response_df.to_csv(responses_file_path, index=False)
74
 
75
  st.success("닡변이 μ œμΆœλ˜μ—ˆμŠ΅λ‹ˆλ‹€!")
76
+ st.write("### λ‹΅λ³€ 제좜 μ™„λ£Œ")
77
+ st.write(f"κ·€ν•˜μ˜ λ‹΅λ³€: {answer}")
78
 
 
 
 
79
  else:
80
  st.warning("섀문이 아직 μ„€μ •λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€. κ΅μ‚¬μ—κ²Œ λ¬Έμ˜ν•˜μ„Έμš”.")
81
 
 
84
  st.title("μ„€λ¬Έ κ²°κ³Ό 확인")
85
  if os.path.exists(responses_file_path):
86
  df = pd.read_csv(responses_file_path)
87
+ st.write("### 응닡 κ²°κ³Ό")
88
+ if os.path.exists(survey_file_path):
89
+ survey_df = pd.read_csv(survey_file_path)
90
+ use_options = survey_df['use_options'][0]
91
+ if use_options:
92
+ st.bar_chart(df['응닡'].value_counts())
93
+ st.table(df)
94
  else:
95
  st.warning("아직 제좜된 닡변이 μ—†μŠ΅λ‹ˆλ‹€.")