Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,29 +5,28 @@ from annotated_text import annotated_text
|
|
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 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
)
|
32 |
return response['choices'][0]['message']['content']
|
33 |
|
@@ -53,11 +52,10 @@ def generate_similar_sentences(base_sentence):
|
|
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("์ฑ์ทจ๊ธฐ์ค์ ์
๋ ฅํ์๋ฉด, ํด๋น ์ฑ์ทจ๊ธฐ์ค์ ๊ธฐ๋ฐํ ํ์์ ํน์ฑ ๋ฐ ํ๋์ ๋ํ ํ๊ฐ๋ฅผ
|
61 |
|
62 |
# ์ฑ์ทจ๊ธฐ์ค ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
|
63 |
achievement_standards = data.achievement_standards
|
@@ -86,21 +84,19 @@ if 'similar_sentences' not in st.session_state:
|
|
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,8 +104,10 @@ if st.button("ํ๊ฐ ์์ฑ"):
|
|
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)
|
114 |
-
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import os
|
6 |
import achivenment_standards as data
|
7 |
|
|
|
8 |
# OpenAI API ์ค์ (ํ๊ฒฝ ๋ณ์์์ ์ฝ์ด์ด)
|
9 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
10 |
|
11 |
+
# gpt์ด์ฉํด์ ์ถ๋ก ํจ์ ๋ง๋ค๊ธฐ
|
12 |
def generate_annotated_text(text):
|
13 |
response = openai.ChatCompletion.create(
|
14 |
+
model="gpt-3.5-turbo-16k",
|
15 |
+
messages=[
|
16 |
+
{
|
17 |
+
"role": "system",
|
18 |
+
"content": "์ฑ์ทจ๊ธฐ์ค ๊ธฐ๋ฐ ํ์์ ํน์ฑ ๋ฐ ํ๋ ํ๊ฐ ์์ฑ\n์ฑ์ทจ๊ธฐ์ค์ ์
๋ ฅํ์๋ฉด, ํด๋น ์ฑ์ทจ๊ธฐ์ค์ ๊ธฐ๋ฐํ ํ์์ ํน์ฑ ๋ฐ ํ๋์ ๋ํ ํ๊ฐ๋ฅผ annotated_text ํ์์ผ๋ก ์ ๊ณตํฉ๋๋ค."
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"role": "user",
|
22 |
+
"content": text
|
23 |
+
}
|
24 |
+
],
|
25 |
+
temperature=1,
|
26 |
+
max_tokens=10000,
|
27 |
+
top_p=1,
|
28 |
+
frequency_penalty=0,
|
29 |
+
presence_penalty=0
|
30 |
)
|
31 |
return response['choices'][0]['message']['content']
|
32 |
|
|
|
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 |
if st.button("ํ๊ฐ ์์ฑ"):
|
85 |
with st.spinner('๋ต๋ณ ์์ฑ์ค...'):
|
86 |
result = generate_annotated_text(achievement_standard)
|
87 |
+
st.session_state.generated_result = result # ๊ฒฐ๊ณผ ์ ์ฅ
|
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 |
# ์ ์ฌํ ๋ฌธ์ฅ ์์ฑ ๋ฒํผ ์ถ๊ฐ
|
105 |
if st.button("์ ์ฌํ ๋ฌธ๊ตฌ ์์ฑ") and st.session_state.get('selected_sentence'):
|
106 |
with st.spinner('๋ฌธ์ฅ ์์ฑ์ค...'):
|
107 |
+
st.session_state.similar_sentences = generate_similar_sentences(st.session_state.selected_sentence)
|
|
|
|
|
|
|
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)
|