Spaces:
Running
Running
import gradio as gr | |
from pdf2docx import Converter | |
import os | |
import tempfile | |
def convert_pdf_to_word(pdf_file): | |
if pdf_file is None: | |
return None | |
# Create a temporary file to store the converted Word document | |
with tempfile.NamedTemporaryFile(delete=False, suffix=".docx") as tmp_file: | |
word_file = tmp_file.name | |
# Create converter object and perform conversion | |
cv = Converter(pdf_file.name) | |
cv.convert(word_file) | |
cv.close() | |
return word_file | |
# Create Gradio interface | |
iface = gr.Interface( | |
fn=convert_pdf_to_word, | |
inputs=gr.File(label="Upload PDF File", type="filepath",file_types=["pdf"]), | |
outputs=gr.File(label="Download Word File"), | |
title="PDF to Word Converter", | |
description=""" | |
<p>Converting PDF to Word is a common office task, and this application allows you to convert PDF to Word documents with just one click.</p> | |
<p>Upload a PDF file and download the converted Word document.</p> | |
<p>For more PDF tools, visit: <a href="https://pdf-tools.wingetgui.com/" target="_blank">pdf-tools.wingetgui.com</a></p> | |
""", | |
allow_flagging="never", | |
analytics_enabled=False | |
) | |
# Launch Gradio app | |
iface.launch() |