Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,60 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
df = pd.read_csv(csv_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
|
| 15 |
-
return
|
| 16 |
|
| 17 |
-
# Extract
|
| 18 |
-
|
| 19 |
|
| 20 |
-
# Dictionary to store selected
|
| 21 |
-
selected_voices = {
|
| 22 |
|
| 23 |
# Function to update the dictionary and display the result
|
| 24 |
def update_voice(*args):
|
| 25 |
-
for
|
| 26 |
-
selected_voices[
|
| 27 |
|
| 28 |
# Create a result string to display
|
| 29 |
-
result = "\n".join([f"For {
|
| 30 |
return result
|
| 31 |
|
| 32 |
# Creating Gradio interface
|
| 33 |
def create_interface():
|
| 34 |
inputs = []
|
| 35 |
-
for
|
| 36 |
-
# Create a dropdown for each
|
| 37 |
-
dropdown = gr.Dropdown(choices=
|
| 38 |
inputs.append(dropdown)
|
| 39 |
|
| 40 |
interface = gr.Interface(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
+
import os
|
| 4 |
+
import random
|
| 5 |
|
| 6 |
+
# Path to voice actors folder
|
| 7 |
+
voice_actors_folder = "tortoise/voices/"
|
| 8 |
|
| 9 |
+
# Get the list of voice actors
|
| 10 |
+
voice_actors = [va for va in os.listdir(voice_actors_folder) if va != "cond_latent_example" and va != ".DS_Store"]
|
| 11 |
+
male_voice_actors = [va for va in voice_actors if va.endswith(".M")]
|
| 12 |
+
female_voice_actors = [va for va in voice_actors if va.endswith(".F")]
|
| 13 |
+
|
| 14 |
+
# Function to extract unique speakers from CSV
|
| 15 |
+
def extract_unique_speakers(csv_file):
|
| 16 |
df = pd.read_csv(csv_file)
|
| 17 |
+
# Extract unique speakers from "Speaker" column
|
| 18 |
+
unique_speakers = df["Speaker"].unique().tolist()
|
| 19 |
+
return unique_speakers
|
| 20 |
+
|
| 21 |
+
# Function to get a random default voice actor for each speaker
|
| 22 |
+
def get_random_voice_for_speaker_fast(speaker):
|
| 23 |
+
selected_voice_actors = voice_actors # default to all voice actors
|
| 24 |
+
|
| 25 |
+
if speaker.endswith(".M") and male_voice_actors:
|
| 26 |
+
selected_voice_actors = male_voice_actors
|
| 27 |
+
elif speaker.endswith(".F") and female_voice_actors:
|
| 28 |
+
selected_voice_actors = female_voice_actors
|
| 29 |
+
elif speaker.endswith(".?"):
|
| 30 |
+
selected_voice_actors = male_voice_actors + female_voice_actors
|
| 31 |
|
| 32 |
+
if not selected_voice_actors: # If list is empty, default to all voice actors
|
| 33 |
+
selected_voice_actors = male_voice_actors + female_voice_actors
|
| 34 |
|
| 35 |
+
return random.choice(selected_voice_actors)
|
| 36 |
|
| 37 |
+
# Extract speakers from the CSV file
|
| 38 |
+
speakers = extract_unique_speakers("book.csv")
|
| 39 |
|
| 40 |
+
# Dictionary to store selected voice actors for each speaker
|
| 41 |
+
selected_voices = {speaker: get_random_voice_for_speaker_fast(speaker) for speaker in speakers}
|
| 42 |
|
| 43 |
# Function to update the dictionary and display the result
|
| 44 |
def update_voice(*args):
|
| 45 |
+
for speaker, selected_voice in zip(speakers, args):
|
| 46 |
+
selected_voices[speaker] = selected_voice
|
| 47 |
|
| 48 |
# Create a result string to display
|
| 49 |
+
result = "\n".join([f"For {speaker}: selected voice actor {voice}" for speaker, voice in selected_voices.items()])
|
| 50 |
return result
|
| 51 |
|
| 52 |
# Creating Gradio interface
|
| 53 |
def create_interface():
|
| 54 |
inputs = []
|
| 55 |
+
for speaker in speakers:
|
| 56 |
+
# Create a dropdown for each speaker with the list of all voice actors
|
| 57 |
+
dropdown = gr.Dropdown(choices=voice_actors, label=f"Select voice actor for {speaker}", value=selected_voices[speaker])
|
| 58 |
inputs.append(dropdown)
|
| 59 |
|
| 60 |
interface = gr.Interface(
|