Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,8 @@ import difflib
|
|
8 |
|
9 |
|
10 |
def compare_and_highlight(text1, text2):
|
|
|
|
|
11 |
matcher = difflib.SequenceMatcher(None, text1, text2)
|
12 |
output = ''
|
13 |
for op, a1, a2, b1, b2 in matcher.get_opcodes():
|
@@ -20,6 +22,7 @@ def compare_and_highlight(text1, text2):
|
|
20 |
elif op == 'replace':
|
21 |
# Handle replacements (more complex)
|
22 |
output += f"<del>{text1[a1:a2]}</del> <ins>{text2[b1:b2]}</ins>"
|
|
|
23 |
return output
|
24 |
|
25 |
|
@@ -83,10 +86,11 @@ with gr.Blocks() as demo:
|
|
83 |
comparison_result = gr.Textbox(label="Comparison Result")
|
84 |
|
85 |
# Event handlers
|
|
|
|
|
86 |
compare_button.click(lambda: compare_and_highlight(text1.value, text2.value), [], comparison_result)
|
87 |
|
88 |
|
89 |
-
generate_button.click(predict, [image, model_choice], caption) # Trigger prediction on button click
|
90 |
# sample_images_gallery.change(predict, [sample_images_gallery, model_choice], caption) # Handle sample images
|
91 |
|
92 |
|
|
|
8 |
|
9 |
|
10 |
def compare_and_highlight(text1, text2):
|
11 |
+
print("Triggered function")
|
12 |
+
|
13 |
matcher = difflib.SequenceMatcher(None, text1, text2)
|
14 |
output = ''
|
15 |
for op, a1, a2, b1, b2 in matcher.get_opcodes():
|
|
|
22 |
elif op == 'replace':
|
23 |
# Handle replacements (more complex)
|
24 |
output += f"<del>{text1[a1:a2]}</del> <ins>{text2[b1:b2]}</ins>"
|
25 |
+
print(output)
|
26 |
return output
|
27 |
|
28 |
|
|
|
86 |
comparison_result = gr.Textbox(label="Comparison Result")
|
87 |
|
88 |
# Event handlers
|
89 |
+
|
90 |
+
generate_button.click(predict, [image, model_choice], caption) # Trigger prediction on button click
|
91 |
compare_button.click(lambda: compare_and_highlight(text1.value, text2.value), [], comparison_result)
|
92 |
|
93 |
|
|
|
94 |
# sample_images_gallery.change(predict, [sample_images_gallery, model_choice], caption) # Handle sample images
|
95 |
|
96 |
|