Commit Β·
7b07c62
1
Parent(s): 55b9c31
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,132 +3,112 @@ import json
|
|
| 3 |
import base64
|
| 4 |
from pptx import Presentation
|
| 5 |
import streamlit as st
|
| 6 |
-
import os
|
| 7 |
|
| 8 |
# Suppress all warnings
|
| 9 |
import warnings
|
| 10 |
warnings.filterwarnings("ignore")
|
| 11 |
|
| 12 |
# Set your OpenAI API key
|
| 13 |
-
openai.api_key = "sk-
|
| 14 |
-
|
| 15 |
-
# Streamlit app
|
| 16 |
-
st.title("
|
| 17 |
-
st.
|
| 18 |
-
|
| 19 |
-
# Introduction section
|
| 20 |
-
st.
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 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 |
-
#
|
| 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 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 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.")
|
|
|
|
| 3 |
import base64
|
| 4 |
from pptx import Presentation
|
| 5 |
import streamlit as st
|
|
|
|
| 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 |
+
# Streamlit app title and header
|
| 15 |
+
st.title("PowerPoint Presentation Generator")
|
| 16 |
+
st.header("Welcome to the Future of Presentation Creation!")
|
| 17 |
+
|
| 18 |
+
# Introduction section
|
| 19 |
+
st.write("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. π¨")
|
| 20 |
+
st.write("Here's what we do:")
|
| 21 |
+
st.write("- **You provide the presentation topic**, and we add captivating content.")
|
| 22 |
+
st.write("- Our AI ensures **each slide has the perfect balance of information**.")
|
| 23 |
+
st.write("- Stay tuned for **exciting future features** that will enhance your presentation experience. π")
|
| 24 |
+
|
| 25 |
+
# Presentation Limits section
|
| 26 |
+
st.header("Presentation Limits")
|
| 27 |
+
st.write("β¨ You can create a minimum of 3 and a maximum of 7 slides per presentation.")
|
| 28 |
+
st.write("β¨ Each slide should have between 3 and 7 points of content.")
|
| 29 |
+
st.write("β¨ Minimum 3 points, maximum 7 points. β οΈ")
|
| 30 |
+
|
| 31 |
+
# Important Notice
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
st.warning("β οΈ Important Notice: Occasional download issues? Try re-downloading or reach out to us for assistance. We apologize for any inconvenience.")
|
| 33 |
|
| 34 |
+
# Contact and Feedback section
|
| 35 |
+
st.header("Contact and Feedback")
|
| 36 |
+
st.write("Have questions, ideas, or cool suggestions for future enhancements? We're all ears!")
|
| 37 |
+
st.write("Your feedback is invaluable in making your experience the best it can be! π")
|
| 38 |
+
|
| 39 |
+
# Input for presentation topic
|
| 40 |
+
presentation_title = st.text_input("Enter your presentation topic:")
|
| 41 |
+
no_of_pages = st.number_input("Number of slides you want", min_value=1, value=1) # Accept and display float values
|
| 42 |
+
least_c = st.number_input("Minimum points in each slide", min_value=1, value=1) # Accept and display float values
|
| 43 |
+
max_c = st.number_input("Maximum points in each slide", min_value=1, value=1) # Accept and display float values
|
| 44 |
+
|
| 45 |
+
if st.button("Generate Presentation"):
|
| 46 |
+
# Check if the user has entered a topic
|
| 47 |
+
if presentation_title:
|
| 48 |
+
question = (
|
| 49 |
+
f"generate a {no_of_pages} slide presentation for the topic {presentation_title}."
|
| 50 |
+
f" Each slide should have {{header}}, {{content}}, should have at least {least_c} points and max {max_c} points in content. Return as JSON"
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
query_json = {
|
| 54 |
+
"input_text": question,
|
| 55 |
+
"output_format": "json",
|
| 56 |
+
"json_structure": {"slides": "{{presentation_slides}}"},
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
# Send the query to OpenAI
|
| 60 |
+
completion = openai.ChatCompletion.create(
|
| 61 |
+
model="gpt-3.5-turbo",
|
| 62 |
+
messages=[{"role": "user", "content": json.dumps(query_json)}],
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
try:
|
| 66 |
+
response = json.loads(completion.choices[0].message.content)
|
| 67 |
|
| 68 |
+
slide_data = response["slides"]
|
| 69 |
+
|
| 70 |
+
prs = Presentation()
|
| 71 |
+
|
| 72 |
+
from pptx.util import Pt # Import the Pt class from pptx.util
|
| 73 |
+
from pptx.enum.text import PP_ALIGN # Import text alignment options
|
| 74 |
+
|
| 75 |
+
# Iterate through slide data and populate the presentation
|
| 76 |
+
for slide in slide_data:
|
| 77 |
+
slide_layout = prs.slide_layouts[1]
|
| 78 |
+
new_slide = prs.slides.add_slide(slide_layout)
|
| 79 |
+
|
| 80 |
+
if slide["header"]:
|
| 81 |
+
title = new_slide.shapes.title
|
| 82 |
+
title.text = slide["header"]
|
| 83 |
+
|
| 84 |
+
if slide["content"]:
|
| 85 |
+
shapes = new_slide.shapes
|
| 86 |
+
body_shape = shapes.placeholders[1]
|
| 87 |
+
tf = body_shape.text_frame
|
| 88 |
+
|
| 89 |
+
# Join the list of content into a single string with line breaks
|
| 90 |
+
content_text = "\n".join(slide["content"])
|
| 91 |
+
|
| 92 |
+
p = tf.add_paragraph()
|
| 93 |
+
p.text = content_text
|
| 94 |
+
|
| 95 |
+
# Set the spacing between lines using Pt (point size)
|
| 96 |
+
p.space_after = Pt(14) # Adjust the spacing between lines
|
| 97 |
+
|
| 98 |
+
# Set text direction to horizontal (left-to-right)
|
| 99 |
+
p.alignment = PP_ALIGN.LEFT
|
| 100 |
+
|
| 101 |
+
# Save the presentation in PPTX format with the topic name as the file name
|
| 102 |
+
presentation_filename = f"{presentation_title}.pptx"
|
| 103 |
+
prs.save(presentation_filename)
|
| 104 |
+
|
| 105 |
+
# Provide a direct download link
|
| 106 |
+
with open(presentation_filename, "rb") as file:
|
| 107 |
+
st.markdown(
|
| 108 |
+
f"### [Download {presentation_title}]"
|
| 109 |
+
f"(data:application/octet-stream;base64,{base64.b64encode(file.read()).decode()})"
|
| 110 |
+
)
|
| 111 |
+
except json.JSONDecodeError as e:
|
| 112 |
+
st.error("Error parsing JSON response from OpenAI.")
|
| 113 |
+
else:
|
| 114 |
+
st.warning("Please enter a presentation topic.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|