Deevyankar commited on
Commit
e1fb09a
Β·
verified Β·
1 Parent(s): 4c891c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -1,6 +1,6 @@
1
 
2
  import gradio as gr
3
- import fitz
4
  from sentence_transformers import SentenceTransformer, util
5
  import matplotlib.pyplot as plt
6
  import pandas as pd
@@ -10,11 +10,13 @@ model = SentenceTransformer("all-MiniLM-L6-v2")
10
 
11
  def extract_text_pdf(file_obj):
12
  try:
13
- with fitz.open(stream=file_obj, filetype="pdf") as doc:
14
- text = ""
15
- for page in doc:
16
- text += page.get_text()
17
- return text if text.strip() else None
 
 
18
  except:
19
  return None
20
 
@@ -51,7 +53,11 @@ def compare_all(old_pdf, new_pdf, lo_file):
51
  summary += "πŸ†• Significant changes detected."
52
 
53
  # LO comparison
54
- los = lo_file.read().decode("utf-8").splitlines()
 
 
 
 
55
  old_scores = compare_with_los(old_text, los)
56
  new_scores = compare_with_los(new_text, los)
57
  score_diff = [round(new - old, 2) for old, new in zip(old_scores, new_scores)]
@@ -92,8 +98,8 @@ iface = gr.Interface(
92
  gr.Plot(label="LO-wise Bar Chart"),
93
  gr.HTML(label="LO-wise Comparison Table")
94
  ],
95
- title="πŸ“˜ Semantic Handout Comparator with LO Alignment",
96
- description="Compare course handouts for overall change and LO alignment using transformer models."
97
  )
98
 
99
  iface.launch()
 
1
 
2
  import gradio as gr
3
+ from PyPDF2 import PdfReader
4
  from sentence_transformers import SentenceTransformer, util
5
  import matplotlib.pyplot as plt
6
  import pandas as pd
 
10
 
11
  def extract_text_pdf(file_obj):
12
  try:
13
+ pdf_reader = PdfReader(file_obj)
14
+ text = ""
15
+ for page in pdf_reader.pages:
16
+ extracted = page.extract_text()
17
+ if extracted:
18
+ text += extracted + "\n"
19
+ return text if text.strip() else None
20
  except:
21
  return None
22
 
 
53
  summary += "πŸ†• Significant changes detected."
54
 
55
  # LO comparison
56
+ los = lo_file.read().decode("utf-8", errors="ignore").splitlines()
57
+ los = [lo.strip() for lo in los if lo.strip()]
58
+ if not los:
59
+ return summary + "\n⚠️ No valid Learning Outcomes found.", None, None
60
+
61
  old_scores = compare_with_los(old_text, los)
62
  new_scores = compare_with_los(new_text, los)
63
  score_diff = [round(new - old, 2) for old, new in zip(old_scores, new_scores)]
 
98
  gr.Plot(label="LO-wise Bar Chart"),
99
  gr.HTML(label="LO-wise Comparison Table")
100
  ],
101
+ title="πŸ“˜ Semantic Handout Comparator with LO Alignment (Fixed)",
102
+ description="Compare course handouts and learning outcomes using robust PDF reading and transformers."
103
  )
104
 
105
  iface.launch()