File size: 3,227 Bytes
829f184
91a314b
6b3d94e
cc9698d
f4de003
e90a597
91a314b
829f184
91a314b
 
 
 
 
 
 
 
 
 
829f184
91a314b
 
 
9447f48
123222c
 
e90a597
 
9447f48
123222c
9447f48
 
 
 
 
91a314b
768f592
91a314b
 
 
829f184
e90a597
 
 
 
91a314b
 
6085307
e90a597
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bca9727
91a314b
3b94099
e90a597
91a314b
 
 
 
 
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
import streamlit as st
import pandas as pd
import openai
import os

# 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": "ν•™μƒμ˜ 이전 μƒν™œκΈ°λ‘λΆ€ 데이터λ₯Ό λ°”νƒ•μœΌλ‘œ μ˜¬ν•΄μ˜ μƒν™œκΈ°λ‘λΆ€λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€."},
            {"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("이전 μƒν™œκΈ°λ‘λΆ€ νŒŒμΌμ„ μ—…λ‘œλ“œν•˜κ±°λ‚˜, 직접 μƒν™œκΈ°λ‘λΆ€ λ‚΄μš©μ„ μž…λ ₯ν•˜μ„Έμš”.")

# μ„Έμ…˜ μƒνƒœ μ΄ˆκΈ°ν™”
if 'record_data' not in st.session_state:
    st.session_state.record_data = []

# 파일 μ—…λ‘œλ“œ κΈ°λŠ₯
uploaded_data = upload_and_process_file()

# μž…λ ₯ ν•„λ“œ 동적 생성
for i in range(len(st.session_state.record_data) + 1):
    class_key = f"class_{i}"
    grade_key = f"grade_{i}"
    record_key = f"record_{i}"

    if class_key not in st.session_state:
        st.session_state[class_key] = "μ΄ˆλ“±ν•™κ΅"
    if grade_key not in st.session_state:
        st.session_state[grade_key] = "1ν•™λ…„"
    if record_key not in st.session_state:
        st.session_state[record_key] = ""

    class_record = st.selectbox("ν•™κΈ‰ 선택", ["μ΄ˆλ“±ν•™κ΅", "쀑학ꡐ", "고등학ꡐ"], key=class_key, index=["μ΄ˆλ“±ν•™κ΅", "쀑학ꡐ", "고등학ꡐ"].index(st.session_state[class_key]))
    grade_options = ["1ν•™λ…„", "2ν•™λ…„", "3ν•™λ…„", "4ν•™λ…„", "5ν•™λ…„", "6ν•™λ…„"] if class_record == "μ΄ˆλ“±ν•™κ΅" else ["1ν•™λ…„", "2ν•™λ…„", "3ν•™λ…„"]
    grade_record = st.selectbox("ν•™λ…„ 선택", grade_options, key=grade_key, index=grade_options.index(st.session_state[grade_key]))
    st.text_input("μƒν™œκΈ°λ‘λΆ€ λ‚΄μš© μž…λ ₯", key=record_key, value=st.session_state[record_key])

    st.session_state.record_data.append((class_key, grade_key, record_key))

if st.button("μž…λ ₯ μΉΈ μΆ”κ°€"):
    st.session_state.record_data.append(("", "", ""))

# 데이터 처리 및 κ²°κ³Ό 좜λ ₯
if st.button("생성"):
    input_data = "\n".join([f"{st.session_state[record[0]]} {st.session_state[record[1]]}: {st.session_state[record[2]]}" for record in st.session_state.record_data if st.session_state[record[2]]])
    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)