|
|
|
|
|
import os
|
|
|
|
import gradio as gr
|
|
import csv
|
|
|
|
def pdf_to_csv(pdf_file):
|
|
|
|
|
|
text_lines = []
|
|
|
|
file_name = os.path.basename(pdf_file.name)
|
|
|
|
text_lines.append(f"File Name: {file_name}")
|
|
csv_filename = "extracted_text.csv"
|
|
|
|
with open(csv_filename, "w", newline="", encoding="utf-8") as csvfile:
|
|
writer = csv.writer(csvfile)
|
|
for line in text_lines:
|
|
writer.writerow([line])
|
|
|
|
|
|
return csv_filename
|
|
|
|
|
|
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()
|
|
|
|
|