File size: 1,235 Bytes
d4258c3 f4e9a9a d4258c3 c6fe7ea d4258c3 f4e9a9a b7a26e4 f4e9a9a d4258c3 663efc9 f4e9a9a 663efc9 f4e9a9a d4258c3 f4e9a9a d4258c3 f4e9a9a d4258c3 f4e9a9a | 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 | # Import the required libraries
import openai
# import os
import streamlit as st
# Set the GPT-3 API key
#openai.api_key = st.secrets["pass"] -- uncomment while running
# Read the text of the article from a file
# with open("article.txt", "r") as f:
# article_text = f.read()
article_text = st.text_area("Enter your scientific texts to summarize")
output_size = st.radio(label = "What kind of output do you want?",
options= ["To-The-Point", "Concise", "Detailed"])
if output_size == "To-The-Point":
out_token = 50
elif output_size == "Concise":
out_token = 128
else:
out_token = 516
if len(article_text)>100:
if st.button("Generate Summary",type='primary'):
# Use GPT-3 to generate a summary of the article
response = openai.Completion.create(
engine="text-davinci-002",
prompt="Please summarize this scientific article for me in a few sentences: " + article_text,
max_tokens = out_token,
temperature = 0.5,
)
# Print the generated summary
res = response["choices"][0]["text"]
st.success(res)
st.download_button('Download result', res)
else:
st.warning("Not enough words to summarize!") |