Commit Β·
55b9c31
1
Parent(s): 2f20cef
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import json
|
|
| 3 |
import base64
|
| 4 |
from pptx import Presentation
|
| 5 |
import streamlit as st
|
|
|
|
| 6 |
|
| 7 |
# Suppress all warnings
|
| 8 |
import warnings
|
|
@@ -12,84 +13,122 @@ warnings.filterwarnings("ignore")
|
|
| 12 |
openai.api_key = "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"
|
| 13 |
|
| 14 |
# Streamlit app
|
| 15 |
-
st.title("PowerPoint Presentation Generator")
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import base64
|
| 4 |
from pptx import Presentation
|
| 5 |
import streamlit as st
|
| 6 |
+
import os
|
| 7 |
|
| 8 |
# Suppress all warnings
|
| 9 |
import warnings
|
|
|
|
| 13 |
openai.api_key = "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"
|
| 14 |
|
| 15 |
# Streamlit app
|
| 16 |
+
st.title("π PowerPoint Presentation Generator π")
|
| 17 |
+
st.markdown("<h1 style='text-align: center; color: white;'>Welcome to the Future of Presentation Creation!</h1>", unsafe_allow_html=True)
|
| 18 |
+
|
| 19 |
+
# Introduction section with improved styling and details
|
| 20 |
+
st.markdown(
|
| 21 |
+
"""
|
| 22 |
+
<div class="st-eb">
|
| 23 |
+
<p style="color: black;">Creating presentations has never been this easy and exciting! With our AI-powered model, you can quickly generate presentation content, while the design remains your creative canvas. π¨</p>
|
| 24 |
+
<p style="color: black;">Here's what we do:</p>
|
| 25 |
+
<ul>
|
| 26 |
+
<li style="color: black;"><strong>You provide the presentation topic</strong>, and we add captivating content.</li>
|
| 27 |
+
<li style="color: black;">Our AI ensures <strong>each slide has the perfect balance of information</strong>.</li>
|
| 28 |
+
<li style="color: black;">Stay tuned for <strong>exciting future features</strong> that will enhance your presentation experience. π</li>
|
| 29 |
+
</ul>
|
| 30 |
+
</div>
|
| 31 |
+
""",
|
| 32 |
+
unsafe_allow_html=True,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Presentation Limits section with improved styling and details
|
| 36 |
+
st.markdown("<h2>Presentation Limits</h2>", unsafe_allow_html=True)
|
| 37 |
+
st.markdown(
|
| 38 |
+
"""
|
| 39 |
+
<div class="st-eb">
|
| 40 |
+
<p style="color: black;">β¨ You can create a minimum of 3 and a maximum of 7 slides per presentation.</p>
|
| 41 |
+
<p style="color: black;">β¨ Each slide should have between 3 and 7 points of content.</p>
|
| 42 |
+
<p style="color: black;">β¨ Minimum 3 points, maximum 7 points. β οΈ</p>
|
| 43 |
+
</div>
|
| 44 |
+
""",
|
| 45 |
+
unsafe_allow_html=True,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
# Important Notice with improved styling
|
| 49 |
+
st.warning("β οΈ Important Notice: Occasional download issues? Try re-downloading or reach out to us for assistance. We apologize for any inconvenience.")
|
| 50 |
+
|
| 51 |
+
# Input for presentation topic with improved styling
|
| 52 |
+
presentation_title = st.text_input("π Enter your presentation topic:")
|
| 53 |
+
no_of_pages = st.number_input("π Number of slides you want (3-8)", min_value=3, max_value=8, value=3)
|
| 54 |
+
least_c = st.number_input("π Minimum points in each slide (3-7)", min_value=3, max_value=7, value=3)
|
| 55 |
+
max_c = st.number_input("π Maximum points in each slide (4-7)", min_value=4, max_value=7, value=7)
|
| 56 |
+
|
| 57 |
+
# Check if any input values are out of range
|
| 58 |
+
if no_of_pages > 8 or no_of_pages < 3 or least_c > 7 or least_c < 3 or max_c > 7 or max_c < 4:
|
| 59 |
+
st.warning("Invalid input values. Please ensure that your inputs are within the specified limits.")
|
| 60 |
+
else:
|
| 61 |
+
if st.button("Generate Presentation"):
|
| 62 |
+
# Check if the user has entered a topic
|
| 63 |
+
if presentation_title:
|
| 64 |
+
question = (
|
| 65 |
+
f"generate a {no_of_pages} slide presentation for the topic {presentation_title}."
|
| 66 |
+
f" Each slide should have {{header}}, {{content}}, should have at least {least_c} points and max {max_c} points in content. Return as JSON"
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
query_json = {
|
| 70 |
+
"input_text": question,
|
| 71 |
+
"output_format": "json",
|
| 72 |
+
"json_structure": {"slides": "{{presentation_slides}}"},
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
# Send the query to OpenAI
|
| 76 |
+
completion = openai.ChatCompletion.create(
|
| 77 |
+
model="gpt-3.5-turbo",
|
| 78 |
+
messages=[{"role": "user", "content": json.dumps(query_json)}],
|
| 79 |
+
)
|
| 80 |
|
| 81 |
+
try:
|
| 82 |
+
response = json.loads(completion.choices[0].message.content)
|
| 83 |
+
|
| 84 |
+
slide_data = response["slides"]
|
| 85 |
+
|
| 86 |
+
prs = Presentation()
|
| 87 |
+
|
| 88 |
+
from pptx.util import Pt
|
| 89 |
+
from pptx.enum.text import PP_ALIGN
|
| 90 |
+
|
| 91 |
+
for slide in slide_data:
|
| 92 |
+
slide_layout = prs.slide_layouts[1]
|
| 93 |
+
new_slide = prs.slides.add_slide(slide_layout)
|
| 94 |
+
|
| 95 |
+
if slide["header"]:
|
| 96 |
+
title = new_slide.shapes.title
|
| 97 |
+
title.text = slide["header"]
|
| 98 |
+
|
| 99 |
+
if slide["content"]:
|
| 100 |
+
shapes = new_slide.shapes
|
| 101 |
+
body_shape = shapes.placeholders[1]
|
| 102 |
+
tf = body_shape.text_frame
|
| 103 |
+
|
| 104 |
+
content_text = "\n".join(slide["content"])
|
| 105 |
+
|
| 106 |
+
p = tf.add_paragraph()
|
| 107 |
+
p.text = content_text
|
| 108 |
+
|
| 109 |
+
p.space_after = Pt(14)
|
| 110 |
+
p.alignment = PP_ALIGN.LEFT
|
| 111 |
+
|
| 112 |
+
# Explicitly save the file with the .pptx extension
|
| 113 |
+
presentation_filename = f"{presentation_title}.pptx"
|
| 114 |
+
prs.save(presentation_filename)
|
| 115 |
+
|
| 116 |
+
# Provide a direct download link to the saved file
|
| 117 |
+
if os.path.exists(presentation_filename):
|
| 118 |
+
with open(presentation_filename, "rb") as file:
|
| 119 |
+
file_bytes = file.read()
|
| 120 |
+
st.download_button(
|
| 121 |
+
label=f"π₯ Download {presentation_title}",
|
| 122 |
+
data=file_bytes,
|
| 123 |
+
file_name=presentation_filename,
|
| 124 |
+
key=f"download_{presentation_filename}",
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
os.remove(presentation_filename)
|
| 128 |
+
else:
|
| 129 |
+
st.error("Error: Presentation file not found.")
|
| 130 |
+
|
| 131 |
+
except json.JSONDecodeError as e:
|
| 132 |
+
st.error("Error parsing JSON response from OpenAI.")
|
| 133 |
+
else:
|
| 134 |
+
st.warning("Please enter a presentation topic.")
|