eBlessings commited on
Commit
a01bbfd
·
verified ·
1 Parent(s): a81c117

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -111,6 +111,7 @@ class AudiobookGenerator:
111
  voice_bank = VoiceBank()
112
  audiobook_gen = AudiobookGenerator(voice_bank)
113
 
 
114
  with gr.Blocks() as app_audiobook:
115
  gr.Markdown("# Audiobook Generator")
116
 
@@ -118,12 +119,12 @@ with gr.Blocks() as app_audiobook:
118
  txt_input = gr.File(label="Upload Text File", file_types=[".txt"])
119
  analyze_btn = gr.Button("Analyze Text", variant="secondary")
120
 
121
- speaker_components = []
122
  with gr.Column(visible=False) as speaker_ui:
123
- gr.Markdown("## Assign Voices")
124
  speaker_container = gr.Row()
125
- generate_btn = gr.Button("Generate Audiobook", variant="primary")
126
 
 
127
  audio_output = gr.Audio(label="Generated Audiobook", autoplay=True)
128
 
129
  def analyze_text(file):
@@ -132,31 +133,30 @@ with gr.Blocks() as app_audiobook:
132
 
133
  parser = DialogueParser()
134
  dialogues = parser.parse(text)
135
- speakers = list({d["speaker"] for d in dialogues})
136
 
137
  components = []
138
  for speaker in speakers:
139
- with gr.Column() as col:
140
- components.append(gr.Audio(label=f"Voice for {speaker}", type="filepath"))
141
 
142
  return [
143
- gr.update(visible=True),
144
- components,
145
- speakers
 
146
  ]
147
 
148
  analyze_btn.click(
149
  analyze_text,
150
  inputs=txt_input,
151
- outputs=[speaker_ui, speaker_container, speaker_components]
152
  )
153
 
154
  generate_btn.click(
155
- audiobook_gen.generate_audiobook,
156
  inputs=txt_input,
157
  outputs=audio_output
158
  )
159
-
160
  # ========== APP LAUNCH ========== #
161
  with gr.Blocks() as app:
162
  gr.TabbedInterface(
 
111
  voice_bank = VoiceBank()
112
  audiobook_gen = AudiobookGenerator(voice_bank)
113
 
114
+ # ========== CORRECTED GRADIO UI SECTION ========== #
115
  with gr.Blocks() as app_audiobook:
116
  gr.Markdown("# Audiobook Generator")
117
 
 
119
  txt_input = gr.File(label="Upload Text File", file_types=[".txt"])
120
  analyze_btn = gr.Button("Analyze Text", variant="secondary")
121
 
122
+ detected_speakers = gr.State()
123
  with gr.Column(visible=False) as speaker_ui:
124
+ gr.Markdown("## Assign Voices to Speakers")
125
  speaker_container = gr.Row()
 
126
 
127
+ generate_btn = gr.Button("Generate Audiobook", variant="primary", visible=False)
128
  audio_output = gr.Audio(label="Generated Audiobook", autoplay=True)
129
 
130
  def analyze_text(file):
 
133
 
134
  parser = DialogueParser()
135
  dialogues = parser.parse(text)
136
+ speakers = list({d["speaker"] for d in dialogues if d["speaker"] != "Narrator"})
137
 
138
  components = []
139
  for speaker in speakers:
140
+ components.append(gr.Audio(label=f"Voice for {speaker}", type="filepath"))
 
141
 
142
  return [
143
+ gr.update(visible=True), # speaker_ui visibility
144
+ gr.Row.update(components=components), # Update speaker_container
145
+ gr.update(visible=True), # generate_btn visibility
146
+ speakers # Store in detected_speakers state
147
  ]
148
 
149
  analyze_btn.click(
150
  analyze_text,
151
  inputs=txt_input,
152
+ outputs=[speaker_ui, speaker_container, generate_btn, detected_speakers]
153
  )
154
 
155
  generate_btn.click(
156
+ lambda text: (24000, np.random.rand(16000)), # Replace with actual TTS
157
  inputs=txt_input,
158
  outputs=audio_output
159
  )
 
160
  # ========== APP LAUNCH ========== #
161
  with gr.Blocks() as app:
162
  gr.TabbedInterface(