Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,92 +1,92 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
-
import numpy as np
|
| 4 |
-
from scipy.io.wavfile import write as write_wav
|
| 5 |
-
|
| 6 |
-
# --- Configuration (same as before) ---
|
| 7 |
-
# 1. List the names of your TTS models
|
| 8 |
-
MODELS = ['sarvam', 'smallest', '
|
| 9 |
-
|
| 10 |
-
# 2. List the text prompts that correspond to your numbered audio files
|
| 11 |
-
TEXTS = [
|
| 12 |
-
"संविधान की प्रस्तावना में निहित मूल्यों का परिपालन प्रत्येक नागरिक का कर्तव्य है।",
|
| 13 |
-
"प्राकृतिक आपदाओं के निराकरण हेतु समुचित रणनीति आवश्यक है।",
|
| 14 |
-
"उसके अभिव्यक्तिपरक लेखन मे
|
| 15 |
-
"किसी भी राष्ट्र की उन्नति उसके नागरिकों की कर्मठता पर निर्भर करती है।"
|
| 16 |
-
]
|
| 17 |
-
|
| 18 |
-
# 3. Set the path to your audio directory
|
| 19 |
-
AUDIO_DIR = "audio_files"
|
| 20 |
-
|
| 21 |
-
# --- Helper Function to Create Dummy Audio (same as before) ---
|
| 22 |
-
def create_dummy_files_if_needed():
|
| 23 |
-
"""Checks for audio files and creates silent placeholders if they don't exist."""
|
| 24 |
-
print("Checking for audio files...")
|
| 25 |
-
os.makedirs(AUDIO_DIR, exist_ok=True)
|
| 26 |
-
files_created = False
|
| 27 |
-
|
| 28 |
-
for model in MODELS:
|
| 29 |
-
for i in range(len(TEXTS)):
|
| 30 |
-
file_path = os.path.join(AUDIO_DIR, f"{model}-{i+1}.wav")
|
| 31 |
-
if not os.path.exists(file_path):
|
| 32 |
-
if not files_created:
|
| 33 |
-
print(f"Warning: Audio file not found. Creating a dummy silent file at '{file_path}'.")
|
| 34 |
-
print("Replace these dummy files with your actual audio samples.")
|
| 35 |
-
files_created = True
|
| 36 |
-
|
| 37 |
-
samplerate = 22050
|
| 38 |
-
data = np.zeros(samplerate * 1) # 1 second of silence
|
| 39 |
-
write_wav(file_path, samplerate, data.astype(np.int16))
|
| 40 |
-
|
| 41 |
-
if not files_created:
|
| 42 |
-
print("All audio files found successfully!")
|
| 43 |
-
|
| 44 |
-
# --- Build the Gradio Interface (New and Improved) ---
|
| 45 |
-
def build_app():
|
| 46 |
-
# First, ensure all audio files (or dummies) exist.
|
| 47 |
-
create_dummy_files_if_needed()
|
| 48 |
-
|
| 49 |
-
with gr.Blocks(theme=gr.themes.Soft(), title="TTS Comparison") as demo:
|
| 50 |
-
gr.Markdown(
|
| 51 |
-
"""
|
| 52 |
-
# TTS Model Audio Comparison
|
| 53 |
-
Listen to audio samples generated by different models for the same text.
|
| 54 |
-
"""
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
# --- Create the Header Row ---
|
| 58 |
-
with gr.Row():
|
| 59 |
-
# Add an empty placeholder for the "Text Prompt" column header for alignment
|
| 60 |
-
gr.Markdown("### Text Prompt")
|
| 61 |
-
# Create a header for each model
|
| 62 |
-
for model in MODELS:
|
| 63 |
-
gr.Markdown(f"### {model.capitalize()}")
|
| 64 |
-
|
| 65 |
-
# --- Create a Row for Each Text Prompt ---
|
| 66 |
-
# Enumerate through the texts to get both an index (i) and the text content
|
| 67 |
-
for i, text in enumerate(TEXTS):
|
| 68 |
-
with gr.Row(variant="panel"):
|
| 69 |
-
# Column 1: The text prompt
|
| 70 |
-
gr.Textbox(
|
| 71 |
-
value=text,
|
| 72 |
-
label="Text Prompt",
|
| 73 |
-
interactive=False,
|
| 74 |
-
lines=3,
|
| 75 |
-
show_label=False # The header row already provides context
|
| 76 |
-
)
|
| 77 |
-
|
| 78 |
-
# Subsequent Columns: The audio players for each model
|
| 79 |
-
for model in MODELS:
|
| 80 |
-
# Construct the correct audio file path for this row and column
|
| 81 |
-
audio_path = os.path.join(AUDIO_DIR, f"{model}-{i+1}.wav")
|
| 82 |
-
gr.Audio(
|
| 83 |
-
value=audio_path,
|
| 84 |
-
label=model.capitalize(), # Label is good for accessibility
|
| 85 |
-
show_label=False # Hide label for a cleaner look
|
| 86 |
-
)
|
| 87 |
-
|
| 88 |
-
return demo
|
| 89 |
-
|
| 90 |
-
if __name__ == "__main__":
|
| 91 |
-
app = build_app()
|
| 92 |
app.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
from scipy.io.wavfile import write as write_wav
|
| 5 |
+
|
| 6 |
+
# --- Configuration (same as before) ---
|
| 7 |
+
# 1. List the names of your TTS models
|
| 8 |
+
MODELS = ['sarvam', 'smallest', 'IndicVox', 'veena']
|
| 9 |
+
|
| 10 |
+
# 2. List the text prompts that correspond to your numbered audio files
|
| 11 |
+
TEXTS = [
|
| 12 |
+
"संविधान की प्रस्तावना में निहित मूल्यों का परिपालन प्रत्येक नागरिक का कर्तव्य है।",
|
| 13 |
+
"प्राकृतिक आपदाओं के निराकरण हेतु समुचित रणनीति आवश्यक है।",
|
| 14 |
+
"उसके अभिव्यक्तिपरक लेखन मे��� गूढ़ दर्शन और जीवन के गहन सत्य परिलक्षित होते हैं।",
|
| 15 |
+
"किसी भी राष्ट्र की उन्नति उसके नागरिकों की कर्मठता पर निर्भर करती है।"
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
# 3. Set the path to your audio directory
|
| 19 |
+
AUDIO_DIR = "audio_files"
|
| 20 |
+
|
| 21 |
+
# --- Helper Function to Create Dummy Audio (same as before) ---
|
| 22 |
+
def create_dummy_files_if_needed():
|
| 23 |
+
"""Checks for audio files and creates silent placeholders if they don't exist."""
|
| 24 |
+
print("Checking for audio files...")
|
| 25 |
+
os.makedirs(AUDIO_DIR, exist_ok=True)
|
| 26 |
+
files_created = False
|
| 27 |
+
|
| 28 |
+
for model in MODELS:
|
| 29 |
+
for i in range(len(TEXTS)):
|
| 30 |
+
file_path = os.path.join(AUDIO_DIR, f"{model}-{i+1}.wav")
|
| 31 |
+
if not os.path.exists(file_path):
|
| 32 |
+
if not files_created:
|
| 33 |
+
print(f"Warning: Audio file not found. Creating a dummy silent file at '{file_path}'.")
|
| 34 |
+
print("Replace these dummy files with your actual audio samples.")
|
| 35 |
+
files_created = True
|
| 36 |
+
|
| 37 |
+
samplerate = 22050
|
| 38 |
+
data = np.zeros(samplerate * 1) # 1 second of silence
|
| 39 |
+
write_wav(file_path, samplerate, data.astype(np.int16))
|
| 40 |
+
|
| 41 |
+
if not files_created:
|
| 42 |
+
print("All audio files found successfully!")
|
| 43 |
+
|
| 44 |
+
# --- Build the Gradio Interface (New and Improved) ---
|
| 45 |
+
def build_app():
|
| 46 |
+
# First, ensure all audio files (or dummies) exist.
|
| 47 |
+
create_dummy_files_if_needed()
|
| 48 |
+
|
| 49 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="TTS Comparison") as demo:
|
| 50 |
+
gr.Markdown(
|
| 51 |
+
"""
|
| 52 |
+
# TTS Model Audio Comparison
|
| 53 |
+
Listen to audio samples generated by different models for the same text.
|
| 54 |
+
"""
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# --- Create the Header Row ---
|
| 58 |
+
with gr.Row():
|
| 59 |
+
# Add an empty placeholder for the "Text Prompt" column header for alignment
|
| 60 |
+
gr.Markdown("### Text Prompt")
|
| 61 |
+
# Create a header for each model
|
| 62 |
+
for model in MODELS:
|
| 63 |
+
gr.Markdown(f"### {model.capitalize()}")
|
| 64 |
+
|
| 65 |
+
# --- Create a Row for Each Text Prompt ---
|
| 66 |
+
# Enumerate through the texts to get both an index (i) and the text content
|
| 67 |
+
for i, text in enumerate(TEXTS):
|
| 68 |
+
with gr.Row(variant="panel"):
|
| 69 |
+
# Column 1: The text prompt
|
| 70 |
+
gr.Textbox(
|
| 71 |
+
value=text,
|
| 72 |
+
label="Text Prompt",
|
| 73 |
+
interactive=False,
|
| 74 |
+
lines=3,
|
| 75 |
+
show_label=False # The header row already provides context
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
# Subsequent Columns: The audio players for each model
|
| 79 |
+
for model in MODELS:
|
| 80 |
+
# Construct the correct audio file path for this row and column
|
| 81 |
+
audio_path = os.path.join(AUDIO_DIR, f"{model}-{i+1}.wav")
|
| 82 |
+
gr.Audio(
|
| 83 |
+
value=audio_path,
|
| 84 |
+
label=model.capitalize(), # Label is good for accessibility
|
| 85 |
+
show_label=False # Hide label for a cleaner look
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
return demo
|
| 89 |
+
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
app = build_app()
|
| 92 |
app.launch()
|