Deevyankar commited on
Commit
c751150
·
verified ·
1 Parent(s): c8667dc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
+ import difflib
4
+
5
+ def compare_docs(old_text, new_text):
6
+ old_lines = old_text.splitlines()
7
+ new_lines = new_text.splitlines()
8
+
9
+ diff = difflib.unified_diff(old_lines, new_lines)
10
+ changes = list(diff)
11
+
12
+ added = [line for line in changes if line.startswith('+') and not line.startswith('+++')]
13
+ removed = [line for line in changes if line.startswith('-') and not line.startswith('---')]
14
+
15
+ percent_change = (len(added) + len(removed)) / max(len(old_lines), 1) * 100
16
+ result = f"📈 Content Updated: {percent_change:.2f}%\n\n"
17
+ result += f"🔼 Added Lines: {len(added)}\n🔽 Removed Lines: {len(removed)}\n\n"
18
+
19
+ return result + "\n".join(changes[:100]) # show first 100 lines of diff
20
+
21
+ iface = gr.Interface(
22
+ fn=compare_docs,
23
+ inputs=[
24
+ gr.Textbox(label="Old Version", lines=20, placeholder="Paste old document text here..."),
25
+ gr.Textbox(label="New Version", lines=20, placeholder="Paste new document text here...")
26
+ ],
27
+ outputs="text",
28
+ title="Document Update Comparator",
29
+ description="Upload or paste old and new version of a document to compare changes and calculate % updated."
30
+ )
31
+
32
+ iface.launch()