feat(video.py): add support for script_prompt.txt file to customize script prompts

fix(script.py): add prompt parameter to generate_script function
feat(main.py): add loop to run main function indefinitely and add option to quit with ctrl+c
This commit is contained in:
Paillat
2023-06-25 19:14:22 +02:00
parent f0dff73ce7
commit 5498fb7bac
3 changed files with 18 additions and 6 deletions

View File

@@ -35,7 +35,15 @@ class Video:
os.remove(os.path.join( self.path, "script.json")) os.remove(os.path.join( self.path, "script.json"))
if not os.path.exists(os.path.join( self.path, "script.json")): if not os.path.exists(os.path.join( self.path, "script.json")):
script = await generate_script(self.idea['title'], self.idea['description']) script_prompt = None
if os.path.exists(os.path.join(self.parent.path, "script_prompt.txt")):
with open(os.path.join(self.parent.path, "script_prompt.txt"), "r") as f:
script_prompt = f.read()
f.close()
if script_prompt:
script = await generate_script(self.idea['title'], self.idea['description'], script_prompt)
else:
script = await generate_script(self.idea['title'], self.idea['description'])
with open(os.path.join( self.path, "script.json"), "w") as f: with open(os.path.join( self.path, "script.json"), "w") as f:
json.dump(json.loads(script), f) json.dump(json.loads(script), f)
f.close() f.close()

View File

@@ -6,8 +6,7 @@ with open('prompts/script.txt') as f:
global_prompt = f.read() global_prompt = f.read()
f.close() f.close()
async def generate_script(title, description): async def generate_script(title, description, prompt=global_prompt):
prompt = global_prompt
prompt = prompt.replace("[title]", title) prompt = prompt.replace("[title]", title)
prompt = prompt.replace("[description]", description) prompt = prompt.replace("[description]", description)
'''response = await openai.ChatCompletion.acreate( '''response = await openai.ChatCompletion.acreate(

11
main.py
View File

@@ -65,7 +65,12 @@ async def main():
printm("Done!") printm("Done!")
printm("Here is the video:") printm("Here is the video:")
printm(video) printm(video)
input("Press enter to continue...")
if __name__ == "__main__": if __name__ == "__main__":
loop = asyncio.get_event_loop() while True:
loop.run_until_complete(main()) asyncio.run(main())
loop.close() try:
input("Press enter to continue or type ctrl+c to quit : ")
clear_screen()
except KeyboardInterrupt:
break