Spaces:
Sleeping
Sleeping
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)
|