File size: 2,919 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
28106e5
7f63595
18eaa41
1d54b79
 
18eaa41
28106e5
 
1d54b79
 
 
 
28106e5
18eaa41
7f63595
 
e90a597
18eaa41
 
bca9727
91a314b
3b94099
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
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()

# ํŒŒ์ผ ์—…๋กœ๋“œ ๋ฐ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ๋ฐ ์ž…๋ ฅ ํ•„๋“œ์— ๋ฐ์ดํ„ฐ ์ž๋™ ์ฑ„์šฐ๊ธฐ
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("์ƒ์„ฑ"):
    with st.spinner('์ƒ์„ฑ์ค‘...'):
        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)