Spaces:
Running
Running
| import os | |
| import gradio as gr | |
| from TTS.api import TTS | |
| print("β³ XTTS-v2 Model Download ho raha hai... Isme 10-15 min lagenge!") | |
| # Coqui TTS ki terms & conditions ko auto-accept karne ka code | |
| os.environ["COQUI_TOS_AGREED"] = "1" | |
| # π ASLI AI MODEL LOADING (Tere server ke andar) | |
| # gpu=False kiya hai kyunki free HF space par CPU hota hai | |
| tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", gpu=False) | |
| def clone_voice(script, ref_audio): | |
| if not script or not ref_audio: | |
| return None, "β οΈ Bhai, Script aur Reference Voice dono zaroori hain!" | |
| try: | |
| output_file = "voiceforge_final.wav" | |
| # Tera local AI engine ab script read karega | |
| tts.tts_to_file( | |
| text=script, | |
| file_path=output_file, | |
| speaker_wav=ref_audio, | |
| language="en" # π Isko "en" kar de! | |
| ) | |
| return output_file, "β Boom! Teri apni AI ne locally aawaz bana di!" | |
| except Exception as e: | |
| return None, f"β οΈ Error: {str(e)}" | |
| # ββ Dark Mode UI ββ | |
| with gr.Blocks(theme=gr.themes.Monochrome()) as iface: | |
| gr.Markdown("# ποΈ VoiceForge Mobile Studio") | |
| gr.Markdown("### β‘ True Local AI Clone Engine (XTTS-v2) | Dev: Naman Rai") | |
| with gr.Row(): | |
| with gr.Column(): | |
| ref_audio_input = gr.Audio(type="filepath", label="π΅ Reference Voice (5-10 sec saaf aawaz)") | |
| script_input = gr.Textbox( | |
| label="π Script Yahan Daal", | |
| lines=4, | |
| placeholder="Bhai log, aaj ke is montage mein..." | |
| ) | |
| generate_btn = gr.Button("π Generate Clone", variant="primary") | |
| with gr.Column(): | |
| audio_output = gr.Audio(label="VoiceForge Output") | |
| status_output = gr.Textbox(label="System Console") | |
| generate_btn.click( | |
| fn=clone_voice, | |
| inputs=[script_input, ref_audio_input], | |
| outputs=[audio_output, status_output], | |
| api_name="clone_voice" # π YEH LINE MISSING THI! Iske bina app nahi chalega. | |
| ) | |
| # Aur server crash se bachane ke liye queue bhi laga de: | |
| iface.queue(default_concurrency_limit=1, max_size=50).launch() | |