kshitij10000 commited on
Commit
a80a9c2
Β·
1 Parent(s): 54d3dfa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -75
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import openai
2
  import json
3
- import base64
4
  from pptx import Presentation
5
  import streamlit as st
6
  import os
@@ -13,95 +12,109 @@ warnings.filterwarnings("ignore")
13
  openai.api_key = "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"
14
 
15
  # Streamlit app title and header
16
- st.title("PowerPoint Presentation Generator")
17
- st.header("Welcome! Create Engaging Presentations with Ease!")
18
-
19
- # What we do
20
- st.write("Provide your topic, and we'll add engaging content.")
21
- st.write("Our AI ensures balanced slides.")
22
- st.write("Exciting features coming soon. πŸš€")
23
-
24
- # Limits
25
- st.write("Max 10 slides with 3-8 points each. ⚠️")
 
 
 
 
 
 
 
 
 
 
26
 
27
  # Important Notice
28
- st.warning("Vertical format issue? Try downloading again. Contact us for help.")
29
 
30
  # Contact and Feedback
31
- st.subheader("Contact and Feedback")
32
- st.write("Questions or ideas? Contact us anytime!")
33
- st.write("Your feedback makes us better. 🌟")
34
 
35
  # Input for presentation topic
36
- presentation_title = st.text_input("Enter your presentation topic:")
37
- no_of_pages = st.number_input("Number of slides you want(max 10)", min_value=2, value=2)
38
- least_c = st.number_input("Minimum points in each slide(min 2)", min_value=2, value=2)
39
- max_c = st.number_input("Maximum points in each slide(max 8)", max_value=8, value=8)
40
-
41
- if st.button("Generate Presentation"):
42
- # Check if the user has entered a topic
43
- if presentation_title:
44
- question = (
45
- f"generate a {no_of_pages} slide presentation for the topic {presentation_title}."
46
- f" Each slide should have {{header}}, {{content}}, should have at least {least_c} points and max {max_c} points in content. Return as JSON"
47
- )
48
-
49
- query_json = {
50
- "input_text": question,
51
- "output_format": "json",
52
- "json_structure": {"slides": "{{presentation_slides}}"},
53
- }
54
-
55
- # Send the query to OpenAI
56
- completion = openai.ChatCompletion.create(
57
- model="gpt-3.5-turbo",
58
- messages=[{"role": "user", "content": json.dumps(query_json)}],
59
- )
60
-
61
- try:
62
- response = json.loads(completion.choices[0].message.content)
 
63
 
64
- slide_data = response["slides"]
 
 
 
65
 
66
- prs = Presentation()
67
 
68
- from pptx.util import Pt
69
- from pptx.enum.text import PP_ALIGN
70
 
71
- for slide in slide_data:
72
- slide_layout = prs.slide_layouts[1]
73
- new_slide = prs.slides.add_slide(slide_layout)
74
 
75
- if slide["header"]:
76
- title = new_slide.shapes.title
77
- title.text = slide["header"]
78
 
79
- if slide["content"]:
80
- shapes = new_slide.shapes
81
- body_shape = shapes.placeholders[1]
82
- tf = body_shape.text_frame
83
 
84
- content_text = "\n".join(slide["content"])
85
 
86
- p = tf.add_paragraph()
87
- p.text = content_text
88
 
89
- p.space_after = Pt(14)
90
- p.alignment = PP_ALIGN.LEFT
91
 
92
- presentation_filename = f"{presentation_title}.pptx"
93
- prs.save(presentation_filename)
94
 
95
- with open(presentation_filename, "rb") as file:
96
- st.download_button(
97
- label=f"Download {presentation_title}",
98
- data=file.read(),
99
- key=presentation_filename,
100
- file_name=presentation_filename
101
- )
102
 
103
- os.remove(presentation_filename)
104
- except json.JSONDecodeError as e:
105
- st.error("Error parsing JSON response from OpenAI.")
106
- else:
107
- st.warning("Please enter a presentation topic.")
 
1
  import openai
2
  import json
 
3
  from pptx import Presentation
4
  import streamlit as st
5
  import os
 
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
19
+ st.markdown(
20
+ """
21
+ 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. 🎨
22
+
23
+ Here's what we do:
24
+ - **You provide the presentation topic**, and we add captivating content.
25
+ - Our AI ensures **each slide has the perfect balance of information**.
26
+ - Stay tuned for **exciting future features** that will enhance your presentation experience. πŸš€
27
+ """
28
+ )
29
+
30
+ # Presentation Limits
31
+ st.subheader("πŸ“Š Presentation Limits (for now, subject to change in future updates) πŸ“Š")
32
+ st.write("✨ You can create a minimum of 3 and a maximum of 8 slides per presentation.")
33
+ st.write("✨ Each slide should have between 3 and 7 points of content.")
34
+ st.write("✨ Minimum 3 points, maximum 7 points. ⚠️")
35
 
36
  # Important Notice
37
+ st.warning("⚠️ Important Notice: Occasional download issues? Try re-downloading or reach out to us for assistance. We apologize for any inconvenience.")
38
 
39
  # Contact and Feedback
40
+ st.subheader("πŸ“ž Contact and Feedback πŸ“ž")
41
+ st.write("Have questions, ideas, or cool suggestions for future enhancements? We're all ears!")
42
+ st.write("Your feedback is invaluable in making your experience the best it can be! 🌟")
43
 
44
  # Input for presentation topic
45
+ presentation_title = st.text_input("πŸ“ Enter your presentation topic:")
46
+ no_of_pages = st.number_input("πŸ“Š Number of slides you want (3-8)", min_value=3, max_value=8, value=3)
47
+ least_c = st.number_input("πŸ“Š Minimum points in each slide (3-7)", min_value=3, max_value=7, value=3)
48
+ max_c = st.number_input("πŸ“Š Maximum points in each slide (4-7)", min_value=4, max_value=7, value=7)
49
+
50
+ # Check if any input values are out of range
51
+ 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:
52
+ st.warning("Invalid input values. Please ensure that your inputs are within the specified limits.")
53
+ else:
54
+ if st.button("Generate Presentation"):
55
+ # Check if the user has entered a topic
56
+ if presentation_title:
57
+ question = (
58
+ f"generate a {no_of_pages} slide presentation for the topic {presentation_title}."
59
+ f" Each slide should have {{header}}, {{content}}, should have at least {least_c} points and max {max_c} points in content. Return as JSON"
60
+ )
61
+
62
+ query_json = {
63
+ "input_text": question,
64
+ "output_format": "json",
65
+ "json_structure": {"slides": "{{presentation_slides}}"},
66
+ }
67
+
68
+ # Send the query to OpenAI
69
+ completion = openai.ChatCompletion.create(
70
+ model="gpt-3.5-turbo",
71
+ messages=[{"role": "user", "content": json.dumps(query_json)}],
72
+ )
73
 
74
+ try:
75
+ response = json.loads(completion.choices[0].message.content)
76
+
77
+ slide_data = response["slides"]
78
 
79
+ prs = Presentation()
80
 
81
+ from pptx.util import Pt
82
+ from pptx.enum.text import PP_ALIGN
83
 
84
+ for slide in slide_data:
85
+ slide_layout = prs.slide_layouts[1]
86
+ new_slide = prs.slides.add_slide(slide_layout)
87
 
88
+ if slide["header"]:
89
+ title = new_slide.shapes.title
90
+ title.text = slide["header"]
91
 
92
+ if slide["content"]:
93
+ shapes = new_slide.shapes
94
+ body_shape = shapes.placeholders[1]
95
+ tf = body_shape.text_frame
96
 
97
+ content_text = "\n".join(slide["content"])
98
 
99
+ p = tf.add_paragraph()
100
+ p.text = content_text
101
 
102
+ p.space_after = Pt(14)
103
+ p.alignment = PP_ALIGN.LEFT
104
 
105
+ presentation_filename = f"{presentation_title}.pptx"
106
+ prs.save(presentation_filename)
107
 
108
+ with open(presentation_filename, "rb") as file:
109
+ st.download_button(
110
+ label=f"πŸ“₯ Download {presentation_title}",
111
+ data=file.read(),
112
+ key=presentation_filename,
113
+ file_name=presentation_filename
114
+ )
115
 
116
+ os.remove(presentation_filename)
117
+ except json.JSONDecodeError as e:
118
+ st.error("Error parsing JSON response from OpenAI.")
119
+ else:
120
+ st.warning("Please enter a presentation topic.")