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()
|