-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_video_content.py
More file actions
79 lines (63 loc) · 2.67 KB
/
Copy pathgenerate_video_content.py
File metadata and controls
79 lines (63 loc) · 2.67 KB
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
from checker import middleware
from choose_title_type import choose_title_type
from generate_title_gpt4o import generate_title_gpt4o
from split_text import split_text
from youtube_to_mp3 import youtube_to_mp3
from openai_client import openai_client
client = openai_client()
def generate_title(text):
sections = split_text(text)
prompt = "create a title of the following text: "
try:
responses = []
for section in sections:
response = client.completions.create(
model="gpt-3.5-turbo-instruct",
prompt=prompt + "\n" + section + "\n\n",
max_tokens=100,
temperature=0.8,
)
responses.append(response.choices[0].text.strip())
except Exception as e:
return str(e)
try:
title_response = client.completions.create(
model="gpt-3.5-turbo-instruct",
prompt="create a title from the following text:" + "\n" + " ".join(responses) + "\n\n",
max_tokens=140,
temperature=1,
)
return title_response.choices[0].text.strip()
except Exception as e:
return str(e)
def generate_text(textPrompt, inputText, maxTokens):
sections = split_text(inputText)
try:
newText = []
for section in sections:
prompt = textPrompt + "\n" + section + "\n\n",
response = client.completions.create(
model="gpt-3.5-turbo-instruct",
prompt=prompt,
max_tokens=maxTokens,
temperature=0.7,
stop=["\n"]
)
newText.append(response.choices[0].text.strip())
except Exception as e:
return str(e)
if len(newText) > 2:
return ''.join(newText)
elif len(newText) == 1:
return newText[0]
else:
return ""
def scriptVideoWriter(maxTokens, url, channel_type):
textPrompt, backgroundMusic,backgroundMusicShort, images_directory, images_short_directory, generated_images_directory, videos_directory, thumbnail_directory, channel, voice, ythandle, deleted_path = choose_title_type(channel_type)
middleware(channel)
youtubeText, title = youtube_to_mp3(url)
# title = generate_title(youtubeText)
generate_title_gpt4o(title)
text = generate_text(textPrompt, youtubeText , maxTokens)
title = str(title).replace('"', "").replace(":", "").replace(" ", "_").replace("'", "").replace("\n", "").replace('"', "").replace(".", "").lower()
return title, text, backgroundMusic,backgroundMusicShort, images_directory,images_short_directory, generated_images_directory, videos_directory, thumbnail_directory, channel, voice, ythandle, deleted_path