Problemsolver / app.py
soojeongcrystal's picture
Update app.py
1ef3ff8 verified
raw
history blame
3.63 kB
import streamlit as st
import pandas as pd
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from datetime import datetime
st.set_page_config(page_title="๊ณ ๋ฏผ ํ•ด๊ฒฐ์‚ฌ", page_icon=":sunglasses:")
scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("analog-marking-416002-e369840763fa.json", scope)
client = gspread.authorize(creds)
sheet = client.open("generation_streamlit_0302").sheet1
def record_advice(concern, advice):
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
sheet.append_row([timestamp, concern, advice])
st.markdown("""
<style>
.header {
font-size: 30px;
font-weight: bold;
margin-bottom: 20px;
color: #333; /* Dark gray color */
padding: 10px;
border-radius: 10px;
}
.description-box {
background-color: #f0f0f0; /* Light gray background */
padding: 10px;
border-radius: 10px;
margin-bottom: 10px;
}
</style>
""", unsafe_allow_html=True)
# Display the header
st.markdown('<div class="header">๐Ÿ† ๋‹ค๋ฅธ ํŒ€์žฅ ๊ณ ๋ฏผํ•ด๊ฒฐ ๋„์™€์ฃผ๊ธฐ ๐Ÿ† </div>', unsafe_allow_html=True)
st.markdown("""
<div class="description-box">
<p> How to use </br> 1. ์ขŒ์ธก์—์„œ ์กฐ์–ธ์„ ์ œ๊ณตํ•  ํŒ€์žฅ์˜ ์—ฐ์ฐจ๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”. </br> 2. [๊ณ ๋ฏผ ํ™•์ธ]๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์•„๋ž˜์— ๊ณ ๋ฏผ ๋‚ด์šฉ๊ณผ ์กฐ์–ธ ์ž‘์„ฑ์ฐฝ์ด ๋œน๋‹ˆ๋‹ค. </br> 3. ๋‹ค์‹œ ํ•œ๋ฒˆ [๊ณ ๋ฏผ ํ™•์ธ]๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์ƒˆ๋กœ์šด ๊ณ ๋ฏผ์ด ๋‚˜์˜ต๋‹ˆ๋‹ค </br> </p>
</div>
""", unsafe_allow_html=True)
# Load Excel file into DataFrame
df = pd.read_excel("painpoint2.xlsx")
# Define experience level options
seniority_options = ['์ €์—ฐ์ฐจ ํŒ€์žฅ', '์ค‘๊ฐ„์—ฐ์ฐจ ํŒ€์žฅ', '๊ณ ์—ฐ์ฐจ ํŒ€์žฅ']
def set_background():
st.markdown(
"""
<style>
.stApp {
background-image: url('URL_TO_YOUR_BACKGROUND_IMAGE');
background-size: cover;
}
</style>
""",
unsafe_allow_html=True
)
set_background()
st.sidebar.markdown("#\n" * 5)
# Add radio button to select experience level
st.sidebar.subheader("์กฐ์–ธํ•ด์ค„ ์—ฐ์ฐจ ์„ ํƒํ•˜๊ธฐ:")
selected_experience = st.sidebar.radio(" ", seniority_options)
submit_button_left = st.sidebar.button("๊ณ ๋ฏผ ํ™•์ธ")
# Initialize session state for button click
if 'button_clicked' not in st.session_state:
st.session_state['button_clicked'] = False
# Modify the button click to update session state
if submit_button_left:
st.session_state['button_clicked'] = True
# Display random rows based on selected experience level
if submit_button_left:
st.subheader("์„ ํƒ๋œ ๊ณ ๋ฏผ์€?")
selected_row = df[selected_experience].sample(n=1)
with st.expander("๊ณ ๋ฏผ ๋‚ด์šฉ๋ณด๊ธฐ", expanded=True):
for column_name, cell_value in selected_row.items():
st.markdown(f"{cell_value}")
# Add advice section
st.subheader("๊ณ ๋ฏผ ์กฐ์–ธํ•ด์ฃผ๊ธฐ")
st.write("์ด ํŒ€์žฅ๋‹˜ ๊ณ ๋ฏผ์— ๋Œ€ํ•ด ์กฐ์–ธํ•ด์ฃผ์‹œ๊ฒ ์–ด์š”?")
advice = st.text_area(" ", height=100)
submit_button_right = st.button("์กฐ์–ธ ์ œ์ถœํ•˜๊ธฐ")
if submit_button_right:
# Google Sheets ๋ฌธ์„œ์— ์กฐ์–ธ ๊ธฐ๋ก
record_advice("์„ ํƒ๋œ ๊ณ ๋ฏผ ๋‚ด์šฉ", advice) # ์—ฌ๊ธฐ์„œ "์„ ํƒ๋œ ๊ณ ๋ฏผ ๋‚ด์šฉ"์„ ์‹ค์ œ ๊ณ ๋ฏผ ๋‚ด์šฉ์œผ๋กœ ๋Œ€์ฒดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
st.success("์กฐ์–ธ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ œ์ถœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!")