Spaces:
Sleeping
Sleeping
Upload pptx2pdf_web_en.py
Browse files- pptx2pdf_web_en.py +25 -3
pptx2pdf_web_en.py
CHANGED
@@ -44,7 +44,10 @@ def make_zip_file(files, zip_path):
|
|
44 |
return zip_path
|
45 |
|
46 |
def pptx2pdf_web(pptx_file): # pptx_file is the Gradio file object
|
47 |
-
|
|
|
|
|
|
|
48 |
gradio_temp_file_path = pptx_file.name # Path to the file uploaded by Gradio
|
49 |
|
50 |
# Create a path for our copy of the PPTX inside our own tmpdir
|
@@ -59,10 +62,29 @@ def pptx2pdf_web(pptx_file): # pptx_file is the Gradio file object
|
|
59 |
# convert_pptx_to_pdf will create the PDF also within tmpdir.
|
60 |
pdf_path = convert_pptx_to_pdf(our_copy_of_pptx_path, tmpdir)
|
61 |
|
62 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
zip_path = os.path.join(tmpdir, 'converted.zip')
|
64 |
make_zip_file([pdf_path], zip_path)
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
with gr.Blocks(title="PPTX to PDF Converter - Easily Convert PowerPoint to PDF") as demo:
|
68 |
gr.Markdown("# PPTX to PDF Converter") # Added main title here
|
|
|
44 |
return zip_path
|
45 |
|
46 |
def pptx2pdf_web(pptx_file): # pptx_file is the Gradio file object
|
47 |
+
# Create a temporary directory that won't be auto-deleted
|
48 |
+
tmpdir = tempfile.mkdtemp()
|
49 |
+
|
50 |
+
try:
|
51 |
gradio_temp_file_path = pptx_file.name # Path to the file uploaded by Gradio
|
52 |
|
53 |
# Create a path for our copy of the PPTX inside our own tmpdir
|
|
|
62 |
# convert_pptx_to_pdf will create the PDF also within tmpdir.
|
63 |
pdf_path = convert_pptx_to_pdf(our_copy_of_pptx_path, tmpdir)
|
64 |
|
65 |
+
# Create persistent copies of the output files for Gradio
|
66 |
+
import tempfile as tf
|
67 |
+
|
68 |
+
# Create persistent PDF file
|
69 |
+
pdf_fd, persistent_pdf_path = tf.mkstemp(suffix='.pdf', prefix='converted_')
|
70 |
+
os.close(pdf_fd)
|
71 |
+
shutil.copy2(pdf_path, persistent_pdf_path)
|
72 |
+
|
73 |
+
# Create persistent ZIP file
|
74 |
+
zip_fd, persistent_zip_path = tf.mkstemp(suffix='.zip', prefix='converted_')
|
75 |
+
os.close(zip_fd)
|
76 |
zip_path = os.path.join(tmpdir, 'converted.zip')
|
77 |
make_zip_file([pdf_path], zip_path)
|
78 |
+
shutil.copy2(zip_path, persistent_zip_path)
|
79 |
+
|
80 |
+
return persistent_pdf_path, persistent_zip_path
|
81 |
+
|
82 |
+
finally:
|
83 |
+
# Clean up our temporary directory
|
84 |
+
try:
|
85 |
+
shutil.rmtree(tmpdir)
|
86 |
+
except:
|
87 |
+
pass # Ignore cleanup errors
|
88 |
|
89 |
with gr.Blocks(title="PPTX to PDF Converter - Easily Convert PowerPoint to PDF") as demo:
|
90 |
gr.Markdown("# PPTX to PDF Converter") # Added main title here
|