keyword / app.py
JUNGU's picture
Update app.py
22a2b21
raw
history blame
4.49 kB
from annotated_text import annotated_text
import streamlit as st
import openai
import os
# OpenAI API ์„ค์ • (ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ ์ฝ์–ด์˜ด)
openai.api_key = os.getenv("OPENAI_API_KEY") # ์‹ค์ œ ์ฝ”๋“œ์—์„œ ์ฃผ์„ ํ•ด์ œ
def main():
st.title("Keyword Highlighter")
user_text = st.text_area("Please enter your text here:", "")
if st.button("Find Keywords"):
# # few-shot learning์„ ์ด์šฉํ•œ task_description
# task_description = """You are a useful helper that generates annotated text for Python's st-annotated-text library. Your job is to identify the topic of the fingerprint and highlight the key words needed to convey meaning. The output should be formatted in the following way:
# annotated_text(
# "This ",
# ("is", ""),
# " some ",
# ("annotated", ""),
# ("text", ""),
# " for those of ",
# ("you", ""),
# " who ",
# ("like", ""),
# " this sort of ",
# ("thing", ""),
# ". "
# )"""
# task_description = """ You are a useful helper that generates annotated text for Python's st-annotated-text library. Your task is to identify the topic of the passage and highlight the key words needed to convey the meaning. You should be able to identify the main points. Also, please mark keywords based on the different paragraphs and headings provided in the text. The output should be formatted in the following way:
# annotated_text(
# "This ",
# ("is", ""),
# " some ",
# ("annotated", ""),
# ("text", ""),
# " for those of ",
# ("you", ""),
# " who ",
# ("like", ""),
# " this sort of ",
# ("thing", ""),
# ". "
# )"""
# ํ•œ๊ตญ์–ด ํ”„๋กฌํ”„ํŠธ
task_description ="""You are a useful helper that generates annotated text for Python's st-annotated-text library. Your task is to identify the topic of the passage and highlight the key words needed to convey the meaning. You should be able to identify the main points. Also, please mark keywords based on the different paragraphs and headings provided in the text. The output should be formatted in the following way:
annotated_text(
"This ",
("is", ""),
" some ",
("annotated", ""),
("text", ""),
" for those of ",
("you", ""),
" who ",
("like", ""),
" this sort of ",
("thing", ""),
". "
)"""
# user_prompt = f"Now, please annotate this text: {user_text}"
# #์ถœ๋ ฅ ๊ดœ์ฐฎ๊ฒŒ ๋‚˜์˜ด1
# task_description = """You are a helpful assistant that generates annotated text for the st-annotated-text library in Python. Your task is to highlight the key terms that are central to the overall topic or theme of the sentence. Your output should be formatted in the following way:
# annotated_text(
# "This ",
# ("is", ""),
# " some ",
# ("annotated", ""),
# ("text", ""),
# " for those of ",
# ("you", ""),
# " who ",
# ("like", ""),
# " this sort of ",
# ("thing", ""),
# ". "
# )"""
# user_prompt = f"Based on the task description, annotate the following text by highlighting key words about the topic: {user_text}"
user_prompt = f"First, extract key words for the topic st-annotated-text format.: {user_text}"
messages = [{"role": "system", "content": task_description}, {"role": "user", "content": user_prompt}]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k",
messages=messages,
temperature=0.1,
max_tokens=2500,
top_p=0.2,
frequency_penalty=0,
presence_penalty=0
)
highlighted_text = response['choices'][0]['message']['content']
# ์—ฌ๊ธฐ์„œ๋Š” ๊ฐ„๋‹จํ•˜๊ฒŒ exec ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด GPT-3.5-turbo๊ฐ€ ์ƒ์„ฑํ•œ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
# ์‹ค์ œ ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ์—์„œ๋Š” ๋ณด์•ˆ ์ด์Šˆ๋ฅผ ๊ณ ๋ คํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
exec(highlighted_text)
if __name__ == "__main__":
main()