Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import openai | |
| import os | |
| import instructions | |
| # OpenAI API ์ค์ | |
| openai.api_key = os.getenv("OPENAI_API_KEY") | |
| # ํ์ผ ์ ๋ก๋ ๋ฐ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ํจ์ | |
| def upload_and_process_file(): | |
| uploaded_file = st.file_uploader("์ด์ ์ํ๊ธฐ๋ก๋ถ ํ์ผ ์ ๋ก๋", type=['csv', 'json']) | |
| if uploaded_file is not None: | |
| if uploaded_file.type == 'text/csv': | |
| data = pd.read_csv(uploaded_file) | |
| elif uploaded_file.type == 'application/json': | |
| data = pd.read_json(uploaded_file) | |
| return data | |
| return None | |
| # ์ํ๊ธฐ๋ก๋ถ ๋ฌธ๊ตฌ ์์ฑ ํจ์ | |
| def generate_living_record(data): | |
| data_str = str(data) | |
| response = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo-16k", | |
| messages=[ | |
| {"role": "system", | |
| "content": instructions.instruction | |
| }, | |
| {"role": "user", | |
| "content": data_str | |
| } | |
| ], | |
| temperature=0.7, | |
| max_tokens=10000, | |
| top_p=1, | |
| frequency_penalty=0, | |
| presence_penalty=0 | |
| ) | |
| return response.choices[0].message.content | |
| # Streamlit ์ฑ ๊ตฌ์ฑ | |
| st.title("์ํ๊ธฐ๋ก๋ถ ์์ฑ ์๋น์ค") | |
| st.write("์ด์ ์ํ๊ธฐ๋ก๋ถ ํ์ผ์ ์ ๋ก๋ํ๊ฑฐ๋, ์ง์ ์ํ๊ธฐ๋ก๋ถ ๋ด์ฉ์ ์ ๋ ฅํ์ธ์.") | |
| # ํ์ผ ์ ๋ก๋ ๊ธฐ๋ฅ | |
| uploaded_data = upload_and_process_file() | |
| # ํ์ผ ์ ๋ก๋ ๋ฐ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ๋ฐ ์ ๋ ฅ ํ๋์ ๋ฐ์ดํฐ ์๋ ์ฑ์ฐ๊ธฐ | |
| for i in range(6): | |
| record_key = f"record_{i}" | |
| # ์ ๋ก๋๋ ๋ฐ์ดํฐ๊ฐ ์๊ณ ํด๋น ์ธ๋ฑ์ค์ ๋ฐ์ดํฐ๊ฐ ์๋ ๊ฒฝ์ฐ | |
| if uploaded_data is not None and i < len(uploaded_data): | |
| # ์ฒซ ๋ฒ์งธ ์ปฌ๋ผ์ ๊ฐ์ ๊ฐ์ ธ์ด | |
| data_value = uploaded_data.iloc[i, 0] | |
| # ๋ฐ์ดํฐ๊ฐ NaN์ด๋ฉด ๋น ๋ฌธ์์ด๋ก ์ฒ๋ฆฌ | |
| if pd.isna(data_value): | |
| st.session_state[record_key] = "" | |
| else: | |
| st.session_state[record_key] = str(data_value) | |
| else: | |
| if record_key not in st.session_state: | |
| st.session_state[record_key] = "" | |
| with st.expander(f"์ ๋ ฅ์ฐฝ {i+1}", expanded=False): | |
| st.text_area("์ํ๊ธฐ๋ก๋ถ ๋ด์ฉ ์ ๋ ฅ", key=record_key, height=150, value=st.session_state[record_key]) | |
| # ๋ฐ์ดํฐ ์ฒ๋ฆฌ ๋ฐ ๊ฒฐ๊ณผ ์ถ๋ ฅ | |
| if st.button("์์ฑ"): | |
| input_data = "\n".join([st.session_state[f'record_{i}'] for i in range(6) if st.session_state[f'record_{i}']]) | |
| if uploaded_data is not None: | |
| generated_record = generate_living_record(uploaded_data) | |
| else: | |
| generated_record = generate_living_record(input_data) | |
| st.write("์์ฑ๋ ์ํ๊ธฐ๋ก๋ถ:", generated_record) |