nelsonjq commited on
Commit
46048a7
·
verified ·
1 Parent(s): 6a4f531

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -18
app.py CHANGED
@@ -1,11 +1,14 @@
1
- from gradio import Interface, File, Dropdown, Button, HTML
2
  import pandas as pd
3
  import os
4
  from utils import pdf_to_text, align_text
5
 
6
  def process_files(source_file, target_file, lang1, lang2):
7
  if source_file is None or target_file is None:
8
- return "Please upload both PDF files."
 
 
 
9
 
10
  # Convert PDFs to text
11
  text_content1 = pdf_to_text(source_file.name)
@@ -24,22 +27,21 @@ def process_files(source_file, target_file, lang1, lang2):
24
  return aligned_html, excel_path
25
 
26
  # Define the Gradio interface
27
- interface = Interface(
28
- fn=process_files,
29
- inputs=[
30
- File(label="Upload Source PDF"),
31
- File(label="Upload Target PDF"),
32
- Dropdown(choices=["en", "es", "fr", "ch", "ar", "ru", "pt", "sw"], label="Select Language 1"),
33
- Dropdown(choices=["en", "es", "fr", "ch", "ar", "ru", "pt", "sw"], label="Select Language 2"),
34
- ],
35
- outputs=[
36
- HTML(label="Aligned DataFrame"),
37
- File(label="Download Aligned Data as Excel")
38
- ],
39
- title="PDF Text Aligner",
40
- live=True,
41
- description="Upload two PDF files and select languages to align the text."
42
- )
43
 
44
  if __name__ == "__main__":
45
  interface.launch()
 
1
+ import gradio as gr
2
  import pandas as pd
3
  import os
4
  from utils import pdf_to_text, align_text
5
 
6
  def process_files(source_file, target_file, lang1, lang2):
7
  if source_file is None or target_file is None:
8
+ return "Please upload both PDF files.", None
9
+
10
+ if lang1 == lang2:
11
+ return "Please select different languages.", None
12
 
13
  # Convert PDFs to text
14
  text_content1 = pdf_to_text(source_file.name)
 
27
  return aligned_html, excel_path
28
 
29
  # Define the Gradio interface
30
+ with gr.Blocks() as interface:
31
+ gr.Markdown("# PDF Text Aligner\nUpload two PDF files and select languages to align the text.")
32
+ source_file = gr.File(label="Upload Source PDF")
33
+ target_file = gr.File(label="Upload Target PDF")
34
+ lang1 = gr.Dropdown(choices=["en", "es", "fr", "ch", "ar", "ru", "pt-br", "sw"], label="Select Language 1")
35
+ lang2 = gr.Dropdown(choices=["en", "es", "fr", "ch", "ar", "ru", "pt-br", "sw"], label="Select Language 2", value="es")
36
+ start_button = gr.Button(value="Start")
37
+ aligned_html = gr.HTML(label="Aligned DataFrame")
38
+ download_button = gr.File(label="Download Aligned Data as Excel")
39
+
40
+ start_button.click(
41
+ fn=process_files,
42
+ inputs=[source_file, target_file, lang1, lang2],
43
+ outputs=[aligned_html, download_button]
44
+ )
 
45
 
46
  if __name__ == "__main__":
47
  interface.launch()