Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,49 +1,47 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from
|
| 4 |
-
import noisereduce as nr
|
| 5 |
import soundfile as sf
|
|
|
|
|
|
|
| 6 |
import gc
|
| 7 |
|
| 8 |
-
#
|
| 9 |
gc.collect()
|
| 10 |
-
os.environ['COQUI_TOS_AGREED'] = '1'
|
| 11 |
|
| 12 |
-
print("⏳ Loading
|
| 13 |
-
# Sabse stable cloning engine jo HF free tier par nahi rukta
|
| 14 |
-
tts = TTS("tts_models/multilingual/multi-dataset/your_tts")
|
| 15 |
-
print("✅ Engine Ready & Running!")
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
output_file = "output_voice.wav"
|
| 29 |
-
|
| 30 |
|
| 31 |
return output_file, "✅ API Status: Success"
|
| 32 |
except Exception as e:
|
| 33 |
return None, f"⚠️ Engine Error: {str(e)}"
|
| 34 |
|
| 35 |
-
# Ekdum clean UI (
|
| 36 |
iface = gr.Interface(
|
| 37 |
fn=generate_api_voice,
|
| 38 |
-
inputs=[
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
],
|
| 42 |
-
outputs=[
|
| 43 |
-
gr.Audio(label="VoiceForge Output"),
|
| 44 |
-
gr.Textbox(label="Status")
|
| 45 |
-
],
|
| 46 |
-
title="🎙️ VoiceForge AI Studio"
|
| 47 |
)
|
| 48 |
|
| 49 |
iface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
import soundfile as sf
|
| 4 |
+
import torch
|
| 5 |
+
from datasets import load_dataset
|
| 6 |
import gc
|
| 7 |
|
| 8 |
+
# System ki purani memory saaf karna
|
| 9 |
gc.collect()
|
|
|
|
| 10 |
|
| 11 |
+
print("⏳ WARNING: Loading the BIGGEST Engine... Server crash hone ke chances hain!")
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
try:
|
| 14 |
+
# Heavy Text-to-Speech pipeline load kar rahe hain
|
| 15 |
+
synthesizer = pipeline("text-to-speech", "microsoft/speecht5_tts")
|
| 16 |
|
| 17 |
+
# High-quality speaker embedding
|
| 18 |
+
embeddings_dataset = load_dataset("Matthijs/cmu_arctic_xvectors", split="validation")
|
| 19 |
+
speaker_embedding = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
| 20 |
+
print("✅ Engine load ho gaya! (Ye ek miracle hai)")
|
| 21 |
+
except Exception as e:
|
| 22 |
+
print(f"❌ Server Crashed: {e}")
|
| 23 |
|
| 24 |
+
def generate_api_voice(text):
|
| 25 |
+
if not text:
|
| 26 |
+
return None, "Error: Script likhna zaruri hai!"
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
# Aawaz generate karne ka heavy process
|
| 30 |
+
speech = synthesizer(text, forward_params={"speaker_embeddings": speaker_embedding})
|
| 31 |
+
|
| 32 |
output_file = "output_voice.wav"
|
| 33 |
+
sf.write(output_file, speech["audio"], samplerate=speech["sampling_rate"])
|
| 34 |
|
| 35 |
return output_file, "✅ API Status: Success"
|
| 36 |
except Exception as e:
|
| 37 |
return None, f"⚠️ Engine Error: {str(e)}"
|
| 38 |
|
| 39 |
+
# Ekdum clean UI (No extra clutter)
|
| 40 |
iface = gr.Interface(
|
| 41 |
fn=generate_api_voice,
|
| 42 |
+
inputs=[gr.Textbox(label="Apni Script Yahan Likho")],
|
| 43 |
+
outputs=[gr.Audio(label="VoiceForge Output"), gr.Textbox(label="Status")],
|
| 44 |
+
title="🎙️ VoiceForge AI Studio - Heavy Engine Test"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
iface.launch()
|