import streamlit as st import openai import os from pptx import Presentation from dotenv import load_dotenv load_dotenv() # Functions from text.py def generate_proposal(input_text): response = openai.ChatCompletion.create( model="gpt-3.5-turbo-16k", messages=[ { "role": "system", "content": "As an expert proposal generator with a keen eye for detail and precision, your task is to craft a professional and comprehensive proposal that will include overview, problem statement, proposed features, solutioning process, roadmap, estimates, team structure and next steps using the provided text. The emphasis will be on maintaining high-quality content, accuracy, and minimizing any potential inaccuracies or imaginative elements in the output. The goal is to create a visually appealing proposal that effectively communicates the key aspects of the input data, ensuring clarity and audience engagement throughout the proposal :", }, {"role": "user", "content": input_text}, ], max_tokens=8192, temperature=0.7, n=1, stop=None, ) return response.choices[0].message["content"] def generate_presentation(proposal_text, num_slides): response = openai.ChatCompletion.create( model="gpt-3.5-turbo-16k", messages=[ { "role": "system", "content": f"As an expert presentation generator with a focus on quality and accuracy, your task is to create a professional presentation consisting of {num_slides} slides for the provided proposal data. The emphasis will be on maintaining high-quality content, accuracy, and minimizing any potential inaccuracies or imaginative elements in the output. The goal is to create a visually appealing presentation that effectively communicates the key aspects of the proposal, ensuring clarity and audience engagement throughout the slides. :", }, {"role": "user", "content": proposal_text}, ], max_tokens=8192, temperature=0.7, n=1, stop=None, ) return response.choices[0].message["content"] # def read_template(file_path): # # Read the contents of the .potx file # with open(file_path, "rb") as file: # return file.read().decode("latin-1", errors="replace") def generate_python_code(template_path, presentation_text): # Use GPT-3.5 model to generate Python code based on the presentation text and the template path response = openai.ChatCompletion.create( model="gpt-3.5-turbo-16k", messages=[ { "role": "system", "content": "You are an expert Python programmer tasked with generating code to create a PowerPoint presentation from given presentation text and a template file. Your code should focus on producing high-quality, accurate content while minimizing potential inaccuracies or imaginative elements. Incorporate robust error handling mechanisms to ensure reliable execution. The generated code should be clean, concise, and free from any suggestions, notes, or comments. Ensure that the output remains consistent and unchanged when the code is executed multiple times. Additionally, include functionality to save the generated PowerPoint presentation as a file named 'generated_presentation.pptx' and provide a mechanism for the user to download this file, such as a download button or a file download prompt :", }, {"role": "user", "content": template_path}, {"role": "user", "content": presentation_text}, ], max_tokens=8192, temperature=0.7, timeout=240, ) return response.choices[0].message["content"] def create_presentation(slides): prs = Presentation(r"CB_Master_Template.pptx") for title, content in slides: slide_layout = prs.slide_layouts[1] # Title Slide layout slide = prs.slides.add_slide(slide_layout) # Find the title placeholder title_placeholder = slide.shapes.title # Find the content placeholder content_placeholder = None for shape in slide.shapes: if ( shape.has_text_frame and shape.shape_type == pptx.shapes.shapeTree.MSO_SHAPE_TYPE.AUTO_SHAPE ): content_placeholder = shape.text_frame break # Set the title and content title_placeholder.text = title if content_placeholder: content_placeholder.text = content def prop(num_slides): proposal_text = generate_proposal(st.session_state["user_stories"]) print("Proposal generated successfully!") presentation_text = generate_presentation(proposal_text, num_slides) print("Presentation generated successfully!") python_code = generate_python_code("CB_Master_Template.pptx", presentation_text) print("Python code generated successfully!") # with open("generated_code.py", "w") as f: # f.write(python_code) # print("Python code saved to 'generated_code.py' successfully!") # Execute the generated Python code exec(python_code, globals()) slides = [] # This should be defined in the generated Python code prs = create_presentation(slides) print("Presentation created successfully!") st.session_state["is_presentation_created"] = True