anmolsahai commited on
Commit
93abebf
1 Parent(s): 00abab5
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -2,8 +2,9 @@ import streamlit as st
2
  from langchain_pipeline import pipeline, model_names
3
  import pdfplumber
4
  from docx import Document
5
- from redlines import Redlines
6
  import tempfile
 
7
 
8
  def pdf_to_word(pdf_path, word_path):
9
  with pdfplumber.open(pdf_path) as pdf:
@@ -32,18 +33,19 @@ def redline_changes(original_path, revised_path, output_path):
32
  original_text = "\n".join([para.text for para in original_doc.paragraphs])
33
  revised_text = "\n".join([para.text for para in revised_doc.paragraphs])
34
 
35
- redline = Redlines(original_text, revised_text)
36
- diff_md = redline.output_markdown()
37
 
38
- # Create a new document and add the Markdown content as text
39
  diff_doc = Document()
40
- for line in diff_md.split("\n"):
41
- if line.startswith('- '):
42
  p = diff_doc.add_paragraph(line, style='Normal')
43
  p.font.color.rgb = RGBColor(255, 0, 0) # Red
44
- elif line.startswith('+ '):
45
  p = diff_doc.add_paragraph(line, style='Normal')
46
  p.font.color.rgb = RGBColor(0, 128, 0) # Green
 
 
 
47
  else:
48
  diff_doc.add_paragraph(line, style='Normal')
49
 
 
2
  from langchain_pipeline import pipeline, model_names
3
  import pdfplumber
4
  from docx import Document
5
+ from difflib import unified_diff
6
  import tempfile
7
+ from docx.shared import RGBColor
8
 
9
  def pdf_to_word(pdf_path, word_path):
10
  with pdfplumber.open(pdf_path) as pdf:
 
33
  original_text = "\n".join([para.text for para in original_doc.paragraphs])
34
  revised_text = "\n".join([para.text for para in revised_doc.paragraphs])
35
 
36
+ diff = unified_diff(original_text.splitlines(), revised_text.splitlines(), lineterm='')
 
37
 
 
38
  diff_doc = Document()
39
+ for line in diff:
40
+ if line.startswith('-'):
41
  p = diff_doc.add_paragraph(line, style='Normal')
42
  p.font.color.rgb = RGBColor(255, 0, 0) # Red
43
+ elif line.startswith('+'):
44
  p = diff_doc.add_paragraph(line, style='Normal')
45
  p.font.color.rgb = RGBColor(0, 128, 0) # Green
46
+ elif line.startswith('@@'):
47
+ p = diff_doc.add_paragraph(line, style='Normal')
48
+ p.font.color.rgb = RGBColor(0, 0, 255) # Blue
49
  else:
50
  diff_doc.add_paragraph(line, style='Normal')
51