Spaces:
Runtime error
Runtime error
Modified Logo
Browse files- app.py +165 -1
- logo.jpg +0 -0
- logo/logo.jpg +0 -0
app.py
CHANGED
|
@@ -303,7 +303,7 @@ with gr.Blocks(theme=custom_theme, css=custom_css) as app:
|
|
| 303 |
)
|
| 304 |
|
| 305 |
with gr.Column(scale=1, elem_id="logo-column"):
|
| 306 |
-
gr.Image("logo/logo
|
| 307 |
|
| 308 |
with gr.Row():
|
| 309 |
with gr.Column(scale=1):
|
|
@@ -382,5 +382,169 @@ with gr.Blocks(theme=custom_theme, css=custom_css) as app:
|
|
| 382 |
"""
|
| 383 |
)
|
| 384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
if __name__ == "__main__":
|
| 386 |
app.launch(share=True)
|
|
|
|
| 303 |
)
|
| 304 |
|
| 305 |
with gr.Column(scale=1, elem_id="logo-column"):
|
| 306 |
+
gr.Image("logo/logo.jpg", label="", show_label=False)
|
| 307 |
|
| 308 |
with gr.Row():
|
| 309 |
with gr.Column(scale=1):
|
|
|
|
| 382 |
"""
|
| 383 |
)
|
| 384 |
|
| 385 |
+
<<<<<<< HEAD
|
| 386 |
+
=======
|
| 387 |
+
# Text input for the prompt
|
| 388 |
+
gen_text_input_emotional = gr.Textbox(label="Text to Generate", lines=10)
|
| 389 |
+
|
| 390 |
+
# Model choice
|
| 391 |
+
model_choice_emotional = gr.Radio(
|
| 392 |
+
choices=["F5-TTS", "E2-TTS"], label="Choose TTS Model", value="F5-TTS"
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 396 |
+
remove_silence_emotional = gr.Checkbox(
|
| 397 |
+
label="Remove Silences",
|
| 398 |
+
value=True,
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
# Generate button
|
| 402 |
+
generate_emotional_btn = gr.Button("Generate Emotional Speech", variant="primary")
|
| 403 |
+
|
| 404 |
+
# Output audio
|
| 405 |
+
audio_output_emotional = gr.Audio(label="Synthesized Audio")
|
| 406 |
+
@gpu_decorator
|
| 407 |
+
def generate_emotional_speech(
|
| 408 |
+
regular_audio,
|
| 409 |
+
regular_ref_text,
|
| 410 |
+
gen_text,
|
| 411 |
+
*args,
|
| 412 |
+
):
|
| 413 |
+
num_additional_speech_types = max_speech_types - 1
|
| 414 |
+
speech_type_names_list = args[:num_additional_speech_types]
|
| 415 |
+
speech_type_audios_list = args[num_additional_speech_types:2 * num_additional_speech_types]
|
| 416 |
+
speech_type_ref_texts_list = args[2 * num_additional_speech_types:3 * num_additional_speech_types]
|
| 417 |
+
model_choice = args[3 * num_additional_speech_types]
|
| 418 |
+
remove_silence = args[3 * num_additional_speech_types + 1]
|
| 419 |
+
|
| 420 |
+
# Collect the speech types and their audios into a dict
|
| 421 |
+
speech_types = {'Regular': {'audio': regular_audio, 'ref_text': regular_ref_text}}
|
| 422 |
+
|
| 423 |
+
for name_input, audio_input, ref_text_input in zip(speech_type_names_list, speech_type_audios_list, speech_type_ref_texts_list):
|
| 424 |
+
if name_input and audio_input:
|
| 425 |
+
speech_types[name_input] = {'audio': audio_input, 'ref_text': ref_text_input}
|
| 426 |
+
|
| 427 |
+
# Parse the gen_text into segments
|
| 428 |
+
segments = parse_speechtypes_text(gen_text)
|
| 429 |
+
|
| 430 |
+
# For each segment, generate speech
|
| 431 |
+
generated_audio_segments = []
|
| 432 |
+
current_emotion = 'Regular'
|
| 433 |
+
|
| 434 |
+
for segment in segments:
|
| 435 |
+
emotion = segment['emotion']
|
| 436 |
+
text = segment['text']
|
| 437 |
+
|
| 438 |
+
if emotion in speech_types:
|
| 439 |
+
current_emotion = emotion
|
| 440 |
+
else:
|
| 441 |
+
# If emotion not available, default to Regular
|
| 442 |
+
current_emotion = 'Regular'
|
| 443 |
+
|
| 444 |
+
ref_audio = speech_types[current_emotion]['audio']
|
| 445 |
+
ref_text = speech_types[current_emotion].get('ref_text', '')
|
| 446 |
+
|
| 447 |
+
# Generate speech for this segment
|
| 448 |
+
audio, _ = infer(ref_audio, ref_text, text, model_choice, remove_silence, 0)
|
| 449 |
+
sr, audio_data = audio
|
| 450 |
+
|
| 451 |
+
generated_audio_segments.append(audio_data)
|
| 452 |
+
|
| 453 |
+
# Concatenate all audio segments
|
| 454 |
+
if generated_audio_segments:
|
| 455 |
+
final_audio_data = np.concatenate(generated_audio_segments)
|
| 456 |
+
return (sr, final_audio_data)
|
| 457 |
+
else:
|
| 458 |
+
gr.Warning("No audio generated.")
|
| 459 |
+
return None
|
| 460 |
+
|
| 461 |
+
generate_emotional_btn.click(
|
| 462 |
+
generate_emotional_speech,
|
| 463 |
+
inputs=[
|
| 464 |
+
regular_audio,
|
| 465 |
+
regular_ref_text,
|
| 466 |
+
gen_text_input_emotional,
|
| 467 |
+
] + speech_type_names + speech_type_audios + speech_type_ref_texts + [
|
| 468 |
+
model_choice_emotional,
|
| 469 |
+
remove_silence_emotional,
|
| 470 |
+
],
|
| 471 |
+
outputs=audio_output_emotional,
|
| 472 |
+
)
|
| 473 |
+
|
| 474 |
+
# Validation function to disable Generate button if speech types are missing
|
| 475 |
+
def validate_speech_types(
|
| 476 |
+
gen_text,
|
| 477 |
+
regular_name,
|
| 478 |
+
*args
|
| 479 |
+
):
|
| 480 |
+
num_additional_speech_types = max_speech_types - 1
|
| 481 |
+
speech_type_names_list = args[:num_additional_speech_types]
|
| 482 |
+
|
| 483 |
+
# Collect the speech types names
|
| 484 |
+
speech_types_available = set()
|
| 485 |
+
if regular_name:
|
| 486 |
+
speech_types_available.add(regular_name)
|
| 487 |
+
for name_input in speech_type_names_list:
|
| 488 |
+
if name_input:
|
| 489 |
+
speech_types_available.add(name_input)
|
| 490 |
+
|
| 491 |
+
# Parse the gen_text to get the speech types used
|
| 492 |
+
segments = parse_emotional_text(gen_text)
|
| 493 |
+
speech_types_in_text = set(segment['emotion'] for segment in segments)
|
| 494 |
+
|
| 495 |
+
# Check if all speech types in text are available
|
| 496 |
+
missing_speech_types = speech_types_in_text - speech_types_available
|
| 497 |
+
|
| 498 |
+
if missing_speech_types:
|
| 499 |
+
# Disable the generate button
|
| 500 |
+
return gr.update(interactive=False)
|
| 501 |
+
else:
|
| 502 |
+
# Enable the generate button
|
| 503 |
+
return gr.update(interactive=True)
|
| 504 |
+
|
| 505 |
+
gen_text_input_emotional.change(
|
| 506 |
+
validate_speech_types,
|
| 507 |
+
inputs=[gen_text_input_emotional, regular_name] + speech_type_names,
|
| 508 |
+
outputs=generate_emotional_btn
|
| 509 |
+
)
|
| 510 |
+
with gr.Blocks() as app:
|
| 511 |
+
gr.Markdown(
|
| 512 |
+
"""
|
| 513 |
+
# Antriksh AI
|
| 514 |
+
"""
|
| 515 |
+
)
|
| 516 |
+
|
| 517 |
+
# Add the image here
|
| 518 |
+
gr.Image(
|
| 519 |
+
value="logo.jpg",
|
| 520 |
+
label="AI System Logo",
|
| 521 |
+
show_label=False,
|
| 522 |
+
width=300,
|
| 523 |
+
height=150
|
| 524 |
+
)
|
| 525 |
+
|
| 526 |
+
gr.TabbedInterface([app_tts, app_podcast, app_emotional, app_credits], ["TTS", "Podcast", "Multi-Style", "Credits"])
|
| 527 |
+
|
| 528 |
+
|
| 529 |
+
@click.command()
|
| 530 |
+
@click.option("--port", "-p", default=None, type=int, help="Port to run the app on")
|
| 531 |
+
@click.option("--host", "-H", default=None, help="Host to run the app on")
|
| 532 |
+
@click.option(
|
| 533 |
+
"--share",
|
| 534 |
+
"-s",
|
| 535 |
+
default=False,
|
| 536 |
+
is_flag=True,
|
| 537 |
+
help="Share the app via Gradio share link",
|
| 538 |
+
)
|
| 539 |
+
@click.option("--api", "-a", default=True, is_flag=True, help="Allow API access")
|
| 540 |
+
def main(port, host, share, api):
|
| 541 |
+
global app
|
| 542 |
+
print(f"Starting app...")
|
| 543 |
+
app.queue(api_open=api).launch(
|
| 544 |
+
server_name=host, server_port=port, share=share, show_api=api
|
| 545 |
+
)
|
| 546 |
+
|
| 547 |
+
|
| 548 |
+
>>>>>>> 3c3b34b0ce3a85c2e202414d6764288cad249a97
|
| 549 |
if __name__ == "__main__":
|
| 550 |
app.launch(share=True)
|
logo.jpg
ADDED
|
logo/logo.jpg
ADDED
|