Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
|
| 2 |
import gradio as gr
|
| 3 |
-
import
|
| 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 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 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
|
| 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()
|