Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ import openai
|
|
| 4 |
import os
|
| 5 |
import instructions
|
| 6 |
|
| 7 |
-
|
| 8 |
# OpenAI API ์ค์
|
| 9 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 10 |
|
|
@@ -22,13 +21,16 @@ def upload_and_process_file():
|
|
| 22 |
return None
|
| 23 |
|
| 24 |
# ์ํ๊ธฐ๋ก๋ถ ๋ฌธ๊ตฌ ์์ฑ ํจ์
|
| 25 |
-
def generate_living_record(data):
|
| 26 |
data_str = str(data)
|
|
|
|
|
|
|
|
|
|
| 27 |
response = openai.ChatCompletion.create(
|
| 28 |
model="gpt-4o-mini",
|
| 29 |
messages=[
|
| 30 |
{"role": "system",
|
| 31 |
-
"content":
|
| 32 |
},
|
| 33 |
{"role": "user",
|
| 34 |
"content": data_str
|
|
@@ -42,27 +44,26 @@ def generate_living_record(data):
|
|
| 42 |
)
|
| 43 |
return response.choices[0].message.content
|
| 44 |
|
| 45 |
-
#์ค๋ฅ๊ฐ ๋์ ์
๋ ฅ์ฐฝ ๋ด ์ง์ฐ๊ธฐ ๊ธฐ๋ฅ์ ์ญ์ ์ฒ๋ฆฌํจ
|
| 46 |
-
# def clear_text(key):
|
| 47 |
-
# st.session_state[key] = ""
|
| 48 |
-
|
| 49 |
# Streamlit ์ฑ ๊ตฌ์ฑ
|
| 50 |
st.title("์ํ๊ธฐ๋ก๋ถ ์์ฑ ์๋น์ค")
|
| 51 |
st.write("๊ธฐ๋ก ์๋ฃ๊ฐ ๋ด๊ธด CSVํ์ผ ์
๋ก๋, ์ง์ ๊ธฐ๋ก์ ์
๋ ฅ, ํค์๋๋ฅผ ์ ํํ์ฌ ์ํ๊ธฐ๋ก๋ถ ์์ฑ์ ํ์ํ ๊ด์ฐฐ ๊ฒฐ๊ณผ๋ฅผ ์ ๊ณตํ ์ ์์ต๋๋ค.")
|
| 52 |
st.write("GPT๋ ์ค์ ํ ์ ์์ต๋๋ค. ์ํ๋ ๊ฒฐ๊ณผ๊ฐ ๋์ค์ง ์๋๋ค๋ฉด ์์ฑ ๋ฒํผ์ ๋ค์ ๋๋ฌ๋ณด์ธ์.")
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
# ํ์ผ ์
๋ก๋ ๊ธฐ๋ฅ
|
| 55 |
uploaded_data = upload_and_process_file()
|
| 56 |
|
| 57 |
-
|
| 58 |
attitude_keywords = [
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
]
|
|
|
|
| 66 |
relationship_keywords = [
|
| 67 |
"ํ๋์ฑ", "์น์ ํจ", "๊ณต๊ฐ ๋ฅ๋ ฅ", "์ปค๋ฎค๋์ผ์ด์
", "๋ฆฌ๋์ญ", "๊ฒฝ์", "ํ๋ ฅ",
|
| 68 |
"์ธ์ ์๊ตฌ", "์์ฌ์ํต ๋ฌธ์ ", "์ ๋ขฐ", "์ํธ์กด์ค", "๊ณต์ ", "์ดํด์ฌ", "์น๋ฐํจ",
|
|
@@ -100,7 +101,6 @@ with col1:
|
|
| 100 |
current_bytes = len(user_input.encode('utf-8'))
|
| 101 |
st.caption(f"ํ์ฌ ์
๋ ฅ์ฐฝ ๋ฐ์ดํธ ์: {current_bytes}")
|
| 102 |
|
| 103 |
-
|
| 104 |
with col2:
|
| 105 |
# ํค์๋ ์ ํ ์ต์
|
| 106 |
st.write("ํค์๋ ์ ํ")
|
|
@@ -113,7 +113,7 @@ with col2:
|
|
| 113 |
input_data = "\n".join([st.session_state[f'record_{i}'] for i in range(5) if st.session_state[f'record_{i}']])
|
| 114 |
keyword_data = " ".join(selected_attitude + selected_relationship + selected_personality)
|
| 115 |
full_data = input_data + "\n" + keyword_data
|
| 116 |
-
generated_record = generate_living_record(full_data)
|
| 117 |
# ์์ฑ๋ ๊ฒฐ๊ณผ๋ฅผ ์ธ์
์ํ์ ์ ์ฅ
|
| 118 |
st.session_state["generated_result"] = generated_record
|
| 119 |
|
|
|
|
| 4 |
import os
|
| 5 |
import instructions
|
| 6 |
|
|
|
|
| 7 |
# OpenAI API ์ค์
|
| 8 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 9 |
|
|
|
|
| 21 |
return None
|
| 22 |
|
| 23 |
# ์ํ๊ธฐ๋ก๋ถ ๋ฌธ๊ตฌ ์์ฑ ํจ์
|
| 24 |
+
def generate_living_record(data, selected_instruction):
|
| 25 |
data_str = str(data)
|
| 26 |
+
instruction_content = (instructions.instruction if selected_instruction == "์ด๋ฑํ๊ต"
|
| 27 |
+
else instructions.highschool_instruction)
|
| 28 |
+
|
| 29 |
response = openai.ChatCompletion.create(
|
| 30 |
model="gpt-4o-mini",
|
| 31 |
messages=[
|
| 32 |
{"role": "system",
|
| 33 |
+
"content": instruction_content
|
| 34 |
},
|
| 35 |
{"role": "user",
|
| 36 |
"content": data_str
|
|
|
|
| 44 |
)
|
| 45 |
return response.choices[0].message.content
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
# Streamlit ์ฑ ๊ตฌ์ฑ
|
| 48 |
st.title("์ํ๊ธฐ๋ก๋ถ ์์ฑ ์๋น์ค")
|
| 49 |
st.write("๊ธฐ๋ก ์๋ฃ๊ฐ ๋ด๊ธด CSVํ์ผ ์
๋ก๋, ์ง์ ๊ธฐ๋ก์ ์
๋ ฅ, ํค์๋๋ฅผ ์ ํํ์ฌ ์ํ๊ธฐ๋ก๋ถ ์์ฑ์ ํ์ํ ๊ด์ฐฐ ๊ฒฐ๊ณผ๋ฅผ ์ ๊ณตํ ์ ์์ต๋๋ค.")
|
| 50 |
st.write("GPT๋ ์ค์ ํ ์ ์์ต๋๋ค. ์ํ๋ ๊ฒฐ๊ณผ๊ฐ ๋์ค์ง ์๋๋ค๋ฉด ์์ฑ ๋ฒํผ์ ๋ค์ ๋๋ฌ๋ณด์ธ์.")
|
| 51 |
|
| 52 |
+
# ํ๊ต๊ธ ์ ํ ๋ผ๋์ค ๋ฒํผ
|
| 53 |
+
school_level = st.radio("ํ๊ต๊ธ ์ ํ", ["์ด๋ฑํ๊ต", "์คยท๊ณ ๋ฑํ๊ต"])
|
| 54 |
+
|
| 55 |
# ํ์ผ ์
๋ก๋ ๊ธฐ๋ฅ
|
| 56 |
uploaded_data = upload_and_process_file()
|
| 57 |
|
| 58 |
+
# ๋๋จธ์ง ์ฝ๋๋ ๋์ผํ๊ฒ ์ ์ง...
|
| 59 |
attitude_keywords = [
|
| 60 |
+
"์ง์ค๋ ฅ", "๊ณผ์ ์ดํด", "๋ฐํ", "๋ฌธ์ ํด๊ฒฐ๋ ฅ", "๊ณผ์ ์ํ", "๊ด์ฐฐ๋ ฅ",
|
| 61 |
+
"ํ๊ตฌ๋ ฅ", "์๊ธฐ ์๊ฐ ํํ", "๋
ผ๋ฆฌ์ ์ฌ๊ณ ๋ ฅ", "์ด๋์ ๊ฒฝ", "ํ๋์ฌ",
|
| 62 |
+
"๋ฆฌ๋์ฝ", "๋
ผ๋ฆฌ์ ๋นํ๋ ฅ", "๊ต๊ณผ ํ์ต ์ฑ์ทจ๋", "๋ชฉํ์์", "๊ธฐ๋ณธ ํ์ต",
|
| 63 |
+
"๋์ ๊ณผ์ ", "๋ฏธ์ ๊ฐ๊ฐ", "์์ ์ ์ฌ๋ฅ", "์์
์ ์ฌ๋ฅ", "ํธ๊ธฐ์ฌ",
|
| 64 |
+
"์ง๋ฌธ", "๋ชจ๋ ํ๋"
|
|
|
|
| 65 |
]
|
| 66 |
+
|
| 67 |
relationship_keywords = [
|
| 68 |
"ํ๋์ฑ", "์น์ ํจ", "๊ณต๊ฐ ๋ฅ๋ ฅ", "์ปค๋ฎค๋์ผ์ด์
", "๋ฆฌ๋์ญ", "๊ฒฝ์", "ํ๋ ฅ",
|
| 69 |
"์ธ์ ์๊ตฌ", "์์ฌ์ํต ๋ฌธ์ ", "์ ๋ขฐ", "์ํธ์กด์ค", "๊ณต์ ", "์ดํด์ฌ", "์น๋ฐํจ",
|
|
|
|
| 101 |
current_bytes = len(user_input.encode('utf-8'))
|
| 102 |
st.caption(f"ํ์ฌ ์
๋ ฅ์ฐฝ ๋ฐ์ดํธ ์: {current_bytes}")
|
| 103 |
|
|
|
|
| 104 |
with col2:
|
| 105 |
# ํค์๋ ์ ํ ์ต์
|
| 106 |
st.write("ํค์๋ ์ ํ")
|
|
|
|
| 113 |
input_data = "\n".join([st.session_state[f'record_{i}'] for i in range(5) if st.session_state[f'record_{i}']])
|
| 114 |
keyword_data = " ".join(selected_attitude + selected_relationship + selected_personality)
|
| 115 |
full_data = input_data + "\n" + keyword_data
|
| 116 |
+
generated_record = generate_living_record(full_data, school_level)
|
| 117 |
# ์์ฑ๋ ๊ฒฐ๊ณผ๋ฅผ ์ธ์
์ํ์ ์ ์ฅ
|
| 118 |
st.session_state["generated_result"] = generated_record
|
| 119 |
|