Spaces:
Sleeping
Sleeping
File size: 2,828 Bytes
829f184 91a314b 6b3d94e cc9698d 0468ba6 f4de003 e90a597 91a314b 829f184 91a314b 829f184 91a314b 9447f48 123222c 040a7a9 0468ba6 040a7a9 9447f48 123222c 9447f48 91a314b 768f592 91a314b 829f184 91a314b 6085307 e90a597 7f63595 e90a597 7f63595 e90a597 7f63595 bca9727 91a314b 3b94099 7f63595 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 |
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):
with st.expander(f"μ
λ ₯μ°½ {i+1}", expanded=False):
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)
grade_options = ["1νλ
", "2νλ
", "3νλ
", "4νλ
", "5νλ
", "6νλ
"] if class_record == "μ΄λ±νκ΅" else ["1νλ
", "2νλ
", "3νλ
"]
grade_record = st.selectbox("νλ
μ ν", grade_options, key=grade_key)
st.text_input("μνκΈ°λ‘λΆ λ΄μ© μ
λ ₯", key=record_key)
# λ°μ΄ν° μ²λ¦¬ λ° κ²°κ³Ό μΆλ ₯
if st.button("μμ±"):
input_data = "\n".join([f"{st.session_state[f'class_{i}']} {st.session_state[f'grade_{i}']}: {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)
|