Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
import fitz # PyMuPDF
|
| 5 |
import docx
|
|
@@ -57,15 +56,6 @@ def content_change_score(text1, text2):
|
|
| 57 |
except:
|
| 58 |
return 100.0
|
| 59 |
|
| 60 |
-
def structure_score(text):
|
| 61 |
-
toc_score = 5 if "table of contents" in text.lower() else 0
|
| 62 |
-
bullet_score = 5 if len(re.findall(r"\n\s*[-β’*]", text)) > 10 else 0
|
| 63 |
-
return toc_score + bullet_score
|
| 64 |
-
|
| 65 |
-
def calculate_weighted_score(content_diff, improved_los, total_los, struct_score=10):
|
| 66 |
-
lo_component = (improved_los / total_los) * 100 if total_los > 0 else 0
|
| 67 |
-
return round(0.6 * lo_component + 0.3 * content_diff + 0.1 * struct_score, 2)
|
| 68 |
-
|
| 69 |
def compare_handouts(old_pdf, new_pdf, lo_file):
|
| 70 |
old_text = extract_text_from_pdf(old_pdf)
|
| 71 |
new_text = extract_text_from_pdf(new_pdf)
|
|
@@ -80,23 +70,22 @@ def compare_handouts(old_pdf, new_pdf, lo_file):
|
|
| 80 |
old_scores = semantic_match(lo_list, old_text)
|
| 81 |
new_scores = semantic_match(lo_list, new_text)
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
weighted_score = calculate_weighted_score(content_diff, improved_count, len(lo_list), struct_score)
|
| 89 |
|
| 90 |
-
|
| 91 |
-
summary += f"π Content Change Estimate: {content_diff}%\n"
|
| 92 |
-
summary += f"ποΈ Structure Score: {struct_score}/10\n"
|
| 93 |
-
summary += f"π’ Final Weighted Score: {weighted_score}%\n"
|
| 94 |
|
|
|
|
|
|
|
|
|
|
| 95 |
if improved_count > 0:
|
| 96 |
-
summary += "
|
| 97 |
else:
|
| 98 |
-
summary += "
|
| 99 |
|
|
|
|
| 100 |
x = np.arange(len(lo_list))
|
| 101 |
width = 0.35
|
| 102 |
fig, ax = plt.subplots()
|
|
@@ -112,8 +101,8 @@ def compare_handouts(old_pdf, new_pdf, lo_file):
|
|
| 112 |
return summary, fig
|
| 113 |
|
| 114 |
with gr.Blocks() as demo:
|
| 115 |
-
gr.Markdown("π **Educational Content Comparator
|
| 116 |
-
gr.Markdown("Upload
|
| 117 |
|
| 118 |
with gr.Row():
|
| 119 |
old_pdf = gr.File(label="π Upload Old PDF", file_types=[".pdf"], type="binary")
|
|
@@ -124,7 +113,7 @@ with gr.Blocks() as demo:
|
|
| 124 |
btn = gr.Button("Submit")
|
| 125 |
clear_btn = gr.Button("Clear")
|
| 126 |
|
| 127 |
-
output_text = gr.Textbox(label="π Summary", lines=6)
|
| 128 |
output_plot = gr.Plot(label="π LO Match Chart")
|
| 129 |
|
| 130 |
btn.click(fn=compare_handouts, inputs=[old_pdf, new_pdf, lo_file], outputs=[output_text, output_plot])
|
|
|
|
| 1 |
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import fitz # PyMuPDF
|
| 4 |
import docx
|
|
|
|
| 56 |
except:
|
| 57 |
return 100.0
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
def compare_handouts(old_pdf, new_pdf, lo_file):
|
| 60 |
old_text = extract_text_from_pdf(old_pdf)
|
| 61 |
new_text = extract_text_from_pdf(new_pdf)
|
|
|
|
| 70 |
old_scores = semantic_match(lo_list, old_text)
|
| 71 |
new_scores = semantic_match(lo_list, new_text)
|
| 72 |
|
| 73 |
+
content_diff_percent = content_change_score(old_text, new_text)
|
| 74 |
+
lo_improvements = [round(new - old, 2) for new, old in zip(new_scores, old_scores)]
|
| 75 |
+
improved_count = sum([diff > 0.01 for diff in lo_improvements])
|
| 76 |
+
improved_total = sum([diff for diff in lo_improvements if diff > 0])
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
lo_change_percent = round((improved_total / len(lo_list)) * 100, 2)
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
summary = f"π§ Improved LOs: {improved_count} / {len(lo_list)} (Total improvement score: {improved_total})\n"
|
| 81 |
+
summary += f"π Content Change Estimate: {content_diff_percent}%\n"
|
| 82 |
+
summary += f"π― LO Change Estimate: {lo_change_percent}%\n"
|
| 83 |
if improved_count > 0:
|
| 84 |
+
summary += "π’ Summary: New handout better aligns with LOs and has improved clarity."
|
| 85 |
else:
|
| 86 |
+
summary += "β οΈ Summary: No significant improvement in LO alignment."
|
| 87 |
|
| 88 |
+
# Plot
|
| 89 |
x = np.arange(len(lo_list))
|
| 90 |
width = 0.35
|
| 91 |
fig, ax = plt.subplots()
|
|
|
|
| 101 |
return summary, fig
|
| 102 |
|
| 103 |
with gr.Blocks() as demo:
|
| 104 |
+
gr.Markdown("π **Educational Content Comparator**")
|
| 105 |
+
gr.Markdown("Upload 2 handouts and a .docx file of Learning Outcomes to compare changes and alignment.")
|
| 106 |
|
| 107 |
with gr.Row():
|
| 108 |
old_pdf = gr.File(label="π Upload Old PDF", file_types=[".pdf"], type="binary")
|
|
|
|
| 113 |
btn = gr.Button("Submit")
|
| 114 |
clear_btn = gr.Button("Clear")
|
| 115 |
|
| 116 |
+
output_text = gr.Textbox(label="π Summary", lines=6, interactive=False)
|
| 117 |
output_plot = gr.Plot(label="π LO Match Chart")
|
| 118 |
|
| 119 |
btn.click(fn=compare_handouts, inputs=[old_pdf, new_pdf, lo_file], outputs=[output_text, output_plot])
|