Spaces:
Runtime error
Runtime error
viboognesh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -73,16 +73,18 @@ def main():
|
|
73 |
st.session_state.file1 = None
|
74 |
if "file2" not in st.session_state:
|
75 |
st.session_state.file2 = None
|
|
|
|
|
76 |
st.markdown('<div style="text-align: center;">' + '<h1>PDF Upload and Compare App</h1>' + '</div>', unsafe_allow_html=True)
|
77 |
|
78 |
# Create columns for side-by-side buttons
|
79 |
col1, col2 = st.columns([2, 2])
|
80 |
|
81 |
# Add upload button to left column
|
82 |
-
st.session_state.file1 = col1.file_uploader("**
|
83 |
|
84 |
# Add upload button to right column
|
85 |
-
st.session_state.file2 = col2.file_uploader("**
|
86 |
|
87 |
|
88 |
# Check if both files are uploaded
|
@@ -93,10 +95,11 @@ def main():
|
|
93 |
|
94 |
if st.session_state.display_data["file1"] != st.session_state.file1 or st.session_state.display_data["file2"] != st.session_state.file2:
|
95 |
st.session_state.display_data = {"file1": st.session_state.file1, "file2": st.session_state.file2, "i": 0}
|
|
|
96 |
|
97 |
try:
|
98 |
-
extracted_text1 =
|
99 |
-
extracted_text2 =
|
100 |
with col1.expander(filename1):
|
101 |
st.write("\n\n".join("\n\n------------------------\n\n".join(extracted_text1).splitlines()))
|
102 |
|
@@ -137,7 +140,7 @@ def main():
|
|
137 |
reverse_pdata = [{'text1': d['text2'], 'text2': d['text1'], 'explanation': d['explanation']} for d in pdata]
|
138 |
st.session_state.differences_data.append({"etext1": etext2, "etext2": etext1, "pdata": reverse_pdata, "dext1": dext2, "dext2": dext1})
|
139 |
|
140 |
-
display_text = "\n\n\n".join([f"**
|
141 |
|
142 |
with st.expander(f"**Page {i+1}** - {filename1}"):
|
143 |
st.markdown("\n\n".join(dext1.splitlines()), unsafe_allow_html=True)
|
|
|
73 |
st.session_state.file1 = None
|
74 |
if "file2" not in st.session_state:
|
75 |
st.session_state.file2 = None
|
76 |
+
if "extracted_texts" not in st.session_state:
|
77 |
+
st.session_state.extracted_texts = {"file1": None, "file2": None, "extracted_text_1": [], "extracted_text_2": []}
|
78 |
st.markdown('<div style="text-align: center;">' + '<h1>PDF Upload and Compare App</h1>' + '</div>', unsafe_allow_html=True)
|
79 |
|
80 |
# Create columns for side-by-side buttons
|
81 |
col1, col2 = st.columns([2, 2])
|
82 |
|
83 |
# Add upload button to left column
|
84 |
+
st.session_state.file1 = col1.file_uploader("**PDF 1**", type="pdf")
|
85 |
|
86 |
# Add upload button to right column
|
87 |
+
st.session_state.file2 = col2.file_uploader("**PDF 2**", type="pdf")
|
88 |
|
89 |
|
90 |
# Check if both files are uploaded
|
|
|
95 |
|
96 |
if st.session_state.display_data["file1"] != st.session_state.file1 or st.session_state.display_data["file2"] != st.session_state.file2:
|
97 |
st.session_state.display_data = {"file1": st.session_state.file1, "file2": st.session_state.file2, "i": 0}
|
98 |
+
st.session_state.extracted_texts = {"file1": st.session_state.file1, "file2": st.session_state.file2, "extracted_text_1": extract_text_with_pypdf(st.session_state.file1), "extracted_text_2": extract_text_with_pypdf(st.session_state.file2)}
|
99 |
|
100 |
try:
|
101 |
+
extracted_text1 = st.session_state.extracted_texts["extracted_text_1"]
|
102 |
+
extracted_text2 = st.session_state.extracted_texts["extracted_text_2"]
|
103 |
with col1.expander(filename1):
|
104 |
st.write("\n\n".join("\n\n------------------------\n\n".join(extracted_text1).splitlines()))
|
105 |
|
|
|
140 |
reverse_pdata = [{'text1': d['text2'], 'text2': d['text1'], 'explanation': d['explanation']} for d in pdata]
|
141 |
st.session_state.differences_data.append({"etext1": etext2, "etext2": etext1, "pdata": reverse_pdata, "dext1": dext2, "dext2": dext1})
|
142 |
|
143 |
+
display_text = "\n\n\n".join([f"**PDF 1:**\n\n{d['text1']}\n\n**PDF 2:**\n\n{d['text2']}\n\n**Explanation:**\n\n{d['explanation']}\n\n----------------------\n" for d in pdata])
|
144 |
|
145 |
with st.expander(f"**Page {i+1}** - {filename1}"):
|
146 |
st.markdown("\n\n".join(dext1.splitlines()), unsafe_allow_html=True)
|