stzhao commited on
Commit
48a0c5d
·
verified ·
1 Parent(s): 819daad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -96,16 +96,29 @@ def process_pptx(pptx_file):
96
  images_dir_path = "images"
97
  if not os.path.exists(images_dir_path):
98
  os.makedirs(images_dir_path)
 
 
 
 
 
 
 
 
99
  json_output, image_paths = transfer_to_structure(pptx_file.name, images_dir_path)
100
- return json_output, image_paths
 
 
 
 
 
101
 
102
  # Gradio interface
103
  iface = gr.Interface(
104
  fn=process_pptx,
105
  inputs=gr.File(label="Upload PowerPoint File"),
106
- outputs=[gr.Textbox(label="JSON Output"), gr.Gallery(label="Extracted Images")],
107
  title="PowerPoint to JSON Converter",
108
- description="Upload a PowerPoint file to convert its structure to JSON and display extracted images."
109
  )
110
 
111
  iface.launch()
 
96
  images_dir_path = "images"
97
  if not os.path.exists(images_dir_path):
98
  os.makedirs(images_dir_path)
99
+
100
+ # Convert the first slide to an image for preview
101
+ prs = Presentation(pptx_file.name)
102
+ slide = prs.slides[0]
103
+ slide_image = slide.shapes.title.text_frame.paragraphs[0].runs[0].font.color.rgb
104
+ slide_image_path = os.path.join(images_dir_path, "preview.png")
105
+ save_slide_as_image(slide, slide_image_path)
106
+
107
  json_output, image_paths = transfer_to_structure(pptx_file.name, images_dir_path)
108
+ return json_output, image_paths, slide_image_path
109
+
110
+ def save_slide_as_image(slide, image_path):
111
+ # Convert slide to image using PIL
112
+ slide_image = slide.shapes.title.text_frame.paragraphs[0].runs[0].font.color.rgb
113
+ slide_image.save(image_path)
114
 
115
  # Gradio interface
116
  iface = gr.Interface(
117
  fn=process_pptx,
118
  inputs=gr.File(label="Upload PowerPoint File"),
119
+ outputs=[gr.Textbox(label="JSON Output"), gr.Gallery(label="Extracted Images"), gr.Image(label="PPT Preview")],
120
  title="PowerPoint to JSON Converter",
121
+ description="Upload a PowerPoint file to convert its structure to JSON and display extracted images and preview."
122
  )
123
 
124
  iface.launch()