import os import torch import argparse import gradio as gr from mailersend import emails from dotenv import load_dotenv from elevenlabs.client import ElevenLabs from elevenlabs import play, save import base64 # Load environment variables load_dotenv() # Argument parsing parser = argparse.ArgumentParser() parser.add_argument("--share", action='store_true', default=False, help="make link public") args = parser.parse_args() # Initialize ElevenLabs client client = ElevenLabs(api_key=os.environ.get("ELEVENLABS_API_KEY")) device = 'cuda' if torch.cuda.is_available() else 'cpu' output_dir = 'outputs' os.makedirs(output_dir, exist_ok=True) supported_languages = ['zh', 'en'] MAILERSEND_API_KEY = os.getenv("MAILERSEND_API_KEY") MAILERSEND_DOMAIN = os.getenv("MAILERSEND_DOMAIN") MAILERSEND_SENDER_EMAIL = f"noreply@{MAILERSEND_DOMAIN}" MAILERSEND_SENDER_NAME = "Voice Clone App" # List of blocked words BLOCKED_WORDS = ['Kill','hurt','shoot','gun','rifle','AR','semi automatic','knife','blade','sword','punch harm','disrupt','blackmail','steal','bitch','cunt','fuck','freaking','nigger','nigga','niggas','cracker','jew','oriental','fag','faggot','account','money','transfer','urgent','help','scared','policy','frightened','accident','fear','scam','address','social security number','assault','injure','maim','destroy','damage','threaten','intimidate','bully','menace','blackmail','extort','exploit','defame','steal','rob','embezzle','defraud Harass','jerk','idiot','stupid','moron','asshole','con','trick','swindle','defraud','payment','credit card','bank account','urgent','immediate','afraid','phone number','email','password'] # Function to check for blocked words def contains_blocked_words(text): return any(word.lower() in text.lower() for word in BLOCKED_WORDS) # Function to send email with downloadable file using MailerSend def send_email_with_file(recipient_email, file_path, subject, body): # ... (rest of the function remains the same) # Predict function def predict(prompt, style, audio_file_pth, voice_name, customer_email): text_hint = 'Your file will only be saved for 24 hours.\n' if len(prompt) < 2: text_hint += "[ERROR] Please provide a longer prompt text.\n" return text_hint, None, None if len(prompt) > 200: text_hint += "[ERROR] Text length limited to 200 characters. Please try shorter text.\n" return text_hint, None, None if contains_blocked_words(prompt): text_hint += "[ERROR] Your text contains blocked words. Please remove them and try again.\n" return text_hint, None, None full_voice_name = f"{voice_name} - {customer_email}" print(audio_file_pth) voice = client.clone( name=full_voice_name, description="A trial voice model for testing", files=[audio_file_pth], ) audio = client.generate(text=prompt, voice=voice) save_path = f'{output_dir}/output.wav' save(audio, save_path) subject = "Your Voice Clone File" body = "Thank you for using our Voice Clone service. Your file is attached." if send_email_with_file(customer_email, save_path, subject, body): text_hint += "Email sent successfully with the voice file.\n" else: text_hint += "Failed to send email with the voice file. Please try again later.\n" return text_hint, save_path, audio_file_pth # Gradio interface setup with gr.Blocks(gr.themes.Glass()) as demo: # ... (rest of the code remains the same) css = """ footer {visibility: hidden} audio .btn-container {display: none} """ demo.add_css(css)