Spaces:
Runtime error
Runtime error
viboognesh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -106,45 +106,46 @@ def main():
|
|
106 |
st.success(f"Content of files **{filename1}** and **{filename2}** have been extracted successfully.")
|
107 |
except Exception as e:
|
108 |
st.error(f"Error saving files: {str(e)}")
|
109 |
-
|
110 |
-
try:
|
111 |
-
# display_text, parsed_data = process_concurrently(extracted_text1, extracted_text2)
|
112 |
-
# display_text, parsed_data = get_llm_response(extracted_text1, extracted_text2)
|
113 |
-
|
114 |
-
for i,(etext1, etext2) in enumerate(zip(extracted_text1, extracted_text2)):
|
115 |
-
if i >= st.session_state.display_data["i"]: break
|
116 |
-
data = next((d for d in st.session_state.differences_data if d['etext1'] == etext1 and d['etext2'] == etext2), None)
|
117 |
-
if data:
|
118 |
-
pdata = data['pdata']
|
119 |
-
dext1 = data['dext1']
|
120 |
-
dext2 = data['dext2']
|
121 |
-
else:
|
122 |
-
pdata = get_llm_response(etext1, etext2)
|
123 |
-
dext1 = etext1
|
124 |
-
dext2 = etext2
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
diff_text1_phrase = "\n".join([f"<span style='background-color: grey;'>{t}</span>" for t in diff_text1.splitlines()])
|
131 |
-
diff_text2_phrase = "\n".join([f"<span style='background-color: grey;'>{t}</span>" for t in diff_text2.splitlines()])
|
132 |
-
dext1 = diff_text1_phrase.join(dext1.split(diff_text1)) if diff_text1 in dext1 else dext1
|
133 |
-
dext2 = diff_text2_phrase.join(dext2.split(diff_text2)) if diff_text2 in dext2 else dext2
|
134 |
-
|
135 |
-
st.session_state.differences_data.append({"etext1": etext1, "etext2": etext2, "pdata": pdata, "dext1": dext1, "dext2": dext2})
|
136 |
-
reverse_pdata = [{'text1': d['text2'], 'text2': d['text1'], 'explanation': d['explanation']} for d in pdata]
|
137 |
-
st.session_state.differences_data.append({"etext1": etext2, "etext2": etext1, "pdata": reverse_pdata, "dext1": dext2, "dext2": dext1})
|
138 |
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
|
150 |
# Add button at the bottom to run Find Differences function
|
|
|
106 |
st.success(f"Content of files **{filename1}** and **{filename2}** have been extracted successfully.")
|
107 |
except Exception as e:
|
108 |
st.error(f"Error saving files: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
+
with st.spinner("Processing Pages within the PDFS"):
|
111 |
+
try:
|
112 |
+
# display_text, parsed_data = process_concurrently(extracted_text1, extracted_text2)
|
113 |
+
# display_text, parsed_data = get_llm_response(extracted_text1, extracted_text2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
+
for i,(etext1, etext2) in enumerate(zip(extracted_text1, extracted_text2)):
|
116 |
+
if i >= st.session_state.display_data["i"]: break
|
117 |
+
data = next((d for d in st.session_state.differences_data if d['etext1'] == etext1 and d['etext2'] == etext2), None)
|
118 |
+
if data:
|
119 |
+
pdata = data['pdata']
|
120 |
+
dext1 = data['dext1']
|
121 |
+
dext2 = data['dext2']
|
122 |
+
else:
|
123 |
+
pdata = get_llm_response(etext1, etext2)
|
124 |
+
dext1 = etext1
|
125 |
+
dext2 = etext2
|
126 |
+
|
127 |
+
for diff in pdata:
|
128 |
+
diff_text1 = diff['text1'].strip()
|
129 |
+
diff_text2 = diff['text2'].strip()
|
130 |
+
if diff_text1 == "" or diff_text2 == "": continue
|
131 |
+
diff_text1_phrase = "\n".join([f"<span style='background-color: grey;'>{t}</span>" for t in diff_text1.splitlines()])
|
132 |
+
diff_text2_phrase = "\n".join([f"<span style='background-color: grey;'>{t}</span>" for t in diff_text2.splitlines()])
|
133 |
+
dext1 = diff_text1_phrase.join(dext1.split(diff_text1)) if diff_text1 in dext1 else dext1
|
134 |
+
dext2 = diff_text2_phrase.join(dext2.split(diff_text2)) if diff_text2 in dext2 else dext2
|
135 |
+
|
136 |
+
st.session_state.differences_data.append({"etext1": etext1, "etext2": etext2, "pdata": pdata, "dext1": dext1, "dext2": dext2})
|
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"**Text1:**\n\n{d['text1']}\n\n**Text2:**\n\n{d['text2']}\n\n**Explanation:**\n\n{d['explanation']}\n\n----------------------\n" for d in pdata])
|
141 |
+
|
142 |
+
with st.expander(f"**Page {i+1}** - {filename1}"):
|
143 |
+
st.markdown("\n\n".join(dext1.splitlines()), unsafe_allow_html=True)
|
144 |
+
with st.expander(f"**Page {i+1}** - {filename2}"):
|
145 |
+
st.markdown("\n\n".join(dext2.splitlines()), unsafe_allow_html=True)
|
146 |
+
st.markdown(display_text)
|
147 |
+
except Exception as e:
|
148 |
+
st.error(f"Error finding differences: {str(e)}")
|
149 |
|
150 |
|
151 |
# Add button at the bottom to run Find Differences function
|