File size: 1,639 Bytes
e69350d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from annotated_text import annotated_text
import streamlit as st
import openai

# API ํ‚ค ์„ค์ • (์‹ค์ œ OpenAI API ํ‚ค๋กœ ๋Œ€์ฒดํ•ด์•ผ ํ•จ)
openai.api_key = "your-openai-api-key"

# Streamlit ์•ฑ ์‹œ์ž‘
def app():
    st.title("ํ‚ค์›Œ๋“œ ๋ถ„์„")

    user_text = st.text_area("๋ถ„์„ํ•  ํ…์ŠคํŠธ๋ฅผ ๋ถ™์—ฌ ๋„ฃ์œผ์„ธ์š”:", height=300)

    if st.button("ํ‚ค์›Œ๋“œ ๋ถ„์„"):
        # ํ‚ค์›Œ๋“œ ์ถ”์ถœ ๋กœ์ง (GPT๋ฅผ ์‚ฌ์šฉ)
        task_description = "Identify key terms in the text."
        user_prompt = f"{user_text}"
        messages = [
            {"role": "system", "content": task_description},
            {"role": "user", "content": user_prompt},
        ]

        response = openai.Completion.create(
            model="gpt-3.5-turbo",
            messages=messages,
            max_tokens=100,
        )
        
        # GPT๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ์‘๋‹ต์„ ํŒŒ์‹ฑํ•˜์—ฌ ํ‚ค์›Œ๋“œ ์ถ”์ถœ
        extracted_keywords = response['choices'][0]['message']['content'].split(", ")

        # ๋นˆ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜์—ฌ ์ฃผ์„์ด ๋‹ฌ๋ฆฐ ํ…์ŠคํŠธ๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
        annotated_list = []

        # ํ…์ŠคํŠธ๋ฅผ ๋‹จ์–ด๋กœ ๋ถ„ํ• ํ•˜๊ณ , ๊ฐ ๋‹จ์–ด๋ฅผ ๊ฒ€์‚ฌํ•˜์—ฌ ์ฃผ์„์„ ๋‹ต๋‹ˆ๋‹ค.
        for word in user_text.split():
            if word in extracted_keywords:
                annotated_list.append((word, 'Keyword'))
            else:
                annotated_list.append(word)
            annotated_list.append(" ")  # ์›๋ž˜์˜ ๊ณต๋ฐฑ์„ ๋ณต์›ํ•ฉ๋‹ˆ๋‹ค.

        # ์ฃผ์„์ด ๋‹ฌ๋ฆฐ ํ…์ŠคํŠธ๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
        annotated_text(*annotated_list)

# Streamlit ์•ฑ ์‹คํ–‰
if __name__ == "__main__":
    app()