Spaces:
Build error
Build error
File size: 1,164 Bytes
838db1d 25dac45 cfb09b2 25dac45 cfb09b2 25dac45 cfb09b2 25dac45 cfb09b2 25dac45 cfb09b2 25dac45 cfb09b2 25dac45 cfb09b2 25dac45 cfb09b2 af49e40 |
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 |
from pdfitdown.pdfconversion import Converter
import warnings
from typing import List
import gradio as gr
import os
class FileNotConvertedWarning(Warning):
"""The file was not in one of the specified formats for conversion to PDF,thus it was not converted"""
def to_pdf(files: List[str]) -> List[str]:
pdfs = []
converter = Converter()
for fl in files:
try:
outf = converter.convert(fl, fl.replace(os.path.splitext(fl)[1], ".pdf"))
except Exception as e:
warnings.warn(f"File {fl} not converted because of an error during the conversion: {e}", FileNotConvertedWarning)
else:
pdfs.append(outf)
return pdfs
def convert_files(files: List[str]) -> List[str]:
pdfs = to_pdf(files)
return pdfs
iface = gr.Interface(
fn=convert_files,
inputs=gr.File(label="Upload your file", file_count="multiple"),
outputs=gr.File(label="Converted PDF", file_count="multiple"),
title="File to PDF Converter",
description="Upload a file in .docx, .xlsx, .html, .pptx, .json, .csv, .xml, .md, .jpg/.jpeg, .png format, and get it converted to PDF."
)
iface.launch(share=True)
|