rongo1 commited on
Commit
04131f9
·
1 Parent(s): 43c005c

left 1 option

Browse files
Files changed (3) hide show
  1. app.py +9 -50
  2. output.pdf +0 -0
  3. requirements.txt +0 -2
app.py CHANGED
@@ -1,65 +1,24 @@
1
  import os
2
  import subprocess
3
  import gradio as gr
4
- from pptx import Presentation
5
- from pptx.util import Inches
6
- from pdf2image import convert_from_path
7
 
 
 
8
 
9
- subprocess.run(['bash', 'setup.sh'], check=True)
10
-
11
-
12
- def pptx_to_pdf(input_pptx, output_pdf):
13
- subprocess.run(['unoconv', '-f', 'pdf', '-o', output_pdf, input_pptx], check=True)
14
-
15
-
16
- def pdf_to_pptx(input_pdf, output_pptx):
17
- # Specify a directory to save images
18
- output_dir = "pdf_images"
19
- os.makedirs(output_dir, exist_ok=True)
20
-
21
- # Convert PDF to images and save in the specified directory
22
- images = convert_from_path(input_pdf, output_folder=output_dir)
23
-
24
- # Create a new PowerPoint presentation
25
- presentation = Presentation()
26
-
27
- for i, img in enumerate(images):
28
- img_path = os.path.join(output_dir, f"page_{i+1}.png")
29
- img.save(img_path, 'PNG')
30
-
31
- slide_layout = presentation.slide_layouts[5] # Use a blank layout
32
- slide = presentation.slides.add_slide(slide_layout)
33
- left = top = Inches(0)
34
- pic = slide.shapes.add_picture(img_path, left, top, width=Inches(10), height=Inches(7.5))
35
-
36
- presentation.save(output_pptx)
37
-
38
- def convert_pptx_to_pdf(pptx_file):
39
  output_pdf = "output.pdf"
40
- pptx_to_pdf(pptx_file.name, output_pdf)
41
  return output_pdf
42
 
43
- def convert_pdf_to_pptx(pdf_file):
44
- output_pptx = "output_converted.pptx"
45
- pdf_to_pptx(pdf_file.name, output_pptx)
46
- return output_pptx
47
-
48
  pptx_to_pdf_interface = gr.Interface(
49
- fn=convert_pptx_to_pdf,
50
  inputs=gr.File(label="Upload PPTX File", file_count="single"),
51
  outputs=gr.File(label="Download PDF File"),
52
  title="Convert PPTX to PDF"
53
  )
54
 
55
- pdf_to_pptx_interface = gr.Interface(
56
- fn=convert_pdf_to_pptx,
57
- inputs=gr.File(label="Upload PDF File", file_count="single"),
58
- outputs=gr.File(label="Download PPTX File"),
59
- title="Convert PDF to PPTX"
60
- )
61
-
62
- app = gr.TabbedInterface([pptx_to_pdf_interface, pdf_to_pptx_interface], ["PPTX to PDF", "PDF to PPTX"])
63
-
64
  if __name__ == "__main__":
65
- app.launch()
 
1
  import os
2
  import subprocess
3
  import gradio as gr
 
 
 
4
 
5
+ # Run the setup script to install unoconv and libreoffice
6
+ #subprocess.run(['bash', 'setup.sh'], check=True)
7
 
8
+ # Function to convert PowerPoint to PDF using unoconv
9
+ def pptx_to_pdf(input_pptx):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  output_pdf = "output.pdf"
11
+ subprocess.run(['unoconv', '-f', 'pdf', '-o', output_pdf, input_pptx], check=True)
12
  return output_pdf
13
 
14
+ # Gradio interface for converting PPTX to PDF
 
 
 
 
15
  pptx_to_pdf_interface = gr.Interface(
16
+ fn=pptx_to_pdf,
17
  inputs=gr.File(label="Upload PPTX File", file_count="single"),
18
  outputs=gr.File(label="Download PDF File"),
19
  title="Convert PPTX to PDF"
20
  )
21
 
22
+ # Launch the Gradio app
 
 
 
 
 
 
 
 
23
  if __name__ == "__main__":
24
+ pptx_to_pdf_interface.launch(share=True)
output.pdf CHANGED
Binary files a/output.pdf and b/output.pdf differ
 
requirements.txt CHANGED
@@ -1,5 +1,3 @@
1
  gradio
2
  python-pptx
3
- fpdf
4
- Pillow
5
  pdf2image
 
1
  gradio
2
  python-pptx
 
 
3
  pdf2image