Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,14 @@
|
|
| 1 |
-
|
| 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 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 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()
|