JUNGU commited on
Commit
e69350d
โ€ข
1 Parent(s): e8e29ad

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
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()