Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import VitsModel, AutoTokenizer
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Load the fine-tuned model and tokenizer
|
| 6 |
+
model = VitsModel.from_pretrained("HusseinBashir/fine_tuned_vits_som")
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("HusseinBashir/fine_tuned_vits_som")
|
| 8 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 9 |
+
model.to(device)
|
| 10 |
+
|
| 11 |
+
# Gradio TTS function
|
| 12 |
+
def tts(text):
|
| 13 |
+
inputs = tokenizer(text, return_tensors="pt").to(device)
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
output = model(**inputs).waveform.squeeze(1).cpu().numpy()
|
| 16 |
+
return output
|
| 17 |
+
|
| 18 |
+
# Gradio interface for the TTS model
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
fn=tts,
|
| 21 |
+
inputs=gr.Textbox(label="Enter text"),
|
| 22 |
+
outputs=gr.Audio(label="Generated Speech"),
|
| 23 |
+
title="Fine-tuned VITS TTS",
|
| 24 |
+
description="Generate speech from text using the fine-tuned VITS model."
|
| 25 |
+
)
|
| 26 |
+
iface.launch()
|