import os import gradio as gr import csv def pdf_to_csv(pdf_file): # Open the uploaded PDF file (pdf_file is a TemporaryFile) # pdf_reader = PyPDF2.PdfReader(pdf_file.name) text_lines = [] file_name = os.path.basename(pdf_file.name) text_lines.append(f"File Name: {file_name}") csv_filename = "extracted_text.csv" # Write each line into the CSV file (each line in its own row) with open(csv_filename, "w", newline="", encoding="utf-8") as csvfile: writer = csv.writer(csvfile) for line in text_lines: writer.writerow([line]) # Return the CSV file path so Gradio can offer it as a download return csv_filename # Create a simple single-page Gradio interface demo = gr.Interface( fn=pdf_to_csv, inputs=gr.File(label="Upload PDF", file_types=[".pdf"]), outputs=gr.File(label="Download CSV"), title="PDF to CSV Converter", description="Upload a PDF file, extract its text line-by-line, and download a CSV." ) demo.launch()