innoai commited on
Commit
508b543
·
verified ·
1 Parent(s): 9f7570d

Upload 2 files

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. PptxToPDF +3 -0
  3. pptx2pdf_web_en.py +65 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ PptxToPDF filter=lfs diff=lfs merge=lfs -text
PptxToPDF ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b7e5ce83ba36bdf83d1493ac34ceac0f7e8044339cbf742b92bcb1d9efbe350b
3
+ size 83765926
pptx2pdf_web_en.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import shutil
4
+ import subprocess
5
+ import tempfile
6
+ from zipfile import ZipFile
7
+
8
+ def convert_pptx_to_pdf(pptx_path, output_dir):
9
+ # Call the PptxToPDF console application
10
+ pdf_path = os.path.join(output_dir, os.path.splitext(os.path.basename(pptx_path))[0] + ".pdf")
11
+ result = subprocess.run([
12
+ './PptxToPDF', # Executable name on Linux
13
+ pptx_path
14
+ ], cwd=output_dir, capture_output=True, text=True)
15
+ if result.returncode != 0 or not os.path.exists(pdf_path):
16
+ raise RuntimeError(f"Conversion failed: {result.stderr}")
17
+ return pdf_path
18
+
19
+ def make_zip_file(files, zip_path):
20
+ with ZipFile(zip_path, 'w') as zipf:
21
+ for f in files:
22
+ zipf.write(f, os.path.basename(f))
23
+ return zip_path
24
+
25
+ def pptx2pdf_web(pptx_file):
26
+ with tempfile.TemporaryDirectory() as tmpdir:
27
+ pptx_path = os.path.join(tmpdir, pptx_file.name)
28
+ with open(pptx_path, 'wb') as f:
29
+ f.write(pptx_file.read())
30
+ # Convert
31
+ pdf_path = convert_pptx_to_pdf(pptx_path, tmpdir)
32
+ # Package
33
+ zip_path = os.path.join(tmpdir, 'converted.zip')
34
+ make_zip_file([pdf_path], zip_path)
35
+ return pdf_path, zip_path
36
+
37
+ with gr.Blocks(title="PPTX to PDF Converter - Easily Convert PowerPoint to PDF") as demo:
38
+ gr.Markdown("# PPTX to PDF Converter") # Added main title here
39
+ with gr.Accordion("Application Introduction and Instructions", open=True):
40
+ gr.Markdown("""
41
+ Welcome to the PPTX to PDF Converter! This tool allows you to easily convert your PowerPoint (PPTX) files into PDF documents.
42
+
43
+ **Features:**
44
+ - **Simple Upload:** Easily upload your PPTX file through the web interface.
45
+ - **One-Click Conversion:** Convert your file to PDF with a single click.
46
+ - **Direct PDF Download:** Download the converted PDF file directly.
47
+ - **Zipped Archive:** Optionally, download a ZIP file containing the converted PDF for convenience.
48
+
49
+ **How to Use:**
50
+ 1. **Upload PPTX File:** Click on the "Upload PPTX File" area or drag and drop your `.pptx` file.
51
+ 2. **Click Convert:** Press the "Convert" button to start the conversion process.
52
+ 3. **Download Files:** Once the conversion is complete, download links for the PDF file and a ZIP archive (containing the PDF) will appear. Click on your preferred option to download.
53
+ """)
54
+ gr.Markdown("---")
55
+ with gr.Row():
56
+ with gr.Column():
57
+ pptx_input = gr.File(label="Upload PPTX File", file_types=[".pptx"])
58
+ convert_btn = gr.Button("Convert")
59
+ with gr.Column():
60
+ pdf_output = gr.File(label="Download PDF File")
61
+ zip_output = gr.File(label="Download ZIP Archive")
62
+ convert_btn.click(pptx2pdf_web, inputs=[pptx_input], outputs=[pdf_output, zip_output])
63
+
64
+ demo.queue(default_concurrency_limit=10, max_size=50)
65
+ demo.launch(show_api=False)