Spaces:
Running
Running
File size: 4,168 Bytes
829f184 91a314b 6b3d94e cc9698d 0468ba6 f4de003 88c0d7a e90a597 91a314b 829f184 88c0d7a 91a314b 829f184 91a314b 9447f48 123222c 040a7a9 0468ba6 040a7a9 9447f48 123222c 9447f48 91a314b 768f592 91a314b 88c0d7a 829f184 91a314b 6085307 65e42f5 433862c 8d8ecfd 433862c 7f63595 18eaa41 bca9727 433862c 65e42f5 433862c 91a314b 3b94099 079956f 433862c 65e42f5 433862c 079956f |
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 |
import streamlit as st
import pandas as pd
import openai
import os
import instructions
# OpenAI API ์ค์
openai.api_key = os.getenv("OPENAI_API_KEY")
st.set_page_config(layout="wide")
# ํ์ผ ์
๋ก๋ ๋ฐ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ํจ์
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("์ด์ ์ํ๊ธฐ๋ก๋ถ ํ์ผ์ ์
๋ก๋ํ๊ฑฐ๋, ์ง์ ์ํ๊ธฐ๋ก๋ถ ๋ด์ฉ์ ์
๋ ฅํ์ธ์.")
st.write("GPT๋ ์ค์ ํ ์ ์์ต๋๋ค. ์ํ๋ ๊ฒฐ๊ณผ๊ฐ ๋์ค์ง ์๋๋ค๋ฉด ์์ฑ ๋ฒํผ์ ๋ค์ ๋๋ฌ๋ณด์ธ์.")
# ํ์ผ ์
๋ก๋ ๊ธฐ๋ฅ
uploaded_data = upload_and_process_file()
#์์ ํค์๋
attitude_keywords = [
"์ง์ค๋ ฅ", "๊ณผ์ ์ดํด", "๋ฐํ", "๋ฌธ์ ํด๊ฒฐ๋ ฅ", "๊ณผ์ ์ํ", "๊ด์ฐฐ๋ ฅ",
"ํ๊ตฌ๋ ฅ", "์๊ธฐ ์๊ฐ ํํ", "๋
ผ๋ฆฌ์ ์ฌ๊ณ ๋ ฅ", "์ด๋์ ๊ฒฝ", "ํ๋์ฌ",
"๋ฆฌ๋์ฝ", "๋
ผ๋ฆฌ์ ๋นํ๋ ฅ", "๊ต๊ณผ ํ์ต ์ฑ์ทจ๋", "๋ชฉํ์์", "๊ธฐ๋ณธ ํ์ต",
"๋์ ๊ณผ์ ", "๋ฏธ์ ๊ฐ๊ฐ", "์์ ์ ์ฌ๋ฅ", "์์
์ ์ฌ๋ฅ", "ํธ๊ธฐ์ฌ",
"์ง๋ฌธ", "๋ชจ๋ ํ๋"
]
relationship_keywords = [
"ํ๋์ฑ", "์น์ ํจ", "๊ณต๊ฐ ๋ฅ๋ ฅ", "์ปค๋ฎค๋์ผ์ด์
", "๋ฆฌ๋์ญ", "๊ฒฝ์", "ํ๋ ฅ",
"์ธ์ ์๊ตฌ", "์์ฌ์ํต ๋ฌธ์ ", "์ ๋ขฐ", "์ํธ์กด์ค", "๊ณต์ ", "์ดํด์ฌ", "์น๋ฐํจ",
"์ง์งํจ", "๋์", "๋ฐฐ๋ ค", "๊ฑฐ๋ถ", "๋น๋ฐ", "์๊ธฐ์ค์ฌ์ ", "์ธ๋ก์", "๋น๋",
"๋ฌด๊ด์ฌ", "์งํฌ", "๊ฐ๋ฑ", "๊ต๋ฅ ํ๋ฐํจ", "์ํต ์ํจ", "๋ค์ ํจ"
]
personality_keywords = [
"์์ ๊ฐ", "์ฑ
์๊ฐ", "ํฌ์ฉ๋ ฅ", "๊ธ์ ์ ํ๋", "์ ์ฐ์ฑ",
"๊ฐ์์ฑ", "์๋ฏผํจ", "ํ๋ฐํจ", "์ฐจ๋ถํจ", "์ ๊ทน์ ",
"์๊ทน์ ", "์์ค์", "๊ฒธ์ํจ", "์์ ๊ฐ", "์์์ ",
"๋ฌด๊ธฐ๋ ฅ", "์ฑ์ค", "์ฌ์ธํจ", "์ฐ๋งํจ", "์กฐ๊ธํจ",
"๊ฑฐ์น ๋ค", "๊ธ์ ์ ", "์น์ ํจ", "๋ถ๋
ธ", "์ธ๋ด์ฌ",
"๋
๋ฆฝ์ ", "์์ฒ", "์จํํจ", "๋ฐ๋ปํจ", "๋ฏธ์",
"์ฌ์น", "์ ๋จธ", "์ต์ธํจ", "์ฐ์ธํจ", "๋ถ์ ์ "
]
# ์ปฌ๋ผ ์์ฑ
col1, col2 = st.columns(2)
with col1:
# ๊ธฐ์กด ์
๋ ฅ์ฐฝ
for i in range(5):
record_key = f"record_{i}"
if record_key not in st.session_state:
st.session_state[record_key] = ""
st.text_area("์ํ๊ธฐ๋ก๋ถ ๋ด์ฉ ์
๋ ฅ", key=record_key, height=150, value=st.session_state[record_key])
with col2:
# ํค์๋ ์ ํ ์ต์
st.write("ํค์๋ ์ ํ")
selected_attitude = st.multiselect("ํ์ตํ๋", attitude_keywords)
selected_relationship = st.multiselect("๊ต์ฐ๊ด๊ณ", relationship_keywords)
selected_personality = st.multiselect("์ฑ๊ฒฉ", personality_keywords)
# ๋ฐ์ดํฐ ์ฒ๋ฆฌ ๋ฐ ๊ฒฐ๊ณผ ์ถ๋ ฅ
if st.button("์์ฑ"):
with st.spinner('์์ฑ์ค...'):
input_data = "\n".join([st.session_state[f'record_{i}'] for i in range(5) if st.session_state[f'record_{i}']])
# ํค์๋๋ฅผ ์
๋ ฅ ๋ฐ์ดํฐ์ ์ถ๊ฐ
keyword_data = " ".join(selected_attitude + selected_relationship + selected_personality)
full_data = input_data + "\n" + keyword_data
generated_record = generate_living_record(full_data)
st.write("์์ฑ๋ ์ํ๊ธฐ๋ก๋ถ:", generated_record) |