mirror of
https://github.com/Paillat-dev/FABLE.git
synced 2026-01-02 01:06:20 +00:00
Added and fixed a whole bunch of things
This commit is contained in:
@@ -5,18 +5,23 @@ from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||
subject = os.getenv("SUBJECT")
|
||||
with open('prompts/ideas.txt') as f:
|
||||
prompt = f.read().replace('[subject]', subject)
|
||||
prompt = f.read()
|
||||
f.close()
|
||||
|
||||
|
||||
async def generate_ideas(path):
|
||||
async def generate_ideas(path, subject):
|
||||
prmpt = prompt.replace('[subject]', subject)
|
||||
try:
|
||||
with open(f'{path}/ideas.json', 'r') as f:
|
||||
ideas = f.read()
|
||||
ides_json = json.loads(ideas)
|
||||
f.close()
|
||||
prmpt = prompt.replace('[existing ideas]', ideas)
|
||||
except:
|
||||
ides_json = []
|
||||
ideas = "There are no existing ideas."
|
||||
prmpt = prmpt.replace('[existing ideas]', ideas)
|
||||
print(prmpt)
|
||||
response = await openai.ChatCompletion.acreate(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
|
||||
@@ -61,7 +61,15 @@ def generate_miniature(path, title, description):
|
||||
generate_image(path, text1, text2)
|
||||
|
||||
def generate_image(path, text1, text2):
|
||||
bcg = Image.open("bcg.png")
|
||||
path_to_bcg = path.split("/")[:-1]
|
||||
path_to_bcg = "/".join(path_to_bcg)
|
||||
print(path_to_bcg)
|
||||
if not os.path.exists(f"{path_to_bcg}/bcg.png"):
|
||||
input("bcg.png not found. Please put bcg.png in the same folder as the video."+path_to_bcg)
|
||||
if not os.path.exists(f"{path_to_bcg}/bcg.png"):
|
||||
input("bcg.png still not found. Exiting.")
|
||||
exit()
|
||||
bcg = Image.open(f"{path_to_bcg}/bcg.png")
|
||||
img = Image.new('RGBA', (1920, 1080))
|
||||
img, textcolor1, textcolor2 = rand_gradient(img)
|
||||
draw = ImageDraw.Draw(img)
|
||||
@@ -108,5 +116,3 @@ def generate_image(path, text1, text2):
|
||||
img.paste(imgtext2, (0, 0), imgtext2)
|
||||
img.save(path + "/miniature.png")
|
||||
return path + "/miniature.png"
|
||||
|
||||
generate_image("test", "Master python loops", "Effortlessly")
|
||||
@@ -28,7 +28,8 @@ RETRIABLE_STATUS_CODES = [500, 502, 503, 504]
|
||||
|
||||
CLIENT_SECRETS_FILE = 'env/client_secret.json'
|
||||
|
||||
SCOPES = ['https://www.googleapis.com/auth/youtube.upload', 'POST https://www.googleapis.com/upload/youtube/v3/thumbnails/set', 'https://www.googleapis.com/auth/youtube.force-ssl']
|
||||
#SCOPES = ['https://www.googleapis.com/auth/youtube.upload', 'https://www.googleapis.com/upload/youtube/v3/thumbnails/set', 'https://www.googleapis.com/auth/youtube.force-ssl']
|
||||
SCOPES = ['https://www.googleapis.com/auth/youtube']
|
||||
API_SERVICE_NAME = 'youtube'
|
||||
API_VERSION = 'v3'
|
||||
|
||||
@@ -36,9 +37,9 @@ VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted')
|
||||
|
||||
|
||||
# Authorize the request and store authorization credentials.
|
||||
def get_authenticated_service():
|
||||
if os.path.exists('env/credentials.json'):
|
||||
with open('env/credentials.json') as json_file:
|
||||
def get_authenticated_service(credentialsPath=""):
|
||||
if os.path.exists(f'{credentialsPath}/credentials.json'):
|
||||
with open(f'{credentialsPath}/credentials.json') as json_file:
|
||||
data = json.load(json_file)
|
||||
credentials = google.oauth2.credentials.Credentials(
|
||||
token=data['token'],
|
||||
@@ -52,7 +53,7 @@ def get_authenticated_service():
|
||||
flow = InstalledAppFlow.from_client_secrets_file(
|
||||
CLIENT_SECRETS_FILE, SCOPES)
|
||||
credentials = flow.run_local_server()
|
||||
with open('env/credentials.json', 'w') as outfile:
|
||||
with open(f'{credentialsPath}/credentials.json', 'w') as outfile:
|
||||
outfile.write(credentials.to_json())
|
||||
return build(API_SERVICE_NAME, API_VERSION, credentials=credentials)
|
||||
|
||||
@@ -67,10 +68,12 @@ def initialize_upload(youtube, options):
|
||||
title=options['title'],
|
||||
description=options['description'],
|
||||
tags=tags,
|
||||
categoryId=options['category']
|
||||
categoryId=options['category'],
|
||||
defaultLanguage='en'
|
||||
),
|
||||
status=dict(
|
||||
privacyStatus=options['privacyStatus']
|
||||
privacyStatus=options['privacyStatus'],
|
||||
selfDeclaredMadeForKids=False
|
||||
)
|
||||
)
|
||||
|
||||
@@ -81,7 +84,8 @@ def initialize_upload(youtube, options):
|
||||
media_body=MediaFileUpload(options['file'], chunksize=-1, resumable=True)
|
||||
)
|
||||
|
||||
resumable_upload(insert_request)
|
||||
videoid = resumable_upload(insert_request)
|
||||
return videoid
|
||||
|
||||
|
||||
def resumable_upload(request):
|
||||
@@ -96,6 +100,7 @@ def resumable_upload(request):
|
||||
if 'id' in response:
|
||||
print('Video id "%s" was successfully uploaded.' %
|
||||
response['id'])
|
||||
return response['id']
|
||||
else:
|
||||
exit('The upload failed with an unexpected response: %s' % response)
|
||||
except HttpError as e:
|
||||
@@ -118,20 +123,25 @@ def resumable_upload(request):
|
||||
print('Sleeping %f seconds and then retrying...' % sleep_seconds)
|
||||
time.sleep(sleep_seconds)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sample_options = {
|
||||
'file': './test.mp4',
|
||||
'title': 'Test Title',
|
||||
'description': 'Test Description',
|
||||
'category': 22,
|
||||
'keywords': 'test, video',
|
||||
'privacyStatus': 'private'
|
||||
def upload_video(path, title, description, category, keywords, privacyStatus='private', credentials_path=""):
|
||||
options = {
|
||||
'file': path +"/montage.mp4",
|
||||
'title': title,
|
||||
'description': description,
|
||||
'category': category,
|
||||
'keywords': keywords,
|
||||
'privacyStatus': privacyStatus
|
||||
}
|
||||
|
||||
youtube = get_authenticated_service()
|
||||
|
||||
youtube = get_authenticated_service(credentials_path)
|
||||
try:
|
||||
initialize_upload(youtube, sample_options)
|
||||
videoid = initialize_upload(youtube, options)
|
||||
except HttpError as e:
|
||||
print('An HTTP error %d occurred:\n%s' % (e.resp.status, e.content))
|
||||
upload_thumbnail(videoid, path + "/miniature.png", credentials_path)
|
||||
|
||||
def upload_thumbnail(video_id, file, credentials_path=""):
|
||||
youtube = get_authenticated_service(credentials_path)
|
||||
youtube.thumbnails().set(
|
||||
videoId=video_id,
|
||||
media_body=file
|
||||
).execute()
|
||||
9
main.py
9
main.py
@@ -7,10 +7,12 @@ from generators.ideas import generate_ideas
|
||||
from generators.script import generate_script
|
||||
from generators.montage import mount, prepare, translate
|
||||
from generators.miniature import generate_miniature
|
||||
from generators.uploader import upload_video
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
async def main():
|
||||
if not os.path.exists('videos'): os.makedirs('videos')
|
||||
with open('env/subjects.txt', 'r', encoding='utf-8') as f:
|
||||
subjects = f.read().splitlines()
|
||||
f.close()
|
||||
@@ -18,11 +20,11 @@ async def main():
|
||||
print(str(i) + ". " + subjects[i])
|
||||
subject = int(input("Which subject do you want to generate ideas for? (enter the number): "))
|
||||
subject = subjects[subject]
|
||||
subjectdirpath = subject[:25].replace(" ", "_").replace(":", "")
|
||||
subjectdirpath = "videos/" + subject[:25].replace(" ", "_").replace(":", "")
|
||||
if not os.path.exists(subjectdirpath): os.makedirs(subjectdirpath)
|
||||
if input("Do you want to generate new ideas? (y/n)") == "y":
|
||||
await generate_ideas(subjectdirpath)
|
||||
with open('ideas/ideas.json', 'r', encoding='utf-8') as f:
|
||||
await generate_ideas(subjectdirpath, subject)
|
||||
with open(subjectdirpath + '/ideas.json', 'r', encoding='utf-8') as f:
|
||||
ideas = json.load(f)
|
||||
f.close()
|
||||
for i in range(len(ideas)):
|
||||
@@ -55,6 +57,7 @@ async def main():
|
||||
f.write(f"Titre: {transtitle}\nDescription: {transdesc}\nCrédits musicaux: {credits}")
|
||||
f.close()
|
||||
generate_miniature(path, title=idea['title'], description=idea['description'])
|
||||
upload_video(path, idea['title'], idea['description'], 28, "", "private", subjectdirpath)
|
||||
print(f"Your video is ready! You can find it in {path}.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
BIN
montage.mp4
BIN
montage.mp4
Binary file not shown.
BIN
nobg_logo_2.png
BIN
nobg_logo_2.png
Binary file not shown.
|
Before Width: | Height: | Size: 331 KiB |
@@ -6,12 +6,12 @@ Here is an example of the output:
|
||||
```
|
||||
[
|
||||
{
|
||||
"title": "Python Tutorial for Beginners",
|
||||
"description": "A video for beginners to learn Python. The following topics are covered: variables, data types, functions, classes, and more."
|
||||
"title": "TITLE OF THE VIDEO",
|
||||
"description": "A video about something. Concept1 and concept2 are explained. Concept3 is also explained a bit."
|
||||
},
|
||||
{
|
||||
"title": "DRAMA: MrBeast did WHAT?!",
|
||||
"description": "MrBeast did something crazy. You won't believe what he did. Watch the video to find out."
|
||||
"title": "TITLE OF THE VIDEO",
|
||||
"description": "A video about something. Concept1 and concept2 are explained. Concept3 is also explained a bit."
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
@@ -27,6 +27,10 @@ Your video will be detailed, long and very complete. Here is an example:
|
||||
{
|
||||
"spoken":"This is a latex formula wich is very important. It is the formula of the integral of x squared from 0 to infinity. You can see it on the screen.",
|
||||
"markdown":"$$\n\\int_0^\\infty x^2 dx\n$$"
|
||||
},
|
||||
{
|
||||
"spoken":"tHanks for watching this video. If you liked it, please like, share and subscribe. See you in the next video.",
|
||||
"image":"thanks+goodbye"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user