-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
43 lines (33 loc) · 1.54 KB
/
app.py
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
# Import necessary libraries
import streamlit as st
from utils import extract_text_from_pdf, summarize, chunk_text
def main():
st.title("Summarizer")
st.header("Upload a PDF and get a summary of it in seconds!")
# allow user to put in user_prompt, system_prompt, and document_prompt
user_prompt = st.text_input("What would you like to ask the system?")
system_prompt = st.text_input("What would you like the system to say?")
model = st.selectbox("Select a model", ["gpt-4"])
# Create a file uploader widget
uploaded_file = st.file_uploader("Upload a PDF", type="pdf")
if uploaded_file is not None:
# allow user to choose a range of pages to summarize instead of all PDF pages
page_range = st.text_input(
"Enter the range of pages to summarize (e.g., '1-5'). Leave blank for all pages."
)
if st.button("Summarize"):
# Use utility function to extract text from PDF
pdf_text = extract_text_from_pdf(uploaded_file, page_range)
# chunk pdf_text using utility function
pdf_chunks = chunk_text(pdf_text)
# print(pdf_chunks)
# Use utility function to generate summary in markdown format
summary = ""
for chunk in pdf_chunks:
summary += summarize(chunk["text"], user_prompt, system_prompt, model)
print(summary)
# Display the summary
st.markdown(summary)
# Run the main function to start the Streamlit app
if __name__ == "__main__":
main()