File size: 1,719 Bytes
2339806 416f7a4 94914e3 416f7a4 bfece13 94914e3 bfece13 416f7a4 bfece13 416f7a4 bfece13 416f7a4 94914e3 416f7a4 bfece13 416f7a4 94914e3 bfece13 416f7a4 94914e3 416f7a4 94914e3 416f7a4 3fabfeb 94914e3 |
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 |
import gradio as gr
import torch
from transformers import AutoModelForObjectDetection, TableTransformerForObjectDetection
from PIL import Image
from pdf_processing import process_pdf
from io_utils import save_remaining_text_to_txt, save_to_csv
# Process PDF file and save text or data to file
def process_pdf_file(pdf_file):
pdf_path = pdf_file.name # Get the path to the uploaded PDF
output_folder = "./output" # Define the output folder
# Process the PDF file (assuming the function does the necessary work)
processed_text = process_pdf(pdf_path, output_folder) # Modify this based on your function's output
# Save processed text to a text file
txt_file_path = save_remaining_text_to_txt(processed_text, output_folder, 1) # Assuming page_num = 1 for now
# Alternatively, you could generate CSV or any other output
data = [] # Replace with your data
csv_file_path = save_to_csv(data, output_folder, 'processed_data.csv')
# Return file paths as outputs for Gradio
return txt_file_path, csv_file_path
# Create Gradio interface
def create_gradio_interface():
input_pdf = gr.File(label="Upload PDF", type="filepath") # Fixed argument here
output_txt_file = gr.File(label="Download Processed Text", interactive=False)
output_csv_file = gr.File(label="Download Processed CSV", interactive=False)
# Define the interface
interface = gr.Interface(
fn=process_pdf_file,
inputs=input_pdf,
outputs=[output_txt_file, output_csv_file],
live=True
)
return interface
# Start the application
if __name__ == "__main__":
gradio_interface = create_gradio_interface()
gradio_interface.launch() |