UpCoder commited on
Commit
1a229ab
·
verified ·
1 Parent(s): e5b716a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from TTS.utils.synthesizer import Synthesizer
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ # 1. Grab the secret key you hid in the settings
7
+ hf_token = os.environ.get("HF_TOKEN")
8
+
9
+ # 2. Quietly download the brain from your private vault
10
+ repo_id = "UpCoder/behruz-vits-v3-private"
11
+
12
+ try:
13
+ print("Downloading model files...")
14
+ model_path = hf_hub_download(repo_id=repo_id, filename="checkpoint_43000.pth", token=hf_token)
15
+ config_path = hf_hub_download(repo_id=repo_id, filename="config.json", token=hf_token)
16
+ except Exception as e:
17
+ print(f"Error downloading files: {e}")
18
+
19
+ # 3. Load the AI (We set use_cuda=False because the free cloud tier doesn't have a GPU!)
20
+ print("Loading AI Model...")
21
+ synthesizer = Synthesizer(
22
+ tts_checkpoint=model_path,
23
+ tts_config_path=config_path,
24
+ use_cuda=False
25
+ )
26
+
27
+ # 4. The function that generates the audio
28
+ def synthesize_voice(text):
29
+ wav = synthesizer.tts(text)
30
+ output_file = "output.wav"
31
+ synthesizer.save_wav(wav, output_file)
32
+ return output_file
33
+
34
+ # 5. Build the beautiful User Interface
35
+ iface = gr.Interface(
36
+ fn=synthesize_voice,
37
+ inputs=gr.Textbox(label="Enter Uzbek Text Here", lines=3, placeholder="Salom, bu mening raqamli ovozim..."),
38
+ outputs=gr.Audio(label="Generated Audio"),
39
+ title="🎙️ Behruz's Digital Voice Clone",
40
+ description="Type any Uzbek sentence below to hear it spoken by an AI trained on my real voice! (Note: Generation takes a few seconds on the free tier).",
41
+ theme="huggingface"
42
+ )
43
+
44
+ iface.launch()