Spaces:
Running
Running
resume
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 |
-
preview_image = "image_previews/output.jpg"
|
| 111 |
-
command = [
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 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
|
| 123 |
# , preview_image
|
| 124 |
except subprocess.CalledProcessError as e:
|
| 125 |
print(f"Attempt {attempt + 1} failed: {e.stderr}")
|
|
@@ -147,20 +147,20 @@ ppt.save("output.pptx")
|
|
| 147 |
subprocess.run(["python", code_file], capture_output=True, text=True, check=True)
|
| 148 |
|
| 149 |
# Convert the pptx to jpg for preview
|
| 150 |
-
preview_image = "image_previews/output.jpg"
|
| 151 |
-
command = [
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 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
|
| 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 |
-
gr.Image(label="Slide Preview", type="filepath")
|
| 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
|
| 123 |
# , preview_image
|
| 124 |
except subprocess.CalledProcessError as e:
|
| 125 |
print(f"Attempt {attempt + 1} failed: {e.stderr}")
|
|
|
|
| 147 |
subprocess.run(["python", code_file], capture_output=True, text=True, check=True)
|
| 148 |
|
| 149 |
# Convert the pptx to jpg for preview
|
| 150 |
+
# preview_image = "image_previews/output.jpg"
|
| 151 |
+
# command = [
|
| 152 |
+
# "libreoffice",
|
| 153 |
+
# "--headless",
|
| 154 |
+
# "--convert-to", "jpg",
|
| 155 |
+
# "--outdir", "image_previews",
|
| 156 |
+
# pptx_path
|
| 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 |
|
| 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 |
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"
|