File size: 4,615 Bytes
e69350d 4e2a346 e69350d 4e2a346 e69350d 924cf8c 79962ad e076670 79962ad 4297a96 3f3b508 252924f 03cbafc 4297a96 d432e9d 9ef62b2 03cbafc 9ef62b2 924cf8c 3f3b508 e69350d 3f3b508 dd91754 e69350d 924cf8c e69350d 924cf8c |
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
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", ""),
". "
)"""
#์ถ๋ ฅ ํ์ธํ๋ ์ฌ๋ฌ๋ถ์ Python์ st-annotated-text ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ํด ์ฃผ์์ด ๋ฌ๋ฆฐ ํ
์คํธ๋ฅผ ์์ฑํ๋ ์ ์ฉํ ๋์ฐ๋ฏธ์
๋๋ค. ์ง๋ฌธ์ ์ฃผ์ ๋ฅผ ํ์
ํ๊ณ ์๋ฏธ ์ ๋ฌ์ ํ์ํ ํต์ฌ์ด๋ฅผ ๊ฐ์กฐ ํ์ํ๋ ๊ฒ์ด ์ฌ๋ฌ๋ถ์ ์๋ฌด์
๋๋ค. ์ถ๋ ฅ๋ฌผ์ ํ์์ ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ์์ผ๋ก ์ง์ ํด์ผ ํฉ๋๋ค.
# 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", ""),
# ". "
# )"""
# 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, please annotate the following text by highlighting the key terms central to its topic : {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=1.3,
max_tokens=2500,
top_p=1,
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() |