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 ="""당신은 Python의 st-annotated-text 라이브러리를 위한 주석이 달린 텍스트를 생성하는 유용한 도우미입니다. 본문의 주제를 파악하고 의미를 전달하는 데 필요한 핵심 단어를 강조해야 합니다. 주요 포인트를 파악할 수 있어야 합니다. 또한 제공된 텍스트의 문단의 중심 내용을 기반으로 단어를 표시하세요. 출력은 다음과 같은 형식으로 포맷되어야 합니다: 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}" 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, 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()