Update app.py
Browse files
app.py
CHANGED
@@ -7,44 +7,46 @@ import os
|
|
7 |
# OpenAI API ์ค์ (ํ๊ฒฝ ๋ณ์์์ ์ฝ์ด์ด)
|
8 |
openai.api_key = os.getenv("OPENAI_API_KEY") # ์ค์ ์ฝ๋์์ ์ฃผ์ ํด์
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
#
|
18 |
-
task_description = "
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
messages=messages,
|
28 |
-
|
|
|
29 |
)
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
#
|
35 |
-
|
36 |
-
|
37 |
-
# ํ
์คํธ๋ฅผ ๋จ์ด๋ก ๋ถํ ํ๊ณ , ๊ฐ ๋จ์ด๋ฅผ ๊ฒ์ฌํ์ฌ ์ฃผ์์ ๋ต๋๋ค.
|
38 |
-
for word in user_text.split():
|
39 |
-
if word in extracted_keywords:
|
40 |
-
annotated_list.append((word, 'Keyword'))
|
41 |
-
else:
|
42 |
-
annotated_list.append(word)
|
43 |
-
annotated_list.append(" ") # ์๋์ ๊ณต๋ฐฑ์ ๋ณต์ํฉ๋๋ค.
|
44 |
-
|
45 |
-
# ์ฃผ์์ด ๋ฌ๋ฆฐ ํ
์คํธ๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
|
46 |
-
annotated_text(*annotated_list)
|
47 |
|
48 |
-
# Streamlit ์ฑ ์คํ
|
49 |
if __name__ == "__main__":
|
50 |
-
|
|
|
7 |
# OpenAI API ์ค์ (ํ๊ฒฝ ๋ณ์์์ ์ฝ์ด์ด)
|
8 |
openai.api_key = os.getenv("OPENAI_API_KEY") # ์ค์ ์ฝ๋์์ ์ฃผ์ ํด์
|
9 |
|
10 |
+
def main():
|
11 |
+
st.title("Keyword Highlighter")
|
12 |
+
|
13 |
+
user_text = st.text_area("Please enter your text here:", "")
|
14 |
+
|
15 |
+
if st.button("Find Keywords"):
|
16 |
+
|
17 |
+
# few-shot learning์ ์ด์ฉํ task_description
|
18 |
+
task_description = """You are a helpful assistant that generates annotated text for the st-annotated-text library in Python. Highlight the key terms that are most important in the context of the sentence. Your output should be formatted in the following way:
|
19 |
+
annotated_text(
|
20 |
+
"This ",
|
21 |
+
("is", ""),
|
22 |
+
" some ",
|
23 |
+
("annotated", ""),
|
24 |
+
("text", ""),
|
25 |
+
" for those of ",
|
26 |
+
("you", ""),
|
27 |
+
" who ",
|
28 |
+
("like", ""),
|
29 |
+
" this sort of ",
|
30 |
+
("thing", ""),
|
31 |
+
". "
|
32 |
+
)"""
|
33 |
+
|
34 |
+
user_prompt = f"Now, please annotate this text: {user_text}"
|
35 |
+
|
36 |
+
messages = [{"role": "system", "content": task_description}, {"role": "user", "content": user_prompt}]
|
37 |
+
|
38 |
+
response = openai.ChatCompletion.create(
|
39 |
+
model="gpt-3.5-turbo-16k",
|
40 |
messages=messages,
|
41 |
+
temperature=0.1,
|
42 |
+
max_tokens=1000
|
43 |
)
|
44 |
|
45 |
+
highlighted_text = response['choices'][0]['message']['content']
|
46 |
+
|
47 |
+
# ์ฌ๊ธฐ์๋ ๊ฐ๋จํ๊ฒ exec ํจ์๋ฅผ ์ด์ฉํด GPT-3.5-turbo๊ฐ ์์ฑํ ์ฝ๋๋ฅผ ์คํํฉ๋๋ค.
|
48 |
+
# ์ค์ ํ๋ก๋์
ํ๊ฒฝ์์๋ ๋ณด์ ์ด์๋ฅผ ๊ณ ๋ คํด์ผ ํฉ๋๋ค.
|
49 |
+
exec(highlighted_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
|
|
51 |
if __name__ == "__main__":
|
52 |
+
main()
|