Spaces:
Running
Running
add
Browse files
app.py
CHANGED
@@ -107,19 +107,19 @@ def create_pptx(api_key, instruction, model_name="gpt-4o", max_tokens=4096):
|
|
107 |
temp_files = files_after - files_before # Identify newly created files
|
108 |
|
109 |
# Convert the pptx to jpg for preview
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
|
121 |
# If successful, return the result
|
122 |
-
return "Slide generated successfully! Download your slide below.", pptx_path
|
123 |
# , preview_image
|
124 |
except subprocess.CalledProcessError as e:
|
125 |
print(f"Attempt {attempt + 1} failed: {e.stderr}")
|
@@ -157,10 +157,10 @@ ppt.save("output.pptx")
|
|
157 |
]
|
158 |
subprocess.run(command)
|
159 |
|
160 |
-
return "Default slide generated after 3 attempts failed.", pptx_path
|
161 |
|
162 |
except Exception as e:
|
163 |
-
return f"An error occurred: {str(e)}", None
|
164 |
finally:
|
165 |
# Cleanup temporary files
|
166 |
files_before.add("output.pptx")
|
@@ -169,8 +169,8 @@ ppt.save("output.pptx")
|
|
169 |
|
170 |
# Create a Gradio interface
|
171 |
def gradio_demo(api_key, instruction):
|
172 |
-
status, pptx_path = create_pptx(api_key, instruction)
|
173 |
-
return status, pptx_path
|
174 |
|
175 |
iface = gr.Interface(
|
176 |
fn=gradio_demo,
|
@@ -181,7 +181,7 @@ iface = gr.Interface(
|
|
181 |
outputs=[
|
182 |
gr.Textbox(label="Status"),
|
183 |
gr.File(label="Download Slide"),
|
184 |
-
|
185 |
],
|
186 |
title="AutoPresent",
|
187 |
description="Automatically Generate a presentation slide"
|
|
|
107 |
temp_files = files_after - files_before # Identify newly created files
|
108 |
|
109 |
# Convert the pptx to jpg for preview
|
110 |
+
preview_image = "image_previews/output.jpg"
|
111 |
+
command = [
|
112 |
+
"libreoffice",
|
113 |
+
"--headless",
|
114 |
+
"--convert-to", "jpg",
|
115 |
+
"--outdir", "image_previews",
|
116 |
+
pptx_path
|
117 |
+
]
|
118 |
+
subprocess.run(command)
|
119 |
+
temp_files.add(preview_image)
|
120 |
|
121 |
# If successful, return the result
|
122 |
+
return "Slide generated successfully! Download your slide below.", pptx_path, preview_image
|
123 |
# , preview_image
|
124 |
except subprocess.CalledProcessError as e:
|
125 |
print(f"Attempt {attempt + 1} failed: {e.stderr}")
|
|
|
157 |
]
|
158 |
subprocess.run(command)
|
159 |
|
160 |
+
return "Default slide generated after 3 attempts failed.", pptx_path, preview_image
|
161 |
|
162 |
except Exception as e:
|
163 |
+
return f"An error occurred: {str(e)}", None, None
|
164 |
finally:
|
165 |
# Cleanup temporary files
|
166 |
files_before.add("output.pptx")
|
|
|
169 |
|
170 |
# Create a Gradio interface
|
171 |
def gradio_demo(api_key, instruction):
|
172 |
+
status, pptx_path, img = create_pptx(api_key, instruction)
|
173 |
+
return status, pptx_path, img
|
174 |
|
175 |
iface = gr.Interface(
|
176 |
fn=gradio_demo,
|
|
|
181 |
outputs=[
|
182 |
gr.Textbox(label="Status"),
|
183 |
gr.File(label="Download Slide"),
|
184 |
+
gr.Image(label="Slide Preview", type="filepath")
|
185 |
],
|
186 |
title="AutoPresent",
|
187 |
description="Automatically Generate a presentation slide"
|