Spaces:
Sleeping
Sleeping
| 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("์กฐ์ธ์ด ์ฑ๊ณต์ ์ผ๋ก ์ ์ถ๋์์ต๋๋ค!") | |