Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ import json
|
|
9 |
import os
|
10 |
from PIL import Image
|
11 |
import io
|
|
|
12 |
|
13 |
def print_json(item):
|
14 |
item_json = json.dumps(item, ensure_ascii=False, indent=4)
|
@@ -97,16 +98,20 @@ def copy_font_style(original_run, new_run):
|
|
97 |
|
98 |
def process_pptx(pptx_file):
|
99 |
images_dir_path = "images"
|
|
|
100 |
if not os.path.exists(images_dir_path):
|
101 |
os.makedirs(images_dir_path)
|
102 |
json_output, image_paths = transfer_to_structure(pptx_file.name, images_dir_path)
|
103 |
-
|
|
|
|
|
|
|
104 |
|
105 |
# Gradio interface
|
106 |
iface = gr.Interface(
|
107 |
fn=process_pptx,
|
108 |
inputs=gr.File(label="Upload PowerPoint File"),
|
109 |
-
outputs=[gr.Textbox(label="JSON Output"), gr.Gallery(label="Extracted Images")],
|
110 |
title="PowerPoint to JSON Converter",
|
111 |
description="Upload a PowerPoint file to convert its structure to JSON and display extracted images."
|
112 |
)
|
|
|
9 |
import os
|
10 |
from PIL import Image
|
11 |
import io
|
12 |
+
from pptx2png import pptx_to_images, render_images_with_skia
|
13 |
|
14 |
def print_json(item):
|
15 |
item_json = json.dumps(item, ensure_ascii=False, indent=4)
|
|
|
98 |
|
99 |
def process_pptx(pptx_file):
|
100 |
images_dir_path = "images"
|
101 |
+
output_dir = 'rendered_png' # Directory to save the rendered images
|
102 |
if not os.path.exists(images_dir_path):
|
103 |
os.makedirs(images_dir_path)
|
104 |
json_output, image_paths = transfer_to_structure(pptx_file.name, images_dir_path)
|
105 |
+
|
106 |
+
images, slide_dimensions = pptx_to_images(pptx_file)
|
107 |
+
rendered_image_path = render_images_with_skia(images, slide_dimensions, output_dir)
|
108 |
+
return json_output, image_paths, rendered_image_path
|
109 |
|
110 |
# Gradio interface
|
111 |
iface = gr.Interface(
|
112 |
fn=process_pptx,
|
113 |
inputs=gr.File(label="Upload PowerPoint File"),
|
114 |
+
outputs=[gr.Textbox(label="JSON Output"), gr.Gallery(label="Extracted Images"), gr.Image(label="PPT Preview")],
|
115 |
title="PowerPoint to JSON Converter",
|
116 |
description="Upload a PowerPoint file to convert its structure to JSON and display extracted images."
|
117 |
)
|