Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from annotated_text import annotated_text
|
2 |
+
import streamlit as st
|
3 |
+
import openai
|
4 |
+
|
5 |
+
# API ํค ์ค์ (์ค์ OpenAI API ํค๋ก ๋์ฒดํด์ผ ํจ)
|
6 |
+
openai.api_key = "your-openai-api-key"
|
7 |
+
|
8 |
+
# Streamlit ์ฑ ์์
|
9 |
+
def app():
|
10 |
+
st.title("ํค์๋ ๋ถ์")
|
11 |
+
|
12 |
+
user_text = st.text_area("๋ถ์ํ ํ
์คํธ๋ฅผ ๋ถ์ฌ ๋ฃ์ผ์ธ์:", height=300)
|
13 |
+
|
14 |
+
if st.button("ํค์๋ ๋ถ์"):
|
15 |
+
# ํค์๋ ์ถ์ถ ๋ก์ง (GPT๋ฅผ ์ฌ์ฉ)
|
16 |
+
task_description = "Identify key terms in the text."
|
17 |
+
user_prompt = f"{user_text}"
|
18 |
+
messages = [
|
19 |
+
{"role": "system", "content": task_description},
|
20 |
+
{"role": "user", "content": user_prompt},
|
21 |
+
]
|
22 |
+
|
23 |
+
response = openai.Completion.create(
|
24 |
+
model="gpt-3.5-turbo",
|
25 |
+
messages=messages,
|
26 |
+
max_tokens=100,
|
27 |
+
)
|
28 |
+
|
29 |
+
# GPT๋ก๋ถํฐ ๋ฐ์ ์๋ต์ ํ์ฑํ์ฌ ํค์๋ ์ถ์ถ
|
30 |
+
extracted_keywords = response['choices'][0]['message']['content'].split(", ")
|
31 |
+
|
32 |
+
# ๋น ๋ฆฌ์คํธ๋ฅผ ์ด๊ธฐํํ์ฌ ์ฃผ์์ด ๋ฌ๋ฆฐ ํ
์คํธ๋ฅผ ์ ์ฅํฉ๋๋ค.
|
33 |
+
annotated_list = []
|
34 |
+
|
35 |
+
# ํ
์คํธ๋ฅผ ๋จ์ด๋ก ๋ถํ ํ๊ณ , ๊ฐ ๋จ์ด๋ฅผ ๊ฒ์ฌํ์ฌ ์ฃผ์์ ๋ต๋๋ค.
|
36 |
+
for word in user_text.split():
|
37 |
+
if word in extracted_keywords:
|
38 |
+
annotated_list.append((word, 'Keyword'))
|
39 |
+
else:
|
40 |
+
annotated_list.append(word)
|
41 |
+
annotated_list.append(" ") # ์๋์ ๊ณต๋ฐฑ์ ๋ณต์ํฉ๋๋ค.
|
42 |
+
|
43 |
+
# ์ฃผ์์ด ๋ฌ๋ฆฐ ํ
์คํธ๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
|
44 |
+
annotated_text(*annotated_list)
|
45 |
+
|
46 |
+
# Streamlit ์ฑ ์คํ
|
47 |
+
if __name__ == "__main__":
|
48 |
+
app()
|