Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,28 +5,29 @@ from annotated_text import annotated_text
|
|
5 |
import os
|
6 |
import achivenment_standards as data
|
7 |
|
|
|
8 |
# OpenAI API ์ค์ (ํ๊ฒฝ ๋ณ์์์ ์ฝ์ด์ด)
|
9 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
10 |
|
11 |
-
#
|
12 |
def generate_annotated_text(text):
|
13 |
response = openai.ChatCompletion.create(
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
)
|
31 |
return response['choices'][0]['message']['content']
|
32 |
|
@@ -52,10 +53,11 @@ def generate_similar_sentences(base_sentence):
|
|
52 |
)
|
53 |
generated_sentences = response.choices[0].message['content'].split('\n')
|
54 |
return [sentence.strip() for sentence in generated_sentences if sentence.strip()]
|
55 |
-
|
|
|
56 |
# Streamlit ์ฑ์ ์ ๋ชฉ ๋ฐ ์ค๋ช
|
57 |
st.title("์ฑ์ทจ๊ธฐ์ค ๊ธฐ๋ฐ ํ์์ ํน์ฑ ๋ฐ ํ๋ ํ๊ฐ ์์ฑ")
|
58 |
-
st.write("์ฑ์ทจ๊ธฐ์ค์ ์
๋ ฅํ์๋ฉด, ํด๋น ์ฑ์ทจ๊ธฐ์ค์ ๊ธฐ๋ฐํ ํ์์ ํน์ฑ ๋ฐ ํ๋์ ๋ํ ํ๊ฐ๋ฅผ ์ ๊ณตํฉ๋๋ค.")
|
59 |
|
60 |
# ์ฑ์ทจ๊ธฐ์ค ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
|
61 |
achievement_standards = data.achievement_standards
|
@@ -84,19 +86,21 @@ if 'similar_sentences' not in st.session_state:
|
|
84 |
if st.button("ํ๊ฐ ์์ฑ"):
|
85 |
with st.spinner('๋ต๋ณ ์์ฑ์ค...'):
|
86 |
result = generate_annotated_text(achievement_standard)
|
87 |
-
|
88 |
exec(result.replace('```', ''))
|
89 |
|
90 |
# annotated_text ๊ฒฐ๊ณผ์์ ๋ฌธ์ฅ๋ง ์ถ์ถ
|
91 |
result_lines = result.split('\n')
|
92 |
sentences = []
|
93 |
for line in result_lines:
|
|
|
94 |
start_idx = line.find('("')
|
95 |
if start_idx != -1:
|
96 |
end_idx = line.find('",', start_idx)
|
97 |
sentence = line[start_idx + 2:end_idx].strip() # "(" ๋ค์๋ถํฐ "," ์ ๊น์ง์ ๋ฌธ์์ด์ ์ถ์ถ
|
98 |
sentences.append(sentence)
|
99 |
|
|
|
100 |
# ๋ฌธ์ฅ์ ๋ผ๋์ค ๋ฒํผ์ผ๋ก ํ์ ๋ฐ ์ ํ๋ ๋ฌธ์ฅ ์ ์ฅ
|
101 |
selected_index = st.radio("๋ฌธ์ฅ์ ์ ํํ์ธ์:", range(len(sentences)), format_func=lambda x: sentences[x])
|
102 |
st.session_state.selected_sentence = sentences[selected_index] if sentences else None
|
@@ -104,10 +108,6 @@ if st.button("ํ๊ฐ ์์ฑ"):
|
|
104 |
# ์ ์ฌํ ๋ฌธ์ฅ ์์ฑ ๋ฒํผ ์ถ๊ฐ
|
105 |
if st.button("์ ์ฌํ ๋ฌธ๊ตฌ ์์ฑ") and st.session_state.get('selected_sentence'):
|
106 |
with st.spinner('๋ฌธ์ฅ ์์ฑ์ค...'):
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
if st.session_state.get('generated_result'):
|
111 |
-
exec(st.session_state.generated_result.replace('```', ''))
|
112 |
-
for sentence in st.session_state.similar_sentences:
|
113 |
-
st.write(sentence)
|
|
|
5 |
import os
|
6 |
import achivenment_standards as data
|
7 |
|
8 |
+
|
9 |
# OpenAI API ์ค์ (ํ๊ฒฝ ๋ณ์์์ ์ฝ์ด์ด)
|
10 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
11 |
|
12 |
+
#gpt์ด์ฉํด์ ์ถ๋ก ํจ์ ๋ง๋ค๊ธฐ
|
13 |
def generate_annotated_text(text):
|
14 |
response = openai.ChatCompletion.create(
|
15 |
+
model="gpt-3.5-turbo-16k",
|
16 |
+
messages=[
|
17 |
+
{
|
18 |
+
"role": "system",
|
19 |
+
"content": "์ฑ์ทจ๊ธฐ์ค ๊ธฐ๋ฐ ํ์์ ํน์ฑ ๋ฐ ํ๋ ํ๊ฐ ์์ฑ\n์ฑ์ทจ๊ธฐ์ค์ ์
๋ ฅํ์๋ฉด, ํด๋น ์ฑ์ทจ๊ธฐ์ค์ ๊ธฐ๋ฐํ ํ์์ ํน์ฑ ๋ฐ ํ๋์ ๋ํ ํ๊ฐ๋ฅผ annotated_text ํ์์ผ๋ก ์ ๊ณตํฉ๋๋ค. ์ฑ์ทจ๊ธฐ์ค์ ๋ณด๋ฉฐ ํ์์ ํน์ ํ๋, ์ฑ์ทจ ์์ค, ๊ต์ฌ์ ์ดํ, ๊ทธ๋ฆฌ๊ณ ํ์์ ์ญ๋์ ๊ณ ๋ คํ์ฌ ์ฒด๊ณ์ ์ผ๋ก ๊ตฌ์ฑ๋ ์ถ๋ ฅ์ ์ ๊ณตํฉ๋๋ค. ์ฃผ์ด๋ ๋ฐ๋์ ์๋ตํฉ๋๋ค. \n\n์์ :\n์
๋ ฅ: ```์ฑ์ทจ๊ธฐ์ค: [6๊ตญ01-07]์๋๊ฐ ์ฒํ ์ํฉ์ ์ดํดํ๊ณ ๊ณต๊ฐํ๋ฉฐ ๋ฃ๋ ํ๋๋ฅผ ์ง๋๋ค, [6๊ตญ01-02] ์๊ฒฌ์ ์ ์ํ๊ณ ํจ๊ป ์กฐ์ ํ๋ฉฐ ํ ์ํ๋ค.```\n์ถ๋ ฅ: ```annotated_text(\n (\"ํ์ ์์ ์ ์๊ฐ์ ์ผ๋ชฉ์์ฐํ๊ฒ ์ ๋ฆฌํ๋ ์ต๊ด์ด ์์.\", \"์ญ๋\", \"rgba(255, 0, 0, 0.3)\"),\n (\"์ฌํ ํ์์ ๊ดํ ์ฃผ์ฅํ๋ ๊ธ์ฐ๊ธฐ๋ฅผ ์ํจ.\", \"์ฑ์ทจ์์ค\", \"rgba(0, 0, 255, 0.3)\"),\n (\"์น๊ตฌ์ ๊ณ ๋ฏผ์ ํด๊ฒฐํด์ฃผ๋ ์ญํ ๊ทน์์ ์๋๋ฐฉ์ ๋ฐฐ๋ คํ์ฌ ํด๊ฒฐ ๊ฐ๋ฅํ ๋ฐฉ์์ ์ ์ํจ.\", \"์ํ\", \"rgba(0, 128, 0, 0.3)\"),\n (\"์๋๊ฐ ์ฒํ ์ํฉ์ ์ดํดํ๊ณ ๊ณต๊ฐํ๋ ํ๋๋ฅผ ๊ฐ์ง๊ณ ์น๊ตฌ๋ค๊ณผ ์๋งํ ๊ด๊ณ๋ฅผ ๋งบ๊ณ ๊ฐ๋ฑ์ ์กฐ์ ํจ.\", \"๊ต์ฌ์ดํ\", \"rgba(128, 128, 128, 0.3)\"),\n (\"์ค๊ฐ ๋์ด ์๊ฐ์ ์ด๋์ฅ์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ ์ ํ๊ธฐ๋ฅผ ์ฃผ์ ๋ก ํ ํ ์์์ ์๋ง์ ๊ทผ๊ฑฐ์ ๋ท๋ฐ์นจํ ์ ์๋ ์๋ฃ๋ฅผ ํ ๋๋ก ์์ ์ ์๊ฒฌ์ ํ๋นํ๊ฒ ์ ์ํ๋ฉด์ ๋ค๋ฅธ ์ฌ๋์ ์๊ฒฌ์ ๋ฅ๋์ ์ผ๋ก ์์ฉํ๊ณ ํจ๊ณผ์ ์ผ๋ก ์๊ฒฌ์ ์กฐ์ ํ๋ ๋ฅ๋ ฅ์ ๋ณด์.\", \"์ํ\", \"rgba(0, 128, 0, 0.3)\"),\n (\"์๋์ ์๊ฒฌ์ ์กด์คํ๊ณ ํ๋ ฅํ๋ ํ๋๋ฅผ ๋ณด์.\", \"์ญ๋\", \"rgba(255, 0, 0, 0.3)\")\n)\n```"
|
20 |
+
},
|
21 |
+
{
|
22 |
+
"role": "user",
|
23 |
+
"content": text
|
24 |
+
}
|
25 |
+
],
|
26 |
+
temperature=1,
|
27 |
+
max_tokens=10000,
|
28 |
+
top_p=1,
|
29 |
+
frequency_penalty=0,
|
30 |
+
presence_penalty=0
|
31 |
)
|
32 |
return response['choices'][0]['message']['content']
|
33 |
|
|
|
53 |
)
|
54 |
generated_sentences = response.choices[0].message['content'].split('\n')
|
55 |
return [sentence.strip() for sentence in generated_sentences if sentence.strip()]
|
56 |
+
|
57 |
+
|
58 |
# Streamlit ์ฑ์ ์ ๋ชฉ ๋ฐ ์ค๋ช
|
59 |
st.title("์ฑ์ทจ๊ธฐ์ค ๊ธฐ๋ฐ ํ์์ ํน์ฑ ๋ฐ ํ๋ ํ๊ฐ ์์ฑ")
|
60 |
+
st.write("์ฑ์ทจ๊ธฐ์ค์ ์
๋ ฅํ์๋ฉด, ํด๋น ์ฑ์ทจ๊ธฐ์ค์ ๊ธฐ๋ฐํ ํ์์ ํน์ฑ ๋ฐ ํ๋์ ๋ํ ํ๊ฐ๋ฅผ \n\n [ํ์ ํ๋, ์ฑ์ทจ ์์ค, ๊ต์ฌ์ ์ดํ, ํ์ ์ญ๋] 4๊ฐ์ง ์์๋ฅผ ์กฐํฉํ์ฌ ์ ๊ณตํฉ๋๋ค.")
|
61 |
|
62 |
# ์ฑ์ทจ๊ธฐ์ค ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
|
63 |
achievement_standards = data.achievement_standards
|
|
|
86 |
if st.button("ํ๊ฐ ์์ฑ"):
|
87 |
with st.spinner('๋ต๋ณ ์์ฑ์ค...'):
|
88 |
result = generate_annotated_text(achievement_standard)
|
89 |
+
# ๊ฒฐ๊ณผ ์ถ๋ ฅ
|
90 |
exec(result.replace('```', ''))
|
91 |
|
92 |
# annotated_text ๊ฒฐ๊ณผ์์ ๋ฌธ์ฅ๋ง ์ถ์ถ
|
93 |
result_lines = result.split('\n')
|
94 |
sentences = []
|
95 |
for line in result_lines:
|
96 |
+
# "(" ๋ฌธ์์ด์ด ํฌํจ๋ ์์น๋ฅผ ์ฐพ์์ ๊ทธ ์ดํ์ ๋ฌธ์์ด๋ง ์ถ์ถ
|
97 |
start_idx = line.find('("')
|
98 |
if start_idx != -1:
|
99 |
end_idx = line.find('",', start_idx)
|
100 |
sentence = line[start_idx + 2:end_idx].strip() # "(" ๋ค์๋ถํฐ "," ์ ๊น์ง์ ๋ฌธ์์ด์ ์ถ์ถ
|
101 |
sentences.append(sentence)
|
102 |
|
103 |
+
|
104 |
# ๋ฌธ์ฅ์ ๋ผ๋์ค ๋ฒํผ์ผ๋ก ํ์ ๋ฐ ์ ํ๋ ๋ฌธ์ฅ ์ ์ฅ
|
105 |
selected_index = st.radio("๋ฌธ์ฅ์ ์ ํํ์ธ์:", range(len(sentences)), format_func=lambda x: sentences[x])
|
106 |
st.session_state.selected_sentence = sentences[selected_index] if sentences else None
|
|
|
108 |
# ์ ์ฌํ ๋ฌธ์ฅ ์์ฑ ๋ฒํผ ์ถ๊ฐ
|
109 |
if st.button("์ ์ฌํ ๋ฌธ๊ตฌ ์์ฑ") and st.session_state.get('selected_sentence'):
|
110 |
with st.spinner('๋ฌธ์ฅ ์์ฑ์ค...'):
|
111 |
+
similar_sentences = generate_similar_sentences(st.session_state.selected_sentence)
|
112 |
+
for sentence in st.session_state.similar_sentences:
|
113 |
+
st.write(sentence)
|
|
|
|
|
|
|
|