zolicsaki commited on
Commit
6e26061
·
verified ·
1 Parent(s): ced780f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -2,8 +2,21 @@ import os
2
  import gradio as gr
3
  import tempfile
4
  from pathlib import Path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- # This is a placeholder function that you would replace with your actual conversion logic
7
  def convert_pdf_to_slides(pdf_path):
8
  """
9
  Convert a PDF file to a slide deck.
@@ -16,18 +29,14 @@ def convert_pdf_to_slides(pdf_path):
16
  """
17
  print(f"Processing PDF: {pdf_path}")
18
 
19
- # This is where you would implement your actual conversion logic
20
- # For this example, we'll just pretend we're creating a PowerPoint file
21
 
22
- # Create a temporary output file with .pptx extension
23
- output_dir = os.path.dirname(pdf_path)
24
  output_filename = f"{Path(pdf_path).stem}_slides.pptx"
25
- output_path = os.path.join(output_dir, output_filename)
26
 
27
- # In a real implementation, you would convert the PDF to slides here
28
- # For demonstration, we'll just create an empty file
29
- with open(output_path, "wb") as f:
30
- f.write(b"Example slide deck content")
31
 
32
  print(f"Conversion complete. Slides saved to: {output_path}")
33
  return output_path
@@ -82,4 +91,8 @@ with gr.Blocks(title="PDF to Slides Converter") as app:
82
 
83
  # Launch the app
84
  if __name__ == "__main__":
85
- app.launch()
 
 
 
 
 
2
  import gradio as gr
3
  import tempfile
4
  from pathlib import Path
5
+ from utils import get_file_name, run_pdf2text, run_paper2slides
6
+
7
+ # Create a temporary directory for outputs
8
+ OUTPUT_FOLDER = tempfile.mkdtemp(prefix="pdf_slides_")
9
+
10
+ def paper2slides(pdf_path: str, logo_path: str='logo.npg'):
11
+ # Ensure the output directory exists
12
+ os.makedirs(OUTPUT_FOLDER, exist_ok=True)
13
+
14
+ output_path = os.path.join(OUTPUT_FOLDER, "converted_slides.pptx")
15
+ file_name = get_file_name(full_path=pdf_path)
16
+ run_pdf2text(paper_pdf_path=pdf_path, save_json_name=file_name + '.json') ## pdf to json file
17
+ run_paper2slides(paper_json_name=file_name + '.json', model='llama3_70b', logo_path=logo_path, save_file_name=output_path) ## json file to slides
18
+ return output_path
19
 
 
20
  def convert_pdf_to_slides(pdf_path):
21
  """
22
  Convert a PDF file to a slide deck.
 
29
  """
30
  print(f"Processing PDF: {pdf_path}")
31
 
32
+ # Ensure the output directory exists
33
+ os.makedirs(OUTPUT_FOLDER, exist_ok=True)
34
 
35
+ # Create output filename in the temporary directory
 
36
  output_filename = f"{Path(pdf_path).stem}_slides.pptx"
37
+ output_path = os.path.join(OUTPUT_FOLDER, output_filename)
38
 
39
+ output_path = paper2slides(pdf_path, 'logo.png')
 
 
 
40
 
41
  print(f"Conversion complete. Slides saved to: {output_path}")
42
  return output_path
 
91
 
92
  # Launch the app
93
  if __name__ == "__main__":
94
+ app.launch()
95
+
96
+ # Optional: Clean up the temporary directory when the app exits
97
+ import shutil
98
+ shutil.rmtree(OUTPUT_FOLDER, ignore_errors=True)