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