-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·152 lines (133 loc) · 5.41 KB
/
main.py
File metadata and controls
executable file
·152 lines (133 loc) · 5.41 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python3
import os, dotenv, json
import warnings
warnings.filterwarnings("ignore")
os.environ["IMAGEIO_FFMPEG_EXE"] = "/usr/bin/ffmpeg" #
dotenv.load_dotenv()
from pathlib import Path
# Set environment variables for Hugging Face
base_path = Path(__file__).parent.resolve()
os.environ["HF_HOME"] = os.path.join(base_path, "models")
os.environ["HF_HUB_CACHE"] = os.path.join(base_path, "models")
os.environ["TRANSFORMERS_CACHE"] = os.path.join(base_path, "models")
import torch
from huggingface_hub import login
login(token=os.environ["HUGGINGFACE_TOKEN"])
from src.reddit_bot import RedditBot
from src.claude_bot import ClaudeBot
from src.prompt_generator import PromptGenerator
from src.image_generator import ImageGenerator
from src.audio_narrator import AudioNarrator
from src.movie_maker import MovieMaker
from src.metadata_generator import MetadataGenerator
from src.youtube_publisher import YouTubePublisher
#torch.cuda.empty_cache()
#load all variables
SUB_REDDIT_NAME = os.getenv("REDDIT_SUBREDDIT_NAME", "TrueCrime")
TARGET_FLAIR = os.getenv("REDDIT_TARGET_FLAIR", "Murder")
POST_DIR = "data"
OVERLAY = "assets/vhs_overrlay.mp4"
BG_TRACK = "assets/Rain_Sound_Effect.webm"
CREDS_FILE = "credentials/credentials.json"
TOKEN_FILE = "credentials/token.json"
SCOPES = [
"https://www.googleapis.com/auth/youtube.upload",
"https://www.googleapis.com/auth/youtubepartner"
]
INTRO = "assets/intro.mp4"
OUTRO = "assets/outro.mp4"
if __name__ == "__main__":
#create config file if it doesn't exist
if not os.path.exists("config/config.json"):
config = {
"published_posts": []
}
os.makedirs("config", exist_ok=True)
with open("config/config.json", "w") as f:
json.dump(config, f, indent=4)
print("Config file created at config/config.json")
#load config json
with open("config/config.json", "r") as f:
config = json.load(f)
p3r = config.get("published_posts_per_run", 1)
count = 0
posts = os.listdir(POST_DIR)
while count < p3r:
with open("config/config.json", "r") as f:
config = json.load(f)
#return a single post that is not in config["published_posts"]
posts = [post for post in posts if post not in config["published_posts"]]
# print(config["published_posts"])
# print(posts)
post = posts[0] if posts else None
if not post:
print("No new posts found to process.")
exit(0)
post_path = os.path.join(POST_DIR, post)
print(f"Processing post: {post_path}")
if len(os.listdir(POST_DIR)) <= len(config["published_posts"]):
print("No new posts found to process.")
#run reddit bot
print("running reddit bot...")
exit(0)
#run reddit bot
# authenticate Reddit bot using environment variables
reddit_bot = RedditBot(
client_id=os.getenv("REDDIT_CLIENT_ID"),
client_secret=os.getenv("REDDIT_CLIENT_SECRET"),
user_agent=os.getenv("REDDIT_USER_AGENT"),
username=os.getenv("REDDIT_USERNAME"),
password=os.getenv("REDDIT_PASSWORD")
)
reddit_bot.set_subreddit(SUB_REDDIT_NAME, TARGET_FLAIR)
posts = reddit_bot.search_posts(sort="new", time_filter="all", limit=10)
reddit_bot.save_data(posts, data_path="data")
print(f"Data saved for posts in subreddit '{SUB_REDDIT_NAME}' with flair '{TARGET_FLAIR}'.")
#run anthropic bot
print("-"* 50)
print("creating narration using Claude...")
claude_bot = ClaudeBot(api_key=os.getenv("CLAUDE_API_KEY"))
claude_bot.run(post_path=post_path)
print("\n\n")
#run prompt generator
print("-"* 50)
print("generating prompts...")
prompt_generator = PromptGenerator(model_name="gpt-4o", temperature=0)
prompt_generator.generate_prompts(post_path=post_path)
print("\n\n")
#run image generator
print("-"* 50)
print("generating images...")
image_generator = ImageGenerator(model_name="black-forest-labs/FLUX.1-dev", device="cuda")
image_generator.generate_image(post_path=post_path)
print("Image generation complete.")
print("\n\n")
#run audio narrator
print("-"* 50)
print("narrating audio...")
audio_narrator = AudioNarrator(api_key=os.getenv("ELEVENLABS_API_KEY"))
audio_narrator.narrate(post_path=post_path)
print("Audio narration complete.")
print("\n\n")
#create video
print("-"* 50)
print("creating video...")
moviemaker = MovieMaker(OVERLAY, BG_TRACK, INTRO, OUTRO)
moviemaker.create_video(post_path=post_path)
print("Video creation complete.")
print("\n\n")
#generate metadata
print("-"* 50)
print("generating metadata...")
metadata_generator = MetadataGenerator()
metadata_generator.create_metadata(post_path=post_path)
print("Metadata generation complete.")
print("\n\n")
#publish to youtube
print("-"* 50)
print("publishing to YouTube...")
youtube_publisher = YouTubePublisher(CREDS_FILE, TOKEN_FILE, SCOPES)
video_id = youtube_publisher.upload_video(post_path=post_path)
print(f"Video published with ID: {video_id}")
print("\n\n")
count += 1