YashMK89 commited on
Commit
7e226f1
·
verified ·
1 Parent(s): 46df963

update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -308
app.py CHANGED
@@ -1,311 +1,3 @@
1
- # import streamlit as st
2
- # import google.generativeai as genai
3
- # from pptx import Presentation
4
- # from pptx.util import Inches, Pt
5
- # from pptx.dml.color import RGBColor
6
- # from pptx.enum.text import PP_ALIGN
7
- # import io
8
- # import os
9
- # from docx import Document
10
- # from fpdf import FPDF
11
- # from io import BytesIO
12
-
13
- # # Configure Google Gemini API key
14
- # genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
15
-
16
- # # Set page config
17
- # st.set_page_config(page_title="Document Generator", layout="wide")
18
-
19
- # # Initialize session state for page navigation
20
- # if 'current_page' not in st.session_state:
21
- # st.session_state.current_page = "PPTX"
22
-
23
- # # Sidebar navigation
24
- # def sidebar_nav():
25
- # st.sidebar.title("Navigation")
26
- # if st.sidebar.button("PPTX Generator"):
27
- # st.session_state.current_page = "PPTX"
28
- # if st.sidebar.button("Word Generator"):
29
- # st.session_state.current_page = "Word"
30
- # if st.sidebar.button("PDF Generator"):
31
- # st.session_state.current_page = "PDF"
32
-
33
- # # Common content generation function
34
- # def generate_content(topic, output_format, slide_count=None, page_count=None):
35
- # model = genai.GenerativeModel('gemini-2.0-flash')
36
-
37
- # if output_format == "pptx":
38
- # prompt = f"""Create a comprehensive presentation on '{topic}' with exactly {slide_count} slides.
39
- # For each slide, provide:
40
- # 1. A clear title in [Title:] format
41
- # 2. 3-5 detailed bullet points in [Content:] format
42
- # 3. Optional speaker notes in [Notes:] format
43
- # 4. Layout suggestion in [Layout:] format (title-only, title-content, two-column, section-header)
44
- # """
45
- # elif output_format in ["docx", "pdf"]:
46
- # prompt = f"""Create a comprehensive document on '{topic}' with approximately {page_count} pages of content.
47
- # Provide the content in the following format:
48
- # [Heading:] Main Heading
49
- # [Subheading:] Subheading if any
50
- # [Content:]
51
- # Paragraph 1 text here.
52
- # - Bullet point 1
53
- # - Bullet point 2
54
- # Paragraph 2 text here.
55
- # """
56
-
57
- # try:
58
- # response = model.generate_content(prompt)
59
- # return response.text
60
- # except Exception as e:
61
- # st.error(f"Error generating content: {str(e)}")
62
- # return None
63
-
64
- # # PPTX Page
65
- # def pptx_page():
66
- # st.header("Text to PowerPoint Presentation")
67
- # topic = st.text_input("Enter Presentation Topic", key="pptx_topic")
68
- # slide_count = st.slider("Number of Slides", 5, 15, 7, key="pptx_slides")
69
-
70
- # if st.button("Generate Presentation", key="pptx_generate"):
71
- # if not topic.strip():
72
- # st.warning("Please enter a topic")
73
- # return
74
-
75
- # with st.spinner("Generating presentation content..."):
76
- # content = generate_content(topic, "pptx", slide_count=slide_count)
77
- # if not content:
78
- # return
79
-
80
- # slides = []
81
- # current_slide = {}
82
- # for line in content.split('\n'):
83
- # line = line.strip()
84
- # if not line:
85
- # continue
86
- # if line.startswith('[Title:]'):
87
- # if current_slide:
88
- # slides.append(current_slide)
89
- # current_slide = {
90
- # 'title': line.replace('[Title:]', '').strip(),
91
- # 'content': [],
92
- # 'notes': '',
93
- # 'layout': 'title-content'
94
- # }
95
- # elif line.startswith('[Content:]'):
96
- # content_text = line.replace('[Content:]', '').strip()
97
- # if content_text:
98
- # current_slide['content'].append(content_text)
99
- # elif line.startswith('-'):
100
- # current_slide['content'].append(line[1:].strip())
101
-
102
- # if current_slide:
103
- # slides.append(current_slide)
104
-
105
- # st.success("Presentation content generated!")
106
-
107
- # # Create PPTX
108
- # try:
109
- # prs = Presentation()
110
- # prs.slide_width = Inches(13.33)
111
- # prs.slide_height = Inches(7.5)
112
-
113
- # for slide_info in slides:
114
- # slide = prs.slides.add_slide(prs.slide_layouts[1])
115
- # slide.shapes.title.text = slide_info['title']
116
- # content_placeholder = slide.placeholders[1].text_frame
117
- # content_placeholder.clear()
118
- # for point in slide_info['content']:
119
- # p = content_placeholder.add_paragraph()
120
- # p.text = point
121
- # p.level = 0
122
-
123
- # pptx_io = BytesIO()
124
- # prs.save(pptx_io)
125
- # pptx_io.seek(0)
126
-
127
- # st.download_button(
128
- # "Download PPTX",
129
- # data=pptx_io,
130
- # file_name=f"{topic.replace(' ','_')}.pptx",
131
- # mime="application/vnd.openxmlformats-officedocument.presentationml.presentation"
132
- # )
133
- # except Exception as e:
134
- # st.error(f"Error creating PowerPoint: {str(e)}")
135
-
136
- # # Word Page
137
- # def word_page():
138
- # st.header("Text to Word Document")
139
- # topic = st.text_input("Enter Document Topic", key="word_topic")
140
- # page_count = st.slider("Approximate Page Count", 1, 10, 3, key="word_pages")
141
-
142
- # if st.button("Generate Word Document", key="word_generate"):
143
- # if not topic.strip():
144
- # st.warning("Please enter a topic")
145
- # return
146
-
147
- # with st.spinner("Generating document content..."):
148
- # content = generate_content(topic, "docx", page_count=page_count)
149
- # if not content:
150
- # return
151
-
152
- # sections = []
153
- # current_section = {'heading': '', 'subheading': '', 'content': []}
154
-
155
- # for line in content.split('\n'):
156
- # line = line.strip()
157
- # if not line:
158
- # continue
159
- # if line.startswith('[Heading:]'):
160
- # if current_section['heading'] or current_section['content']:
161
- # sections.append(current_section)
162
- # current_section = {
163
- # 'heading': line.replace('[Heading:]', '').strip(),
164
- # 'subheading': '',
165
- # 'content': []
166
- # }
167
- # elif line.startswith('[Subheading:]'):
168
- # current_section['subheading'] = line.replace('[Subheading:]', '').strip()
169
- # elif line.startswith('[Content:]'):
170
- # content_text = line.replace('[Content:]', '').strip()
171
- # if content_text:
172
- # current_section['content'].append(content_text)
173
- # elif line.startswith('-'):
174
- # current_section['content'].append(f"• {line[1:].strip()}")
175
- # else:
176
- # current_section['content'].append(line)
177
-
178
- # if current_section['heading'] or current_section['content']:
179
- # sections.append(current_section)
180
-
181
- # st.success("Document content generated!")
182
-
183
- # # Create DOCX
184
- # try:
185
- # doc = Document()
186
- # for section in sections:
187
- # if section['heading']:
188
- # doc.add_heading(section['heading'], level=1)
189
- # if section['subheading']:
190
- # doc.add_heading(section['subheading'], level=2)
191
- # for content in section['content']:
192
- # if content.startswith('•'):
193
- # doc.add_paragraph(content, style='List Bullet')
194
- # else:
195
- # doc.add_paragraph(content)
196
- # doc.add_paragraph()
197
-
198
- # docx_io = BytesIO()
199
- # doc.save(docx_io)
200
- # docx_io.seek(0)
201
-
202
- # st.download_button(
203
- # "Download DOCX",
204
- # data=docx_io,
205
- # file_name=f"{topic.replace(' ','_')}.docx",
206
- # mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
207
- # )
208
- # except Exception as e:
209
- # st.error(f"Error creating Word document: {str(e)}")
210
-
211
- # # PDF Page
212
- # def pdf_page():
213
- # st.header("Text to PDF Report")
214
- # topic = st.text_input("Enter Report Topic", key="pdf_topic")
215
- # page_count = st.slider("Approximate Page Count", 1, 10, 3, key="pdf_pages")
216
-
217
- # if st.button("Generate PDF Report", key="pdf_generate"):
218
- # if not topic.strip():
219
- # st.warning("Please enter a topic")
220
- # return
221
-
222
- # with st.spinner("Generating report content..."):
223
- # content = generate_content(topic, "pdf", page_count=page_count)
224
- # if not content:
225
- # return
226
-
227
- # sections = []
228
- # current_section = {'heading': '', 'subheading': '', 'content': []}
229
-
230
- # for line in content.split('\n'):
231
- # line = line.strip()
232
- # if not line:
233
- # continue
234
- # if line.startswith('[Heading:]'):
235
- # if current_section['heading'] or current_section['content']:
236
- # sections.append(current_section)
237
- # current_section = {
238
- # 'heading': line.replace('[Heading:]', '').strip(),
239
- # 'subheading': '',
240
- # 'content': []
241
- # }
242
- # elif line.startswith('[Subheading:]'):
243
- # current_section['subheading'] = line.replace('[Subheading:]', '').strip()
244
- # elif line.startswith('[Content:]'):
245
- # content_text = line.replace('[Content:]', '').strip()
246
- # if content_text:
247
- # current_section['content'].append(content_text)
248
- # elif line.startswith('-'):
249
- # current_section['content'].append(f"• {line[1:].strip()}")
250
- # else:
251
- # current_section['content'].append(line)
252
-
253
- # if current_section['heading'] or current_section['content']:
254
- # sections.append(current_section)
255
-
256
- # st.success("Report content generated!")
257
-
258
- # # Create PDF
259
- # try:
260
- # pdf = FPDF()
261
- # pdf.add_page()
262
- # pdf.set_font("Arial", size=12)
263
-
264
- # for section in sections:
265
- # if section['heading']:
266
- # pdf.set_font("Arial", 'B', 16)
267
- # pdf.cell(200, 10, txt=section['heading'], ln=1, align='L')
268
- # pdf.set_font("Arial", size=12)
269
- # if section['subheading']:
270
- # pdf.set_font("Arial", 'I', 14)
271
- # pdf.cell(200, 10, txt=section['subheading'], ln=1, align='L')
272
- # pdf.set_font("Arial", size=12)
273
- # for content in section['content']:
274
- # if content.startswith('•'):
275
- # pdf.cell(10)
276
- # pdf.multi_cell(0, 10, txt=content)
277
- # else:
278
- # pdf.multi_cell(0, 10, txt=content)
279
- # pdf.ln(5)
280
-
281
- # pdf_io = BytesIO()
282
- # pdf.output(pdf_io)
283
- # pdf_io.seek(0)
284
-
285
- # st.download_button(
286
- # "Download PDF",
287
- # data=pdf_io,
288
- # file_name=f"{topic.replace(' ','_')}.pdf",
289
- # mime="application/pdf"
290
- # )
291
- # except Exception as e:
292
- # st.error(f"Error creating PDF: {str(e)}")
293
-
294
- # # Main App
295
- # def main():
296
- # sidebar_nav()
297
-
298
- # if st.session_state.current_page == "PPTX":
299
- # pptx_page()
300
- # elif st.session_state.current_page == "Word":
301
- # word_page()
302
- # elif st.session_state.current_page == "PDF":
303
- # pdf_page()
304
-
305
- # if __name__ == "__main__":
306
- # main()
307
-
308
-
309
  import streamlit as st
310
 
311
  # Set page config
@@ -324,6 +16,7 @@ The **Document Generator** is a powerful Streamlit app designed to simplify docu
324
  - **Text to PDF**: Convert your text into beautifully formatted PDF documents.
325
  - **Text to Word**: Generate Word documents from your text for easy editing and sharing.
326
  - **Pexels Image Search**: Search for high-quality images from Pexels and download them directly for your projects.
 
327
 
328
  Get started by exploring these features in the full application!
329
  """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
3
  # Set page config
 
16
  - **Text to PDF**: Convert your text into beautifully formatted PDF documents.
17
  - **Text to Word**: Generate Word documents from your text for easy editing and sharing.
18
  - **Pexels Image Search**: Search for high-quality images from Pexels and download them directly for your projects.
19
+ - **Standardize_PowerPoints : Smart PPTX Styler with AI Layout & Clean Formatting.
20
 
21
  Get started by exploring these features in the full application!
22
  """)