|
from annotated_text import annotated_text |
|
import streamlit as st |
|
import openai |
|
|
|
|
|
openai.api_key = "your-openai-api-key" |
|
|
|
|
|
def app(): |
|
st.title("ํค์๋ ๋ถ์") |
|
|
|
user_text = st.text_area("๋ถ์ํ ํ
์คํธ๋ฅผ ๋ถ์ฌ ๋ฃ์ผ์ธ์:", height=300) |
|
|
|
if st.button("ํค์๋ ๋ถ์"): |
|
|
|
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, |
|
) |
|
|
|
|
|
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) |
|
|
|
|
|
if __name__ == "__main__": |
|
app() |
|
|