Spaces:
Running
Running
File size: 4,530 Bytes
577ec3b e6ecc3e 44e9020 e6ecc3e a9086cb e6ecc3e baef142 e6ecc3e fc2a80f e6ecc3e fc2a80f e6ecc3e fc2a80f e6ecc3e a9086cb e6ecc3e fc2a80f 44e9020 e6ecc3e 85eda91 a9086cb e6ecc3e fc2a80f f4aa625 e6ecc3e f4aa625 fc2a80f 9c9228c fc2a80f f4aa625 44e9020 37734a9 a9086cb baef142 a9086cb 44e9020 fc2a80f 52246c7 990121a baef142 44e9020 85eda91 44e9020 a9086cb fc2a80f 85eda91 baef142 85eda91 baef142 fc2a80f 44e9020 37734a9 85eda91 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
import streamlit as st
import pandas as pd
import os
# μ¬μ΄λλ°μμ νμ΄μ§ μ ν
user_type = st.sidebar.selectbox("μ¬μ©μ μ νμ μ ννμΈμ:", ["νμ μλ΅", "μ€λ¬Έ μ€μ ", "κ²°κ³Ό νμΈ"])
# μ€λ¬Έ λ°μ΄ν° νμΌ κ²½λ‘
survey_file_path = "survey_data.csv"
responses_file_path = "responses_data.csv"
# μ€λ¬Έ μ€μ νμ΄μ§ (κ°μ¬μ©)
if user_type == "μ€λ¬Έ μ€μ ":
st.title("μ€λ¬Έ μ€μ ")
question = st.text_input("μ€λ¬Έ μ§λ¬Έμ μ
λ ₯νμΈμ:")
use_options = st.checkbox("κ°κ΄μ μ΅μ
μ¬μ©")
options = []
if use_options:
options = st.text_area("μ νν λ΅λ³ νλͺ©μ μ
λ ₯νμΈμ (κ° νλͺ©μ μ μ€μ μ
λ ₯):").split('\n')
options = [option.strip() for option in options if option.strip()] # λΉ μ΅μ
μ κ±°
if st.button("μ€λ¬Έ μμ"):
if question:
data = {
'question': [question],
'options': [options],
'use_options': [use_options]
}
df = pd.DataFrame(data)
df.to_csv(survey_file_path, index=False)
st.success("μ€λ¬Έμ΄ μ€μ λμμ΅λλ€.")
else:
st.error("μ§λ¬Έμ μ
λ ₯νμΈμ.")
if st.button("μ€μ μ΄κΈ°ν"):
if os.path.exists(survey_file_path):
os.remove(survey_file_path)
if os.path.exists(responses_file_path):
os.remove(responses_file_path)
st.success("λͺ¨λ μ€μ κ³Ό μλ΅μ΄ μ΄κΈ°νλμμ΅λλ€.")
# νμ μλ΅ νμ΄μ§
elif user_type == "νμ μλ΅":
st.title("μ€λ¬Έ μλ΅")
if os.path.exists(survey_file_path):
df = pd.read_csv(survey_file_path)
question = df['question'][0]
use_options = df['use_options'][0]
options = eval(df['options'][0]) if use_options else []
st.write(f"### {question}")
if use_options and options:
options.append("κΈ°ν (μ§μ μ
λ ₯)")
selected_option = st.radio("λ΅λ³μ μ ννμΈμ:", options)
if selected_option == "κΈ°ν (μ§μ μ
λ ₯)":
answer = st.text_area("μ£Όκ΄μ λ΅λ³μ μ
λ ₯νμΈμ:")
else:
answer = selected_option
else:
answer = st.text_area("μ£Όκ΄μ λ΅λ³μ μ
λ ₯νμΈμ:")
if st.button("λ΅λ³ μ μΆ"):
# μλ΅ λ°μ΄ν° μ μ₯
response_data = {
'μλ΅': [answer],
'μ ν': ['κ°κ΄μ' if use_options and answer in options else 'μ£Όκ΄μ']
}
response_df = pd.DataFrame(response_data)
if os.path.exists(responses_file_path):
response_df.to_csv(responses_file_path, mode='a', header=False, index=False)
else:
response_df.to_csv(responses_file_path, index=False)
st.success("λ΅λ³μ΄ μ μΆλμμ΅λλ€!")
st.write("### λ΅λ³ μ μΆ μλ£")
st.write(f"κ·νμ λ΅λ³: {answer}")
else:
st.warning("μ€λ¬Έμ΄ μμ§ μ€μ λμ§ μμμ΅λλ€. κ°μ¬μκ² λ¬ΈμνμΈμ.")
# κ²°κ³Ό νμΈ νμ΄μ§ (κ°μ¬μ©)
elif user_type == "κ²°κ³Ό νμΈ":
st.title("μ€λ¬Έ κ²°κ³Ό νμΈ")
if os.path.exists(responses_file_path):
df = pd.read_csv(responses_file_path)
st.write("### μλ΅ κ²°κ³Ό")
if os.path.exists(survey_file_path):
survey_df = pd.read_csv(survey_file_path)
use_options = survey_df['use_options'][0]
if use_options:
options = eval(survey_df['options'][0])
# κ°κ΄μ μλ΅λ§ νν°λ§νμ¬ λ§λ κ·Έλν μμ±
objective_responses = df[df['μ ν'] == 'κ°κ΄μ']
response_counts = objective_responses['μλ΅'].value_counts().reindex(options, fill_value=0)
st.bar_chart(response_counts)
# μ£Όκ΄μ μλ΅ νμ
subjective_responses = df[df['μ ν'] == 'μ£Όκ΄μ']
if not subjective_responses.empty:
st.write("### μ£Όκ΄μ μλ΅")
st.table(subjective_responses['μλ΅'])
else:
st.info("μμ§ μ£Όκ΄μ μλ΅μ΄ μμ΅λλ€.")
# λͺ¨λ μλ΅ νμ
st.write("### λͺ¨λ μλ΅")
st.table(df)
else:
st.warning("μμ§ μ μΆλ λ΅λ³μ΄ μμ΅λλ€.")
|