-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
55 lines (43 loc) · 2.25 KB
/
app.py
File metadata and controls
55 lines (43 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
from src.comparison import compare_files, compare_texts
def create_ui():
"""Create the Gradio UI for the diff viewer."""
with gr.Blocks(title="Diff Viewer", theme=gr.themes.Soft()) as app:
gr.Markdown("# Text Difference Viewer")
with gr.Tabs():
with gr.TabItem("File Comparison"):
gr.Markdown("Upload two text files to compare and see word-level differences highlighted.")
with gr.Row():
file1_input = gr.File(label="Original Text File", file_types=["text"])
file2_input = gr.File(label="Modified Text File", file_types=["text"])
compare_btn = gr.Button("Compare Files", variant="primary")
file_diff_output = gr.HTML(label="Differences")
compare_btn.click(
fn=compare_files,
inputs=[file1_input, file2_input],
outputs=file_diff_output
)
with gr.TabItem("Direct Text Comparison"):
gr.Markdown("Paste text directly into the text areas to compare.")
with gr.Row():
text1_input = gr.Textbox(label="Original Text", lines=10, placeholder="Paste original text here...")
text2_input = gr.Textbox(label="Modified Text", lines=10, placeholder="Paste modified text here...")
compare_text_btn = gr.Button("Compare Texts", variant="primary")
text_diff_output = gr.HTML(label="Differences")
compare_text_btn.click(
fn=compare_texts,
inputs=[text1_input, text2_input],
outputs=text_diff_output
)
gr.Markdown("""
## Features
- Word-level difference highlighting
- Synchronized scrolling between panels (can be toggled)
- Line numbers for easy reference
- Statistics showing additions, deletions, and changes
- Support for both file uploads and direct text entry
""")
return app
if __name__ == "__main__":
app = create_ui()
app.launch()