kshitij10000 commited on
Commit
54d3dfa
·
1 Parent(s): 4aeda2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -21
app.py CHANGED
@@ -3,7 +3,7 @@ import json
3
  import base64
4
  from pptx import Presentation
5
  import streamlit as st
6
- import os # Import the os module to handle file renaming
7
 
8
  # Suppress all warnings
9
  import warnings
@@ -12,19 +12,21 @@ warnings.filterwarnings("ignore")
12
  # Set your OpenAI API key
13
  openai.api_key = "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"
14
 
15
- import streamlit as st
16
-
17
- # Page title and header
18
  st.title("PowerPoint Presentation Generator")
19
  st.header("Welcome! Create Engaging Presentations with Ease!")
 
20
  # What we do
21
  st.write("Provide your topic, and we'll add engaging content.")
22
  st.write("Our AI ensures balanced slides.")
23
  st.write("Exciting features coming soon. 🚀")
 
24
  # Limits
25
  st.write("Max 10 slides with 3-8 points each. ⚠️")
 
26
  # Important Notice
27
  st.warning("Vertical format issue? Try downloading again. Contact us for help.")
 
28
  # Contact and Feedback
29
  st.subheader("Contact and Feedback")
30
  st.write("Questions or ideas? Contact us anytime!")
@@ -32,9 +34,9 @@ st.write("Your feedback makes us better. 🌟")
32
 
33
  # Input for presentation topic
34
  presentation_title = st.text_input("Enter your presentation topic:")
35
- no_of_pages = st.number_input("Number of slides you want(max 10)", min_value=2, value=2) # Accept and display float values
36
- least_c = st.number_input("Minimum points in each slide(min 2)", min_value=2, value=2) # Accept and display float values
37
- max_c = st.number_input("Maximum points in each slide(max 8)", max_value=8, value=8) # Accept and display float values
38
 
39
  if st.button("Generate Presentation"):
40
  # Check if the user has entered a topic
@@ -63,10 +65,9 @@ if st.button("Generate Presentation"):
63
 
64
  prs = Presentation()
65
 
66
- from pptx.util import Pt # Import the Pt class from pptx.util
67
- from pptx.enum.text import PP_ALIGN # Import text alignment options
68
 
69
- # Iterate through slide data and populate the presentation
70
  for slide in slide_data:
71
  slide_layout = prs.slide_layouts[1]
72
  new_slide = prs.slides.add_slide(slide_layout)
@@ -80,33 +81,25 @@ if st.button("Generate Presentation"):
80
  body_shape = shapes.placeholders[1]
81
  tf = body_shape.text_frame
82
 
83
- # Join the list of content into a single string with line breaks
84
  content_text = "\n".join(slide["content"])
85
 
86
  p = tf.add_paragraph()
87
  p.text = content_text
88
 
89
- # Set the spacing between lines using Pt (point size)
90
- p.space_after = Pt(14) # Adjust the spacing between lines
91
-
92
- # Set text direction to horizontal (left-to-right)
93
  p.alignment = PP_ALIGN.LEFT
94
 
95
- # Save the presentation in PPTX format with the topic name as the file name
96
  presentation_filename = f"{presentation_title}.pptx"
97
  prs.save(presentation_filename)
98
 
99
- # Provide a direct download link with a custom filename
100
  with open(presentation_filename, "rb") as file:
101
- # Specify the custom filename using the "key" parameter
102
  st.download_button(
103
  label=f"Download {presentation_title}",
104
  data=file.read(),
105
- key=presentation_filename, # Use the filename as the key
106
- file_name=presentation_filename # Use the same filename for the downloaded file
107
  )
108
 
109
- # Delete the temporary presentation file
110
  os.remove(presentation_filename)
111
  except json.JSONDecodeError as e:
112
  st.error("Error parsing JSON response from OpenAI.")
 
3
  import base64
4
  from pptx import Presentation
5
  import streamlit as st
6
+ import os
7
 
8
  # Suppress all warnings
9
  import warnings
 
12
  # Set your OpenAI API key
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!")
 
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
 
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)
 
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.")