-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_gen.py
100 lines (67 loc) · 2.04 KB
/
text_gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import os
import openai
from dotenv import load_dotenv
# Generate the response using OpenAI API
def get_response(topic):
load_dotenv()
openai_secret_key=os.getenv("OPEN_API_KEY")
openai.api_key = openai_secret_key
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": f"""
I am making slide presentation on {topic} give me content of 7 slides each slide should have concepts explainaton in a detailed manner for topic title of each slide in points your response should follow this pattern for any topics
Slide 1: Title Slide
Title:
Slide 2: Topics
Topics to be discussed:
Slide 3:
Topic:
Content:
Slide 4:
Topic:
Content:
Slide 5:
Topic:
Content:
Slide 6:
Topic:
Content:
Slide 7:
Topic:
Content:
Slide 8:
Topic:
Content:
Slide 9:
Topic:
Content:
"""
}
]
)
# Extract the text for each slide
slides = response.choices[0].message.content.split("Slide")
print(slides)
formatted_slides = []
for slide in slides[4:]:
# Split slide into title and content
slide_parts = slide.split("Content:")
if len(slide_parts) > 1:
val = slide_parts[0].split("Topic:")
title = val[1]
content = slide_parts[1].strip()
formatted_slide = {
"title": title,
"content": content
}
formatted_slides.append(formatted_slide)
# Print the formatted slides
slide_t = []
slide_c = []
for index, slide in enumerate(formatted_slides):
slide_t.append(slide['title'])
slide_c.append(slide['content'])
slide1_title = slides[2].split("Title:")[1]
slide2_content = slides[3].split("Topics to be discussed:")[1]
return slide1_title,slide2_content,slide_t,slide_c