Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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;
|
| 27 |
padding: 10px;
|
| 28 |
border-radius: 10px;
|
| 29 |
}
|
| 30 |
.description-box {
|
| 31 |
-
background-color: #f0f0f0;
|
| 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 |
-
#
|
| 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.
|
| 45 |
</div>
|
| 46 |
""", unsafe_allow_html=True)
|
| 47 |
|
| 48 |
-
#
|
| 49 |
df = pd.read_excel("painpoint2.xlsx")
|
| 50 |
|
| 51 |
-
#
|
| 52 |
seniority_options = ['์ ์ฐ์ฐจ ํ์ฅ', '์ค๊ฐ์ฐ์ฐจ ํ์ฅ', '๊ณ ์ฐ์ฐจ ํ์ฅ']
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 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 |
-
|
|
|
|
| 68 |
|
| 69 |
-
|
| 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['๊ณ ๋ฏผ']
|
| 87 |
with st.expander("๊ณ ๋ฏผ ๋ด์ฉ๋ณด๊ธฐ", expanded=True):
|
| 88 |
-
st.markdown(selected_row['๊ณ ๋ฏผ'])
|
| 89 |
|
| 90 |
-
#
|
| 91 |
st.subheader("๊ณ ๋ฏผ ์กฐ์ธํด์ฃผ๊ธฐ")
|
| 92 |
-
st.
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
if
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 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.
|
|
|
|
| 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("์ค์ ๋ก ์กฐ์ธ์ ์
๋ ฅํด์ฃผ์ธ์.")
|