From 5498fb7bace7d44c41a02f24ea1ce37e66d976f6 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 25 Jun 2023 19:14:22 +0200 Subject: [PATCH] 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 --- classes/video.py | 10 +++++++++- generators/script.py | 3 +-- main.py | 11 ++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/classes/video.py b/classes/video.py index 193541d..0bfe838 100644 --- a/classes/video.py +++ b/classes/video.py @@ -35,7 +35,15 @@ class Video: os.remove(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: json.dump(json.loads(script), f) f.close() diff --git a/generators/script.py b/generators/script.py index 963e885..0fe2e99 100644 --- a/generators/script.py +++ b/generators/script.py @@ -6,8 +6,7 @@ with open('prompts/script.txt') as f: global_prompt = f.read() f.close() -async def generate_script(title, description): - prompt = global_prompt +async def generate_script(title, description, prompt=global_prompt): prompt = prompt.replace("[title]", title) prompt = prompt.replace("[description]", description) '''response = await openai.ChatCompletion.acreate( diff --git a/main.py b/main.py index f11967e..04af359 100644 --- a/main.py +++ b/main.py @@ -65,7 +65,12 @@ async def main(): printm("Done!") printm("Here is the video:") printm(video) + input("Press enter to continue...") if __name__ == "__main__": - loop = asyncio.get_event_loop() - loop.run_until_complete(main()) - loop.close() + while True: + asyncio.run(main()) + try: + input("Press enter to continue or type ctrl+c to quit : ") + clear_screen() + except KeyboardInterrupt: + break \ No newline at end of file