Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,11 +46,11 @@ def get_llm_response(extractedtext1, extractedtext2):
|
|
| 46 |
try:
|
| 47 |
differences_list = extract_differences(message_text.split("<differences>")[1].split("</differences>")[0].strip())
|
| 48 |
except Exception as e:
|
| 49 |
-
return message_text
|
| 50 |
|
| 51 |
difference_content = "\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----------------------" for d in differences_list])
|
| 52 |
display_text = f"{before_differences}\n\n{difference_content}\n\n{after_differences}"
|
| 53 |
-
return display_text
|
| 54 |
|
| 55 |
|
| 56 |
def extract_text_with_pypdf(pdf_path):
|
|
@@ -73,7 +73,7 @@ def main():
|
|
| 73 |
|
| 74 |
# Add upload button to right column
|
| 75 |
uploaded_file2 = col2.file_uploader("**Text 2**", type="pdf")
|
| 76 |
-
|
| 77 |
# Check if both files are uploaded
|
| 78 |
if uploaded_file1 and uploaded_file2:
|
| 79 |
# Get filenames from uploaded files
|
|
@@ -96,7 +96,21 @@ def main():
|
|
| 96 |
# Add button at the bottom to run Find Differences function
|
| 97 |
if st.button("Find Differences"):
|
| 98 |
try:
|
| 99 |
-
display_text = get_llm_response(extracted_text1, extracted_text2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
st.markdown(display_text)
|
| 101 |
except Exception as e:
|
| 102 |
st.error(f"Error finding differences: {str(e)}")
|
|
|
|
| 46 |
try:
|
| 47 |
differences_list = extract_differences(message_text.split("<differences>")[1].split("</differences>")[0].strip())
|
| 48 |
except Exception as e:
|
| 49 |
+
return message_text, []
|
| 50 |
|
| 51 |
difference_content = "\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----------------------" for d in differences_list])
|
| 52 |
display_text = f"{before_differences}\n\n{difference_content}\n\n{after_differences}"
|
| 53 |
+
return display_text, differences_list
|
| 54 |
|
| 55 |
|
| 56 |
def extract_text_with_pypdf(pdf_path):
|
|
|
|
| 73 |
|
| 74 |
# Add upload button to right column
|
| 75 |
uploaded_file2 = col2.file_uploader("**Text 2**", type="pdf")
|
| 76 |
+
|
| 77 |
# Check if both files are uploaded
|
| 78 |
if uploaded_file1 and uploaded_file2:
|
| 79 |
# Get filenames from uploaded files
|
|
|
|
| 96 |
# Add button at the bottom to run Find Differences function
|
| 97 |
if st.button("Find Differences"):
|
| 98 |
try:
|
| 99 |
+
display_text, parsed_data = get_llm_response(extracted_text1, extracted_text2)
|
| 100 |
+
display_text1 = extracted_text1
|
| 101 |
+
display_text2 = extracted_text2
|
| 102 |
+
|
| 103 |
+
for diff in parsed_data:
|
| 104 |
+
diff_text1 = diff['text1'].strip()
|
| 105 |
+
diff_text2 = diff['text2'].strip()
|
| 106 |
+
display_text1 = f"**{diff_text1}**".join(display_text1.split(diff_text1)) if diff_text1 in display_text1
|
| 107 |
+
display_text2 = f"**{diff_text2}**".join(display_text2.split(diff_text2)) if diff_text2 in display_text2
|
| 108 |
+
with col1.expander(filename1):
|
| 109 |
+
st.write(display_text1)
|
| 110 |
+
|
| 111 |
+
with col2.expander(filename2):
|
| 112 |
+
st.write(display_text2)
|
| 113 |
+
|
| 114 |
st.markdown(display_text)
|
| 115 |
except Exception as e:
|
| 116 |
st.error(f"Error finding differences: {str(e)}")
|