Darpan07 commited on
Commit
e23eebc
1 Parent(s): 501a630

Upload Proposal.py

Browse files
Files changed (1) hide show
  1. Proposal.py +120 -0
Proposal.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+ import os
4
+ from pptx import Presentation
5
+ from dotenv import load_dotenv
6
+
7
+ load_dotenv()
8
+
9
+
10
+ # Functions from text.py
11
+ def generate_proposal(input_text):
12
+ response = openai.ChatCompletion.create(
13
+ model="gpt-3.5-turbo-16k",
14
+ messages=[
15
+ {
16
+ "role": "system",
17
+ "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 :",
18
+ },
19
+ {"role": "user", "content": input_text},
20
+ ],
21
+ max_tokens=8192,
22
+ temperature=0.7,
23
+ n=1,
24
+ stop=None,
25
+ )
26
+ return response.choices[0].message["content"]
27
+
28
+
29
+ def generate_presentation(proposal_text, num_slides):
30
+ response = openai.ChatCompletion.create(
31
+ model="gpt-3.5-turbo-16k",
32
+ messages=[
33
+ {
34
+ "role": "system",
35
+ "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. :",
36
+ },
37
+ {"role": "user", "content": proposal_text},
38
+ ],
39
+ max_tokens=8192,
40
+ temperature=0.7,
41
+ n=1,
42
+ stop=None,
43
+ )
44
+ return response.choices[0].message["content"]
45
+
46
+
47
+ # def read_template(file_path):
48
+ # # Read the contents of the .potx file
49
+ # with open(file_path, "rb") as file:
50
+ # return file.read().decode("latin-1", errors="replace")
51
+
52
+
53
+ def generate_python_code(template_path, presentation_text):
54
+ # Use GPT-3.5 model to generate Python code based on the presentation text and the template path
55
+ response = openai.ChatCompletion.create(
56
+ model="gpt-3.5-turbo-16k",
57
+ messages=[
58
+ {
59
+ "role": "system",
60
+ "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 :",
61
+ },
62
+ {"role": "user", "content": template_path},
63
+ {"role": "user", "content": presentation_text},
64
+ ],
65
+ max_tokens=8192,
66
+ temperature=0.7,
67
+ timeout=240,
68
+ )
69
+ return response.choices[0].message["content"]
70
+
71
+
72
+ def create_presentation(slides):
73
+ prs = Presentation(r"CB_Master_Template.pptx")
74
+
75
+ for title, content in slides:
76
+ slide_layout = prs.slide_layouts[1] # Title Slide layout
77
+ slide = prs.slides.add_slide(slide_layout)
78
+
79
+ # Find the title placeholder
80
+ title_placeholder = slide.shapes.title
81
+
82
+ # Find the content placeholder
83
+ content_placeholder = None
84
+ for shape in slide.shapes:
85
+ if (
86
+ shape.has_text_frame
87
+ and shape.shape_type == pptx.shapes.shapeTree.MSO_SHAPE_TYPE.AUTO_SHAPE
88
+ ):
89
+ content_placeholder = shape.text_frame
90
+ break
91
+
92
+ # Set the title and content
93
+ title_placeholder.text = title
94
+ if content_placeholder:
95
+ content_placeholder.text = content
96
+
97
+
98
+ def prop(num_slides):
99
+
100
+ proposal_text = generate_proposal(st.session_state["user_stories"])
101
+ print("Proposal generated successfully!")
102
+
103
+ presentation_text = generate_presentation(proposal_text, num_slides)
104
+ print("Presentation generated successfully!")
105
+
106
+ python_code = generate_python_code("CB_Master_Template.pptx", presentation_text)
107
+ print("Python code generated successfully!")
108
+
109
+ with open("generated_code.py", "w") as f:
110
+ f.write(python_code)
111
+
112
+ print("Python code saved to 'generated_code.py' successfully!")
113
+
114
+ # Execute the generated Python code
115
+ exec(python_code, globals())
116
+ slides = [] # This should be defined in the generated Python code
117
+ prs = create_presentation(slides)
118
+
119
+ print("Presentation created successfully!")
120
+ st.session_state["is_presentation_created"] = True