create a web page thats make possible to upload 2 pdfs, display a preview of the pdfs, and leave a space for comparing the pdfs. the comparison will be mate by LLM
Drop files here
or click to upload
import streamlit as st
from PyPDF2 import PdfReader
from pdf2image import convert_from_bytes
import tempfile
st.title("PDF Comparison Tool")
# Create two columns for PDF uploads
col1, col2 = st.columns(2)
with col1:
st.subheader("First PDF")
pdf1 = st.file_uploader("Upload first PDF", type=['pdf'], key='pdf1')
if pdf1 is not None:
# Read PDF content
pdf_reader1 = PdfReader(pdf1)
text1 = ""
for page in pdf_reader1.pages:
text1 += page.extract_text()
# Display PDF preview
with tempfile.NamedTemporaryFile(suffix='.pdf') as tmp_file:
tmp_file.write(pdf1.getvalue())
images = convert_from_bytes(pdf1.getvalue())
if images:
st.image(images[0], caption='First page preview', use_column_width=True)
# Display extracted text
with st.expander("Show extracted text"):
st.text(text1)
with col2:
st.subheader("Second PDF")
pdf2 = st.file_uploader("Upload second PDF", type=['pdf'], key='pdf2')
if pdf2 is not None:
# Read PDF content
pdf_reader2 = PdfReader(pdf2)
text2 = ""
for page in pdf_reader2.pages:
text2 += page.extract_text()
# Display PDF preview
with tempfile.NamedTemporaryFile(suffix='.pdf') as tmp_file:
tmp_file.write(pdf2.getvalue())
images = convert_from_bytes(pdf2.getvalue())
if images:
st.image(images[0], caption='First page preview', use_column_width=True)
# Display extracted text
with st.expander("Show extracted text"):
st.text(text2)
# Comparison section
st.divider()
st.subheader("PDF Comparison")
if pdf1 is not None and pdf2 is not None:
st.info("""
This is where the LLM comparison would take place.
The comparison could analyze:
- Content differences
- Structure similarities
- Key points comparison
- Summary of changes
To implement the actual comparison, you would need to:
1. Set up an LLM API connection (e.g., OpenAI)
2. Format the extracted text appropriately
3. Send both texts to the LLM with specific comparison instructions
4. Display the results
""")
else:
st.warning("Please upload both PDFs to enable comparison")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?