-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
267 lines (198 loc) · 7.74 KB
/
Copy pathapp.py
File metadata and controls
267 lines (198 loc) · 7.74 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
from dotenv import load_dotenv
import os
import json
import time
from REDDIT.GENERATE_REDDIT import create_content
from LLM.GENERATE_PODCUST import create_conversation,send_prompt,split_conversation
from AUDIO.GENERATE_AUDIO import create_audios, create_one_audio, mix_podcust_audio
from MUSIC.GENERATE_MUSIC import generate_music
from MUSIC.FIX_MUSIC import fix_music
from IMAGE.GENERATE_IMAGES import create_images_prompts, create_images
from VIDEO.GENERATE_VIDEO import generate_video
from UPLOAD.SHARE_VIDEO import share_video,split_infos, get_authenticated_service
import requests
from bs4 import BeautifulSoup
import json
def get_proxies():
# URL of the website
url = "https://free-proxy-list.net/"
# Send a GET request to the website
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(response.text, 'html.parser')
# Find the table containing the proxies
table = soup.find('table', {'class': 'table table-striped table-bordered'})
# Initialize a list to store the proxies with HTTPS support
https_proxies = []
# Iterate over each row in the table (skip the header row)
for row in table.find_all('tr')[1:]:
columns = row.find_all('td')
# Extract the relevant information
ip_address = columns[0].text
port = columns[1].text
https_support = columns[6].text
# Check if HTTPS support is "yes"
if https_support.lower() == 'yes':
proxy_url = f"http://{ip_address}:{port}"
https_proxies.append({
"http": proxy_url,
"https": proxy_url
})
# Save the proxies to a JSON file
with open('proxies.json', 'w') as f:
json.dump(https_proxies, f, indent=4)
print("Proxies saved to proxies.json")
else:
print(f"Failed to retrieve the webpage. Status code: {response.status_code}")
print("START !!!!!!!!!!!!!!!!!!!!!!!!!!")
def delete_files(file_list):
"""
Deletes a list of files.
Args:
file_list (list): A list of file paths to delete.
"""
for file_path in file_list:
try:
# Check if the file exists
if os.path.exists(file_path):
# Delete the file
os.unlink(file_path)
print(f"Deleted file: {file_path}")
else:
print(f"File does not exist: {file_path}")
except Exception as e:
print(f"Failed to delete {file_path}. Reason: {e}")
# Load environment variables from .env file
load_dotenv()
# Initialize a list to store all generated paths
generated_paths = []
# Access the variables
CLIENT_ID = os.getenv("CLIENT_ID")
CLIENT_SECRET = os.getenv("CLIENT_SECRET")
USER_AGENT = os.getenv("USER_AGENT")
# Create text from reddit
print("creating text from reddit .....")
text = create_content(CLIENT_ID,CLIENT_SECRET,USER_AGENT)
print("text from reddit created")
time.sleep(5)
# Access the variables
OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
OPENROUTER_API_URL = os.getenv("OPENROUTER_API_URL")
MODEL = os.getenv("MODEL")
conversation_prompt = open("PROMPTS/conversation_prompt.txt", "r", encoding ="UTF-8").read()
time.sleep(5)
# Create the conversation
print("creating conversation ....")
conversation_list = create_conversation(conversation_prompt,text,OPENROUTER_API_URL,OPENROUTER_API_KEY,MODEL)
#conversation = open("conversation.txt", "r", encoding ="UTF-8").read()
#conversation_list = split_conversation(conversation)
print("conversation created by llm")
print("getting proxies ....")
try:
get_proxies()
print("proxies saved !")
except:
print("proxies not saved !")
time.sleep(5)
# Access the variables
VOICE_ID_MAN = os.getenv("VOICE_ID_MAN")
VOICE_ID_WOMAN = os.getenv("VOICE_ID_WOMAN")
# Load the proxies from the JSON file
print("Loading Proxies ....")
with open("proxies.json", "r") as file:
proxies = json.load(file)
print("Proxies loaded")
print("creating podcust audios, wait for finish ....")
audios_list = create_audios(conversation_list,proxies,VOICE_ID_MAN,VOICE_ID_WOMAN)
print("podcust audios created")
time.sleep(5)
# create one audio
AUDIO_OUTPUT_FILE = os.getenv("AUDIO_OUTPUT_FILE")
print("generating one audio ...")
path_podcust_audio = create_one_audio(audios_list,AUDIO_OUTPUT_FILE)
print("one audio generated")
time.sleep(5)
# create music background
HUGGING_FACE_TOKEN = os.getenv("HUGGING_FACE_TOKEN")
MUSIC_API_URL = os.getenv("MUSIC_API_URL")
llm_music_prompt = open("PROMPTS/music_prompt.txt", "r", encoding ="UTF-8").read()
conversation = open("conversation.txt", "r", encoding ="UTF-8").read()
print("generating prompt music ...")
music_prompt = send_prompt(llm_music_prompt,conversation,OPENROUTER_API_URL,OPENROUTER_API_KEY,MODEL)
print("prompt music generated")
time.sleep(1)
print("generating music ....")
path_music = generate_music(music_prompt,
conversation,
HUGGING_FACE_TOKEN,
MUSIC_API_URL,
"podcast/background.mp3")
print("music generated")
time.sleep(5)
# fix music (adding metadata)
print("FIXING BACKGROUND ....")
path_fixed = fix_music()
print("music fixed")
time.sleep(5)
# mix music with audio
print("MIXING PODCUST ...")
path_mixed_audio = mix_podcust_audio(path_podcust_audio,path_fixed)
print("podcast mixed")
time.sleep(5)
# generate images
# Get the IMAGE_API_URLS from the .env file
image_api_urls_str = os.getenv("IMAGE_API_URLS")
IMAGE_API_URLS = image_api_urls_str.split(",")
llm_images_prompt = open("PROMPTS/images_prompt.txt", "r", encoding ="UTF-8").read()
print('generating prompts of images....')
images_prompt = send_prompt(llm_images_prompt,conversation,OPENROUTER_API_URL,OPENROUTER_API_KEY,MODEL)
print('prompts generated')
print('generating prompts list ...')
prompts_list = create_images_prompts(images_prompt)
print('prompts list generated')
time.sleep(1)
print("wait, generating images ........")
path_created_images = create_images(prompts_list,IMAGE_API_URLS,HUGGING_FACE_TOKEN)
print("images generated")
time.sleep(3)
# generate vedios
print("generating the video .....")
output_video_path = generate_video(path_mixed_audio, path_created_images)
print("video generated")
time.sleep(3)
generated_paths.append(path_podcust_audio)#
generated_paths.append(audios_list)#
generated_paths.append(path_music)#
generated_paths.append(path_fixed)#
generated_paths.append(path_mixed_audio)#
generated_paths.extend(path_created_images)#
generated_paths.append(output_video_path)#
# upload to youtube
UPLOAD_TO_YOUTUBE = os.getenv("UPLOAD_TO_YOUTUBE")
TOKEN_FILE_YOUTUBE = os.getenv("TOKEN_FILE_YOUTUBE")
share_prompt = open("PROMPTS/share_prompt.txt", "r", encoding ="UTF-8").read()
print('sharing is :', UPLOAD_TO_YOUTUBE)
if UPLOAD_TO_YOUTUBE == "ON":
print("generating infos ....")
video_infos = send_prompt(share_prompt,conversation,OPENROUTER_API_URL,OPENROUTER_API_KEY,MODEL)
title, description, tags = split_infos(video_infos)
print("title, description, tags generated")
time.sleep(1)
with open("video_infos.txt", "w", encoding ="UTF-8") as file:
content = f"""
video infos : {video_infos} .
title : {title} .
description : {description} .
tags : {tags} .
"""
file.write(content)
print("infos saved ! ")
print("uploading video")
youtube = get_authenticated_service(TOKEN_FILE_YOUTUBE)
print("youtube ready !!")
share_video(youtube, title, description, tags, output_video_path)
print('video uploaded')
# Delete all generated files
delete_files(generated_paths)