keyword / app.py
JUNGU's picture
Create app.py
e69350d
raw history blame
No virus
1.64 kB
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()