drewThomasson commited on
Commit
a695b96
·
verified ·
1 Parent(s): b224b45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -18
app.py CHANGED
@@ -1,40 +1,60 @@
1
  import gradio as gr
2
  import pandas as pd
 
 
3
 
4
- # Predefined list of voices
5
- voices = ["Voice1", "Voice2", "Voice3"]
6
 
7
- # Function to extract unique names from CSV
8
- def extract_unique_names(csv_file):
9
- # Read the CSV
 
 
 
 
10
  df = pd.read_csv(csv_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- # Extract unique names from "Speaker" column
13
- unique_names = df["Speaker"].unique().tolist()
14
 
15
- return unique_names
16
 
17
- # Extract names from the CSV file
18
- names = extract_unique_names("book.csv")
19
 
20
- # Dictionary to store selected voices
21
- selected_voices = {name: None for name in names}
22
 
23
  # Function to update the dictionary and display the result
24
  def update_voice(*args):
25
- for name, selected_voice in zip(names, args):
26
- selected_voices[name] = selected_voice
27
 
28
  # Create a result string to display
29
- result = "\n".join([f"For {name}: selected voice {voice}" for name, voice in selected_voices.items()])
30
  return result
31
 
32
  # Creating Gradio interface
33
  def create_interface():
34
  inputs = []
35
- for name in names:
36
- # Create a dropdown for each name with the predefined voices
37
- dropdown = gr.Dropdown(choices=voices, label=f"Select voice for {name}")
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(