Skip to content

Commit 739b44a

Browse files
committed
Rollback
1 parent 67ea99a commit 739b44a

File tree

6 files changed

+169
-49
lines changed

6 files changed

+169
-49
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ Songs/
66
google-maps-scraper-0.9.7/
77
niche.txt
88
*.exe
9-
auto.sh
9+
auto.sh
10+
.DS_Store

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.9.7
1+
3.9

src/classes/Tts.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import os
2+
import sys
3+
import site
24

35
from config import ROOT_DIR
46
from TTS.utils.manage import ModelManager
@@ -15,16 +17,26 @@ def __init__(self) -> None:
1517
Returns:
1618
None
1719
"""
18-
venv_site_packages = "venv\\Lib\\site-packages"
20+
# Detect virtual environment site packages
21+
if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
22+
# We're in a virtual environment
23+
site_packages = site.getsitepackages()[0]
24+
else:
25+
# We're not in a virtual environment, use the user's site packages
26+
site_packages = site.getusersitepackages()
1927

2028
# Path to the .models.json file
2129
models_json_path = os.path.join(
22-
ROOT_DIR,
23-
venv_site_packages,
30+
site_packages,
2431
"TTS",
2532
".models.json",
2633
)
2734

35+
# Create directory if it doesn't exist
36+
tts_dir = os.path.dirname(models_json_path)
37+
if not os.path.exists(tts_dir):
38+
os.makedirs(tts_dir)
39+
2840
# Initialize the ModelManager
2941
self._model_manager = ModelManager(models_json_path)
3042

@@ -72,4 +84,4 @@ def synthesize(self, text: str, output_file: str = os.path.join(ROOT_DIR, ".mp",
7284
self.synthesizer.save_wav(outputs, output_file)
7385

7486
return output_file
75-
87+

src/classes/YouTube.py

Lines changed: 126 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ def __init__(self, account_uuid: str, account_nickname: str, fp_profile_path: st
7272
if get_headless():
7373
self.options.add_argument("--headless")
7474

75-
# Set the profile path
76-
self.options.add_argument("-profile")
77-
self.options.add_argument(fp_profile_path)
75+
profile = webdriver.FirefoxProfile(self._fp_profile_path)
76+
self.options.profile = profile
7877

7978
# Set the service
8079
self.service: Service = Service(GeckoDriverManager().install())
@@ -226,7 +225,22 @@ def generate_prompts(self) -> List[str]:
226225
Returns:
227226
image_prompts (List[str]): Generated List of image prompts.
228227
"""
229-
n_prompts = len(self.script) / 3
228+
# Check if using G4F for image generation
229+
cached_accounts = get_accounts("youtube")
230+
account_config = None
231+
for account in cached_accounts:
232+
if account["id"] == self._account_uuid:
233+
account_config = account
234+
break
235+
236+
# Calculate number of prompts based on script length
237+
base_n_prompts = len(self.script) / 3
238+
239+
# If using G4F, limit to 25 prompts
240+
if account_config and account_config.get("use_g4f", False):
241+
n_prompts = min(base_n_prompts, 25)
242+
else:
243+
n_prompts = base_n_prompts
230244

231245
prompt = f"""
232246
Generate {n_prompts} Image Prompts for AI Image Generation,
@@ -279,60 +293,135 @@ def generate_prompts(self) -> List[str]:
279293
warning("Failed to generate Image Prompts. Retrying...")
280294
return self.generate_prompts()
281295

282-
self.image_prompts = image_prompts
296+
# Limit prompts to max allowed amount
297+
if account_config and account_config.get("use_g4f", False):
298+
image_prompts = image_prompts[:25]
299+
elif len(image_prompts) > n_prompts:
300+
image_prompts = image_prompts[:int(n_prompts)]
283301

284-
# Check the amount of image prompts
285-
# and remove if it's more than needed
286-
if len(image_prompts) > n_prompts:
287-
image_prompts = image_prompts[:n_prompts]
302+
self.image_prompts = image_prompts
288303

289304
success(f"Generated {len(image_prompts)} Image Prompts.")
290305

291306
return image_prompts
292307

293-
def generate_image(self, prompt: str) -> str:
308+
def generate_image_g4f(self, prompt: str) -> str:
294309
"""
295-
Generates an AI Image based on the given prompt.
310+
Generates an AI Image using G4F with SDXL Turbo.
296311
297312
Args:
298313
prompt (str): Reference for image generation
299314
300315
Returns:
301316
path (str): The path to the generated image.
302317
"""
303-
ok = False
304-
while ok == False:
305-
url = f"https://hercai.onrender.com/{get_image_model()}/text2image?prompt={prompt}"
318+
print(f"Generating Image using G4F: {prompt}")
319+
320+
try:
321+
from g4f.client import Client
322+
323+
client = Client()
324+
response = client.images.generate(
325+
model="sdxl-turbo",
326+
prompt=prompt,
327+
response_format="url"
328+
)
329+
330+
if response and response.data and len(response.data) > 0:
331+
# Download image from URL
332+
image_url = response.data[0].url
333+
image_response = requests.get(image_url)
334+
335+
if image_response.status_code == 200:
336+
image_path = os.path.join(ROOT_DIR, ".mp", str(uuid4()) + ".png")
337+
338+
with open(image_path, "wb") as image_file:
339+
image_file.write(image_response.content)
340+
341+
if get_verbose():
342+
info(f" => Downloaded Image from {image_url} to \"{image_path}\"\n")
343+
344+
self.images.append(image_path)
345+
return image_path
346+
else:
347+
if get_verbose():
348+
warning(f"Failed to download image from URL: {image_url}")
349+
return None
350+
else:
351+
if get_verbose():
352+
warning("Failed to generate image using G4F - no data in response")
353+
return None
354+
355+
except Exception as e:
356+
if get_verbose():
357+
warning(f"Failed to generate image using G4F: {str(e)}")
358+
return None
306359

307-
r = requests.get(url)
308-
parsed = r.json()
360+
def generate_image_cloudflare(self, prompt: str, worker_url: str) -> str:
361+
"""
362+
Generates an AI Image using Cloudflare worker.
309363
310-
if "url" not in parsed or not parsed.get("url"):
311-
# Retry
312-
if get_verbose():
313-
info(f" => Failed to generate Image for Prompt: {prompt}. Retrying...")
314-
ok = False
315-
else:
316-
ok = True
317-
image_url = parsed["url"]
364+
Args:
365+
prompt (str): Reference for image generation
366+
worker_url (str): The Cloudflare worker URL
318367
319-
if get_verbose():
320-
info(f" => Generated Image: {image_url}")
368+
Returns:
369+
path (str): The path to the generated image.
370+
"""
371+
print(f"Generating Image using Cloudflare: {prompt}")
321372

322-
image_path = os.path.join(ROOT_DIR, ".mp", str(uuid4()) + ".png")
323-
324-
with open(image_path, "wb") as image_file:
325-
# Write bytes to file
326-
image_r = requests.get(image_url)
373+
url = f"{worker_url}?prompt={prompt}&model=sdxl"
374+
375+
response = requests.get(url)
376+
377+
if response.headers.get('content-type') == 'image/png':
378+
image_path = os.path.join(ROOT_DIR, ".mp", str(uuid4()) + ".png")
379+
380+
with open(image_path, "wb") as image_file:
381+
image_file.write(response.content)
382+
383+
if get_verbose():
384+
info(f" => Wrote Image to \"{image_path}\"\n")
385+
386+
self.images.append(image_path)
387+
388+
return image_path
389+
else:
390+
if get_verbose():
391+
warning("Failed to generate image. The response was not a PNG image.")
392+
return None
327393

328-
image_file.write(image_r.content)
394+
def generate_image(self, prompt: str) -> str:
395+
"""
396+
Generates an AI Image based on the given prompt.
329397
330-
if get_verbose():
331-
info(f" => Wrote Image to \"{image_path}\"\n")
398+
Args:
399+
prompt (str): Reference for image generation
332400
333-
self.images.append(image_path)
334-
335-
return image_path
401+
Returns:
402+
path (str): The path to the generated image.
403+
"""
404+
# Get account config from cache
405+
cached_accounts = get_accounts("youtube")
406+
account_config = None
407+
for account in cached_accounts:
408+
if account["id"] == self._account_uuid:
409+
account_config = account
410+
break
411+
412+
if not account_config:
413+
error("Account configuration not found")
414+
return None
415+
416+
# Check if using G4F or Cloudflare
417+
if account_config.get("use_g4f", False):
418+
return self.generate_image_g4f(prompt)
419+
else:
420+
worker_url = account_config.get("worker_url")
421+
if not worker_url:
422+
error("Cloudflare worker URL not configured for this account")
423+
return None
424+
return self.generate_image_cloudflare(prompt, worker_url)
336425

337426
def generate_script_to_speech(self, tts_instance: TTS) -> str:
338427
"""

src/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def parse_model(model_name: str) -> any:
5858
if model_name == "gpt4":
5959
return g4f.models.gpt_4
6060
elif model_name == "gpt35_turbo":
61-
return g4f.models.gpt_35_turbo
61+
return g4f.models.gpt_4o_mini
6262
elif model_name == "llama2_7b":
6363
return g4f.models.llama2_7b
6464
elif model_name == "llama2_13b":
@@ -69,4 +69,4 @@ def parse_model(model_name: str) -> any:
6969
return g4f.models.mixtral_8x7b
7070
else:
7171
# Default model is gpt3.5-turbo
72-
return g4f.models.gpt_35_turbo
72+
return g4f.models.gpt_4o_mini

src/main.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,34 @@ def main():
5959
fp_profile = question(" => Enter the path to the Firefox profile: ")
6060
niche = question(" => Enter the account niche: ")
6161
language = question(" => Enter the account language: ")
62-
63-
add_account("youtube", {
62+
63+
# Add image generation options
64+
info("\n============ IMAGE GENERATION ============", False)
65+
print(colored(" 1. G4F (SDXL Turbo)", "cyan"))
66+
print(colored(" 2. Cloudflare Worker", "cyan"))
67+
info("=======================================", False)
68+
print(colored("\nRecommendation: If you're unsure, select G4F (Option 1) as there's no additional setup", "yellow"))
69+
info("=======================================\n", False)
70+
71+
image_gen_choice = question(" => Select image generation method (1/2): ")
72+
73+
account_data = {
6474
"id": generated_uuid,
6575
"nickname": nickname,
6676
"firefox_profile": fp_profile,
6777
"niche": niche,
6878
"language": language,
79+
"use_g4f": image_gen_choice == "1",
6980
"videos": []
70-
})
81+
}
82+
83+
if image_gen_choice == "2":
84+
worker_url = question(" => Enter your Cloudflare worker URL for image generation: ")
85+
account_data["worker_url"] = worker_url
86+
87+
add_account("youtube", account_data)
88+
89+
success("Account configured successfully!")
7190
else:
7291
table = PrettyTable()
7392
table.field_names = ["ID", "UUID", "Nickname", "Niche"]
@@ -274,7 +293,6 @@ def job():
274293
success("Set up CRON Job.")
275294
else:
276295
break
277-
278296
elif user_input == 4:
279297
if get_verbose():
280298
info(" => Climbing Options Ladder...", False)

0 commit comments

Comments
 (0)