Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -96,41 +96,16 @@ 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 |
-
|
100 |
-
# Convert the first slide to an image for preview
|
101 |
-
prs = Presentation(pptx_file.name)
|
102 |
-
slide = prs.slides[0]
|
103 |
-
slide_image_path = os.path.join(images_dir_path, "preview.png")
|
104 |
-
save_slide_as_image(slide, slide_image_path)
|
105 |
-
|
106 |
json_output, image_paths = transfer_to_structure(pptx_file.name, images_dir_path)
|
107 |
-
return json_output, image_paths
|
108 |
-
|
109 |
-
def save_slide_as_image(slide, image_path):
|
110 |
-
# Convert slide to image using PIL
|
111 |
-
slide_image = slide.shapes.title.text_frame.paragraphs[0].runs[0].font.color.rgb
|
112 |
-
slide_image.save(image_path)
|
113 |
|
114 |
# Gradio interface
|
115 |
-
def upload_pptx(pptx_file):
|
116 |
-
images_dir_path = "images"
|
117 |
-
if not os.path.exists(images_dir_path):
|
118 |
-
os.makedirs(images_dir_path)
|
119 |
-
|
120 |
-
# Convert the first slide to an image for preview
|
121 |
-
prs = Presentation(pptx_file.name)
|
122 |
-
slide = prs.slides[0]
|
123 |
-
slide_image_path = os.path.join(images_dir_path, "preview.png")
|
124 |
-
save_slide_as_image(slide, slide_image_path)
|
125 |
-
|
126 |
-
return slide_image_path
|
127 |
-
|
128 |
iface = gr.Interface(
|
129 |
fn=process_pptx,
|
130 |
inputs=gr.File(label="Upload PowerPoint File"),
|
131 |
-
outputs=[gr.Textbox(label="JSON Output"), gr.Gallery(label="Extracted Images")
|
132 |
title="PowerPoint to JSON Converter",
|
133 |
-
description="Upload a PowerPoint file to convert its structure to JSON and display extracted images
|
134 |
)
|
135 |
|
136 |
iface.launch()
|
|
|
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()
|