diff --git a/main.py b/main.py index 2fb3601..b9b13e1 100755 --- a/main.py +++ b/main.py @@ -54,11 +54,14 @@ def main(POST_ID=None) -> None: reddit_object = get_subreddit_threads(POST_ID) redditid = id(reddit_object) post_text = ' '.join(reddit_object['thread_post']) + print(reddit_object['thread_post']) + print("================================================================") + print(post_text) if not os.path.exists(f"./assets/temp/{reddit_object['thread_id']}/"): - settings.config["settings"]["debug"]["reuse_images"] = False - settings.config["settings"]["debug"]["reuse_mp3"] = False - settings.config["settings"]["debug"]["reuse_video"] = False + for key in settings.config["settings"]["debug"].keys(): + if key != "debug": + settings.config["settings"]["debug"][key] = False length, number_of_comments = save_text_to_mp3(reddit_object) length = math.ceil(length) diff --git a/requirements.txt b/requirements.txt index 4f1092b..6604827 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/utils/.config.template.toml b/utils/.config.template.toml index 6cea8ff..af30ed1 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -18,6 +18,8 @@ min_comments = { default = 20, optional = false, nmin = 10, type = "int", explan [ai] ai_similarity_enabled = {optional = true, option = [true, false], default = false, type = "bool", explanation = "Threads read from Reddit are sorted based on their similarity to the keywords given below"} ai_similarity_keywords = {optional = true, type="str", example= 'Elon Musk, Twitter, Stocks', explanation = "Every keyword or even sentence, seperated with comma, is used to sort the reddit threads based on similarity"} +gemini_api_key = { optional = false, example = "21f13f91f54d741e2ae27d2ab1b99d59", explanation = "Gemini API key" } +openai_api_key = { optional = false, example = "21f13f91f54d741e2ae27d2ab1b99d59", explanation = "OpenAI API key" } [settings] allow_nsfw = { optional = false, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Whether to allow NSFW content, True or False" } @@ -35,8 +37,10 @@ run_every = { optional = false, default = 24, example = 5, explanation = "How of [settings.debug] debug = { optional = false, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Debug mode (Whether to delete temp files after creating the video or not)" } -reuse_mp3 = { optional = false, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Use mp3 files from temp data" } +reuse_separate_mp3s = { optional = false, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Use mp3 files from temp data" } +reuse_mp3 = { optional = false, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Use the whole mp3 file from temp data" } reuse_images = { optional = false, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Use images from temp data" } +reuse_background = { optional = false, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Use previously generated background audio & video." } reuse_video = { optional = false, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Use already generated video" } [settings.background] @@ -66,6 +70,3 @@ python_voice = { optional = false, default = "1", example = "1", explanation = " py_voice_num = { optional = false, default = "2", example = "2", explanation = "The number of system voices (2 are pre-installed in Windows)" } silence_duration = { optional = true, example = "0.1", explanation = "Time in seconds between TTS comments", default = 0.3, type = "float" } no_emojis = { optional = false, type = "bool", default = false, example = false, options = [true, false,], explanation = "Whether to remove emojis from the comments" } - -[settings.gemini] -gemini_api_key = { optional = false, example = "21f13f91f54d741e2ae27d2ab1b99d59", explanation = "Gemini API key" } \ No newline at end of file diff --git a/utils/compressor.py b/utils/compressor.py index de5edff..11919a1 100644 --- a/utils/compressor.py +++ b/utils/compressor.py @@ -1,6 +1,6 @@ import os import ffmpeg -import settings +from utils import settings def compress_video(video_full_path): diff --git a/utils/proofreading.py b/utils/proofreading.py new file mode 100644 index 0000000..c2f2429 --- /dev/null +++ b/utils/proofreading.py @@ -0,0 +1,35 @@ +import time +import google +import google.generativeai as genai +from utils import settings + + +genai.configure(api_key=settings.config["ai"]["gemini_api_key"]) +model = genai.GenerativeModel('gemini-pro') + +prompt = """Can you please proof read this text while keeping the context the same. +Only respond with the proofread text. +If any part of the text wasn't human understandable remove it. +Here it is: +""" + + +def proofread_post(post): + proofread_post = [] + for post_part in post: + try: + proofread_post_part = model.generate_content(prompt + post_part) + except google.api_core.exceptions.ResourceExhausted: + print("Resource Exhausted when proofreading the post. Sleeping for a few seconds.") + time.sleep(62) + proofread_post_part = model.generate_content(prompt + post_part) + + try: + proofread_post_part = proofread_post_part.text + print("Text:", proofread_post_part) + except: + print("Data:", proofread_post_part.prompt_feedback) + proofread_post_part = post_part + print("Original Text:", proofread_post_part) + proofread_post.append(proofread_post_part) + return proofread_post \ No newline at end of file diff --git a/video_creation/voices.py b/video_creation/voices.py index 5895933..f7dcb5a 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -38,10 +38,14 @@ def save_text_to_mp3(reddit_obj) -> Tuple[int, int]: tuple[int,int]: (total length of the audio, the number of comments audio was generated for) """ - if settings.config["settings"]["debug"]["reuse_mp3"]: + if settings.config["settings"]["debug"]["reuse_separate_mp3s"]: comments = len(glob.glob(f"./assets/temp/{reddit_obj['thread_id']}/mp3/*")) - 2 - audio = AudioSegment.from_mp3(f"./assets/temp/{reddit_obj['thread_id']}/audio.mp3") - return audio.duration_seconds, comments + duration = 0 + audios = glob.glob(f"./assets/temp/{reddit_obj['thread_id']}/mp3/*") + for audio in audios: + audio = AudioSegment.from_mp3(audio) + duration += audio.duration_seconds + settings.config["settings"]["tts"]["silence_duration"] + return duration, comments voice = settings.config["settings"]["tts"]["voice_choice"] if str(voice).casefold() in map(lambda _: _.casefold(), TTSProviders): diff --git a/video_data_generation/gemini.py b/video_data_generation/gemini.py index 144d9f7..19ccbe6 100644 --- a/video_data_generation/gemini.py +++ b/video_data_generation/gemini.py @@ -2,7 +2,7 @@ import google.generativeai as genai from utils import settings -genai.configure(api_key=settings.config["settings"]["gemini"]["gemini_api_key"]) +genai.configure(api_key=settings.config["ai"]["gemini_api_key"]) prompt1 = """I make some youtube videos where I get subreddits about ghost stories and make a video of it. I will send a post to you and you should generate a YouTube video title, tags and description for it. @@ -54,9 +54,9 @@ def get_credits(bg_config): video_credits = bg_config['video'][-2] credits_template = f""" - Background audio by - {audio_credits} - Background video by - {video_credits} - """ +Background audio by - {audio_credits} +Background video by - {video_credits} +""" return credits_template def get_data(post): @@ -92,27 +92,3 @@ def get_video_data(post, bg_config): data['description'] = description_tags + data['description'] + get_credits(bg_config) data['tags'] = data['tags'] + ', ' + ', '.join(default_tags) return data, thumbnail - -if __name__ == '__main__': - post = """ - -This is my dads story. With all of the weirdest things that have happened, this one takes the cake. - -My dad doesn't really speak of many paranormal experiences. This one freaked him out enough though, that he told me. One night, he went to bed with my mom and their dogs. My dad falls asleep pretty fast but for some reason that night, he couldn't. - -Some background info: My parents at the time had two cats, Sweetpea and Baby Princess( my sister named her when she was 6) Their cats would sometimss go into their room when they were sleeping. My parents always slept with their door open(I could never, creeps me out). Their room is the first room when you would reach the top of the steps. - -Anyways, my dad was laying in bed tossing and turning. He flipped on his back and closed his eyes. When he was laying there, he felt a pressure going up his legs. He figured the cats were walking up his legs. He then realized the pressure was going up his legs and ended up to his chest. He couldn't move a muscle. That's when he started to choke. His eyes popped open and he looked over and there was a figure standing over him with his hands around my dads throat. - -According to my dad, the figure had a black WW2 Nazi uniform on with the black uniform hat that had a swastika on it. The choking lasted for some time until my dad told it to get the fuck off of him, then it disappeared. My dad was freaked out. He got up and checked inside all of our bedrooms and throughout the house but couldn't find anyone anywhere. Everyone was asleep. - -I asked my dad why he thought the Nazi was choking him. He said he wasn't sure why, maybe he was an old angry relative. My grandma grew up in Germany through the war and my grandmas dad was a Nazi. So to say the least, we had some relatives that were in the war. I'm not sure why this ghost attacked my dad, maybe because he was the strongest in the house? Who knows. - -My dad isn't one to make up stories like this, so I believe him. He's a very strong and brave man, and it takes a lot for him to get scared. He told me that this really got to him and that he was scared for us and this is why he got up and searched throughout the house. Usually, if paranormal things happen, he doesn't say much because he didn't want to scare us when we were kids. - -I know that some of you might think that he had sleep paralysis when this happened, but my dad did not suffer from this. He told me that this was the first and only time that he couldn't move like this. - -Thank you for reading! Let me know what you guys think :) -""" - for i in get_video_data(post): - print(i, end="\n\n") \ No newline at end of file