Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,6 +41,13 @@ def semantic_match(lo_list, content):
|
|
| 41 |
scores = [cosine_similarity([content_vec], [vec])[0][0] for vec in vectors[1:]]
|
| 42 |
return scores
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
def compare_all(old_pdf, new_pdf, lo_file):
|
| 45 |
try:
|
| 46 |
los = lo_file.decode("utf-8", errors="ignore").splitlines()
|
|
@@ -57,7 +64,6 @@ def compare_all(old_pdf, new_pdf, lo_file):
|
|
| 57 |
old_scores = semantic_match(los, old_text)
|
| 58 |
new_scores = semantic_match(los, new_text)
|
| 59 |
|
| 60 |
-
# Create bar plot
|
| 61 |
labels = [f"LO{i+1}" for i in range(len(los))]
|
| 62 |
x = range(len(labels))
|
| 63 |
fig, ax = plt.subplots()
|
|
@@ -69,7 +75,6 @@ def compare_all(old_pdf, new_pdf, lo_file):
|
|
| 69 |
ax.set_title("Learning Outcomes Comparison")
|
| 70 |
ax.legend()
|
| 71 |
|
| 72 |
-
# Table
|
| 73 |
data = {
|
| 74 |
"Learning Outcome": labels,
|
| 75 |
"Old Match": [round(s*100, 2) for s in old_scores],
|
|
@@ -78,8 +83,11 @@ def compare_all(old_pdf, new_pdf, lo_file):
|
|
| 78 |
}
|
| 79 |
df = pd.DataFrame(data)
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
| 83 |
summary += f"π’ New content appears {'more' if sum(new_scores) > sum(old_scores) else 'less'} aligned with outcomes."
|
| 84 |
|
| 85 |
return summary, df, fig
|
|
|
|
| 41 |
scores = [cosine_similarity([content_vec], [vec])[0][0] for vec in vectors[1:]]
|
| 42 |
return scores
|
| 43 |
|
| 44 |
+
def compute_change_percentage(old_text, new_text):
|
| 45 |
+
vectorizer = TfidfVectorizer()
|
| 46 |
+
vectors = vectorizer.fit_transform([old_text, new_text])
|
| 47 |
+
cos_sim = cosine_similarity(vectors[0], vectors[1])[0][0]
|
| 48 |
+
change_percentage = round((1 - cos_sim) * 100, 2)
|
| 49 |
+
return change_percentage
|
| 50 |
+
|
| 51 |
def compare_all(old_pdf, new_pdf, lo_file):
|
| 52 |
try:
|
| 53 |
los = lo_file.decode("utf-8", errors="ignore").splitlines()
|
|
|
|
| 64 |
old_scores = semantic_match(los, old_text)
|
| 65 |
new_scores = semantic_match(los, new_text)
|
| 66 |
|
|
|
|
| 67 |
labels = [f"LO{i+1}" for i in range(len(los))]
|
| 68 |
x = range(len(labels))
|
| 69 |
fig, ax = plt.subplots()
|
|
|
|
| 75 |
ax.set_title("Learning Outcomes Comparison")
|
| 76 |
ax.legend()
|
| 77 |
|
|
|
|
| 78 |
data = {
|
| 79 |
"Learning Outcome": labels,
|
| 80 |
"Old Match": [round(s*100, 2) for s in old_scores],
|
|
|
|
| 83 |
}
|
| 84 |
df = pd.DataFrame(data)
|
| 85 |
|
| 86 |
+
change_percentage = compute_change_percentage(old_text, new_text)
|
| 87 |
+
matched_los = sum(1 for s in new_scores if s >= 0.5)
|
| 88 |
+
|
| 89 |
+
summary = f"π Overall Content Change: {change_percentage}%\n"
|
| 90 |
+
summary += f"π― Matched LOs: {matched_los} of {len(los)}\n"
|
| 91 |
summary += f"π’ New content appears {'more' if sum(new_scores) > sum(old_scores) else 'less'} aligned with outcomes."
|
| 92 |
|
| 93 |
return summary, df, fig
|