rongo1 commited on
Commit
b63e903
·
1 Parent(s): 1f8f68d

fixed gradio no input

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -5,24 +5,30 @@ from pptx import Presentation
5
  from pptx.util import Inches
6
  from pdf2image import convert_from_path
7
 
 
8
  subprocess.run(['bash', 'setup.sh'], check=True)
9
 
 
10
  def pptx_to_pdf(input_pptx, output_pdf):
11
  subprocess.run(['unoconv', '-f', 'pdf', '-o', output_pdf, input_pptx], check=True)
12
 
 
13
  def pdf_to_pptx(input_pdf, output_pptx):
 
14
  output_dir = "pdf_images"
15
  os.makedirs(output_dir, exist_ok=True)
16
 
 
17
  images = convert_from_path(input_pdf, output_folder=output_dir)
18
-
 
19
  presentation = Presentation()
20
 
21
  for i, img in enumerate(images):
22
  img_path = os.path.join(output_dir, f"page_{i+1}.png")
23
  img.save(img_path, 'PNG')
24
 
25
- slide_layout = presentation.slide_layouts[5]
26
  slide = presentation.slides.add_slide(slide_layout)
27
  left = top = Inches(0)
28
  pic = slide.shapes.add_picture(img_path, left, top, width=Inches(10), height=Inches(7.5))
@@ -41,15 +47,15 @@ def convert_pdf_to_pptx(pdf_file):
41
 
42
  pptx_to_pdf_interface = gr.Interface(
43
  fn=convert_pptx_to_pdf,
44
- inputs=gr.inputs.File(file_count="single", type="file", label="Upload PPTX File"),
45
- outputs=gr.outputs.File(label="Download PDF File"),
46
  title="Convert PPTX to PDF"
47
  )
48
 
49
  pdf_to_pptx_interface = gr.Interface(
50
  fn=convert_pdf_to_pptx,
51
- inputs=gr.inputs.File(file_count="single", type="file", label="Upload PDF File"),
52
- outputs=gr.outputs.File(label="Download PPTX File"),
53
  title="Convert PDF to PPTX"
54
  )
55
 
 
5
  from pptx.util import Inches
6
  from pdf2image import convert_from_path
7
 
8
+ # Run the setup script to install unoconv and libreoffice
9
  subprocess.run(['bash', 'setup.sh'], check=True)
10
 
11
+ # Function to convert PowerPoint to PDF using unoconv
12
  def pptx_to_pdf(input_pptx, output_pdf):
13
  subprocess.run(['unoconv', '-f', 'pdf', '-o', output_pdf, input_pptx], check=True)
14
 
15
+ # Function to convert PDF to PowerPoint
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))
 
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