|
from annotated_text import annotated_text |
|
import streamlit as st |
|
import openai |
|
import os |
|
|
|
|
|
|
|
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"): |
|
|
|
|
|
task_description = """You are a helpful assistant that generates annotated text for the st-annotated-text library in Python. Highlight the key terms that are most important in the context 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"Now, please annotate this text: {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=1000 |
|
) |
|
|
|
highlighted_text = response['choices'][0]['message']['content'] |
|
|
|
|
|
|
|
exec(highlighted_text) |
|
|
|
if __name__ == "__main__": |
|
main() |