Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,13 @@ import platform
|
|
| 3 |
import sys
|
| 4 |
|
| 5 |
# Fix for "ValueError: Invalid file descriptor: -1" on shutdown
|
| 6 |
-
|
|
|
|
| 7 |
try:
|
| 8 |
-
#
|
| 9 |
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
|
| 10 |
-
except
|
| 11 |
-
pass # Ignore
|
| 12 |
|
| 13 |
# Now import other modules
|
| 14 |
import gradio as gr
|
|
@@ -19,7 +20,7 @@ import scipy.io.wavfile
|
|
| 19 |
import warnings
|
| 20 |
warnings.filterwarnings("ignore")
|
| 21 |
|
| 22 |
-
# Clean white theme CSS
|
| 23 |
css = """
|
| 24 |
<style>
|
| 25 |
/* WHITE BACKGROUND THEME */
|
|
@@ -63,12 +64,6 @@ body, .gradio-container {
|
|
| 63 |
padding: 1.75rem;
|
| 64 |
margin-bottom: 1.5rem;
|
| 65 |
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
|
| 66 |
-
transition: transform 0.2s, box-shadow 0.2s;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
.card:hover {
|
| 70 |
-
transform: translateY(-2px);
|
| 71 |
-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
|
| 72 |
}
|
| 73 |
|
| 74 |
/* Text Input - BLACK TEXT ON WHITE */
|
|
@@ -76,13 +71,12 @@ textarea {
|
|
| 76 |
background: white !important;
|
| 77 |
border: 2px solid #D1D5DB !important;
|
| 78 |
border-radius: 12px !important;
|
| 79 |
-
color: #111827 !important;
|
| 80 |
padding: 1rem !important;
|
| 81 |
font-size: 16px !important;
|
| 82 |
font-family: 'SF Mono', Monaco, 'Courier New', monospace !important;
|
| 83 |
width: 100% !important;
|
| 84 |
min-height: 140px !important;
|
| 85 |
-
transition: all 0.2s !important;
|
| 86 |
line-height: 1.5 !important;
|
| 87 |
}
|
| 88 |
|
|
@@ -108,11 +102,6 @@ textarea::placeholder {
|
|
| 108 |
font-weight: 600 !important;
|
| 109 |
font-size: 1rem !important;
|
| 110 |
cursor: pointer !important;
|
| 111 |
-
transition: all 0.2s !important;
|
| 112 |
-
display: inline-flex !important;
|
| 113 |
-
align-items: center !important;
|
| 114 |
-
justify-content: center !important;
|
| 115 |
-
gap: 0.5rem !important;
|
| 116 |
}
|
| 117 |
|
| 118 |
.btn-primary:hover {
|
|
@@ -128,7 +117,6 @@ textarea::placeholder {
|
|
| 128 |
border-radius: 12px !important;
|
| 129 |
font-weight: 500 !important;
|
| 130 |
cursor: pointer !important;
|
| 131 |
-
transition: all 0.2s !important;
|
| 132 |
}
|
| 133 |
|
| 134 |
.btn-secondary:hover {
|
|
@@ -196,12 +184,6 @@ input[type="range"]::-webkit-slider-thumb {
|
|
| 196 |
border-radius: 12px;
|
| 197 |
padding: 1.25rem;
|
| 198 |
text-align: center;
|
| 199 |
-
transition: all 0.2s;
|
| 200 |
-
}
|
| 201 |
-
|
| 202 |
-
.stat-box:hover {
|
| 203 |
-
border-color: #4F46E5;
|
| 204 |
-
transform: translateY(-2px);
|
| 205 |
}
|
| 206 |
|
| 207 |
.stat-value {
|
|
@@ -242,32 +224,6 @@ input[type="range"]::-webkit-slider-thumb {
|
|
| 242 |
margin: 1rem 0 !important;
|
| 243 |
}
|
| 244 |
|
| 245 |
-
/* Examples */
|
| 246 |
-
.examples-grid {
|
| 247 |
-
display: grid;
|
| 248 |
-
gap: 0.75rem;
|
| 249 |
-
margin-top: 1rem;
|
| 250 |
-
}
|
| 251 |
-
|
| 252 |
-
.example-btn {
|
| 253 |
-
background: white;
|
| 254 |
-
border: 1px solid #E5E7EB;
|
| 255 |
-
border-radius: 10px;
|
| 256 |
-
padding: 0.875rem 1rem;
|
| 257 |
-
text-align: left;
|
| 258 |
-
color: #374151;
|
| 259 |
-
cursor: pointer;
|
| 260 |
-
transition: all 0.2s;
|
| 261 |
-
font-size: 0.95rem;
|
| 262 |
-
line-height: 1.4;
|
| 263 |
-
}
|
| 264 |
-
|
| 265 |
-
.example-btn:hover {
|
| 266 |
-
border-color: #4F46E5;
|
| 267 |
-
background: #F5F3FF;
|
| 268 |
-
transform: translateX(4px);
|
| 269 |
-
}
|
| 270 |
-
|
| 271 |
/* Footer */
|
| 272 |
.footer {
|
| 273 |
text-align: center;
|
|
@@ -465,7 +421,7 @@ with gr.Blocks() as demo:
|
|
| 465 |
gr.HTML("""
|
| 466 |
<div class="header">
|
| 467 |
<h1>🎵 VibeVoice Text-to-Speech</h1>
|
| 468 |
-
<p>Convert text into natural-sounding speech
|
| 469 |
</div>
|
| 470 |
""")
|
| 471 |
|
|
@@ -478,7 +434,7 @@ with gr.Blocks() as demo:
|
|
| 478 |
|
| 479 |
text_input = gr.Textbox(
|
| 480 |
label="",
|
| 481 |
-
placeholder="Type or paste your text here...
|
| 482 |
lines=6,
|
| 483 |
elem_id="text-input"
|
| 484 |
)
|
|
@@ -549,11 +505,11 @@ with gr.Blocks() as demo:
|
|
| 549 |
|
| 550 |
gr.Examples(
|
| 551 |
examples=[
|
| 552 |
-
["Hello! Welcome to VibeVoice text-to-speech system.
|
| 553 |
-
["The quick brown fox jumps over the lazy dog.
|
| 554 |
-
["Artificial intelligence is revolutionizing
|
| 555 |
-
["Would you like a cup of coffee or tea this morning?
|
| 556 |
-
["This text-to-speech system converts written text into spoken words.
|
| 557 |
],
|
| 558 |
inputs=text_input,
|
| 559 |
label="Click any example to load it:",
|
|
@@ -564,39 +520,28 @@ with gr.Blocks() as demo:
|
|
| 564 |
with gr.Column(elem_classes="card"):
|
| 565 |
gr.Markdown("### ℹ️ About VibeVoice TTS")
|
| 566 |
gr.Markdown("""
|
| 567 |
-
**VibeVoice TTS**
|
| 568 |
|
| 569 |
-
**
|
| 570 |
-
- 🎵
|
| 571 |
-
- ⚡
|
| 572 |
-
- 🎭
|
| 573 |
-
- ⚙️
|
| 574 |
-
- 📱 **User-friendly interface**
|
| 575 |
|
| 576 |
-
**Tips
|
| 577 |
1. Use clear, well-punctuated text
|
| 578 |
-
2. Keep
|
| 579 |
3. Adjust speed to match your preference
|
| 580 |
-
4. Try different voice styles for variety
|
| 581 |
-
|
| 582 |
-
**Common Use Cases:**
|
| 583 |
-
- Accessibility tools for visually impaired users
|
| 584 |
-
- Content creation for videos and podcasts
|
| 585 |
-
- Language learning and pronunciation practice
|
| 586 |
-
- Audiobook creation
|
| 587 |
-
- Voiceover generation
|
| 588 |
""")
|
| 589 |
|
| 590 |
# Footer
|
| 591 |
gr.HTML("""
|
| 592 |
<div class="footer">
|
| 593 |
<div style="margin-bottom: 1rem;">
|
| 594 |
-
<span style="color: #4F46E5; font-weight: 600;">VibeVoice TTS</span>
|
| 595 |
-
<span>AI-Powered Speech Synthesis</span> •
|
| 596 |
-
<span>Version 1.0</span>
|
| 597 |
</div>
|
| 598 |
<div style="font-size: 0.9em; color: #9CA3AF;">
|
| 599 |
-
Made with
|
| 600 |
</div>
|
| 601 |
</div>
|
| 602 |
""")
|
|
@@ -648,7 +593,7 @@ with gr.Blocks() as demo:
|
|
| 648 |
outputs=[stats_display]
|
| 649 |
)
|
| 650 |
|
| 651 |
-
# Launch the app with
|
| 652 |
if __name__ == "__main__":
|
| 653 |
try:
|
| 654 |
demo.launch(
|
|
@@ -656,18 +601,12 @@ if __name__ == "__main__":
|
|
| 656 |
server_port=7860,
|
| 657 |
show_error=True,
|
| 658 |
quiet=True,
|
| 659 |
-
debug=False
|
|
|
|
|
|
|
|
|
|
| 660 |
)
|
| 661 |
except KeyboardInterrupt:
|
| 662 |
print("\n👋 Shutting down VibeVoice TTS...")
|
| 663 |
-
# Clean shutdown
|
| 664 |
-
try:
|
| 665 |
-
import asyncio
|
| 666 |
-
loop = asyncio.get_event_loop()
|
| 667 |
-
if loop.is_running():
|
| 668 |
-
loop.stop()
|
| 669 |
-
except:
|
| 670 |
-
pass
|
| 671 |
-
print("✅ Shutdown complete!")
|
| 672 |
except Exception as e:
|
| 673 |
print(f"❌ Error: {e}")
|
|
|
|
| 3 |
import sys
|
| 4 |
|
| 5 |
# Fix for "ValueError: Invalid file descriptor: -1" on shutdown
|
| 6 |
+
# This is specifically for Hugging Face Spaces environment
|
| 7 |
+
if sys.platform.startswith("linux") or sys.platform.startswith("darwin"):
|
| 8 |
try:
|
| 9 |
+
# Use the default policy to prevent faulty cleanup on shutdown
|
| 10 |
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
|
| 11 |
+
except Exception:
|
| 12 |
+
pass # Ignore any errors if this fails
|
| 13 |
|
| 14 |
# Now import other modules
|
| 15 |
import gradio as gr
|
|
|
|
| 20 |
import warnings
|
| 21 |
warnings.filterwarnings("ignore")
|
| 22 |
|
| 23 |
+
# Clean white theme CSS with black text
|
| 24 |
css = """
|
| 25 |
<style>
|
| 26 |
/* WHITE BACKGROUND THEME */
|
|
|
|
| 64 |
padding: 1.75rem;
|
| 65 |
margin-bottom: 1.5rem;
|
| 66 |
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
|
| 69 |
/* Text Input - BLACK TEXT ON WHITE */
|
|
|
|
| 71 |
background: white !important;
|
| 72 |
border: 2px solid #D1D5DB !important;
|
| 73 |
border-radius: 12px !important;
|
| 74 |
+
color: #111827 !important;
|
| 75 |
padding: 1rem !important;
|
| 76 |
font-size: 16px !important;
|
| 77 |
font-family: 'SF Mono', Monaco, 'Courier New', monospace !important;
|
| 78 |
width: 100% !important;
|
| 79 |
min-height: 140px !important;
|
|
|
|
| 80 |
line-height: 1.5 !important;
|
| 81 |
}
|
| 82 |
|
|
|
|
| 102 |
font-weight: 600 !important;
|
| 103 |
font-size: 1rem !important;
|
| 104 |
cursor: pointer !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
}
|
| 106 |
|
| 107 |
.btn-primary:hover {
|
|
|
|
| 117 |
border-radius: 12px !important;
|
| 118 |
font-weight: 500 !important;
|
| 119 |
cursor: pointer !important;
|
|
|
|
| 120 |
}
|
| 121 |
|
| 122 |
.btn-secondary:hover {
|
|
|
|
| 184 |
border-radius: 12px;
|
| 185 |
padding: 1.25rem;
|
| 186 |
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
}
|
| 188 |
|
| 189 |
.stat-value {
|
|
|
|
| 224 |
margin: 1rem 0 !important;
|
| 225 |
}
|
| 226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
/* Footer */
|
| 228 |
.footer {
|
| 229 |
text-align: center;
|
|
|
|
| 421 |
gr.HTML("""
|
| 422 |
<div class="header">
|
| 423 |
<h1>🎵 VibeVoice Text-to-Speech</h1>
|
| 424 |
+
<p>Convert text into natural-sounding speech</p>
|
| 425 |
</div>
|
| 426 |
""")
|
| 427 |
|
|
|
|
| 434 |
|
| 435 |
text_input = gr.Textbox(
|
| 436 |
label="",
|
| 437 |
+
placeholder="Type or paste your text here...",
|
| 438 |
lines=6,
|
| 439 |
elem_id="text-input"
|
| 440 |
)
|
|
|
|
| 505 |
|
| 506 |
gr.Examples(
|
| 507 |
examples=[
|
| 508 |
+
["Hello! Welcome to VibeVoice text-to-speech system."],
|
| 509 |
+
["The quick brown fox jumps over the lazy dog."],
|
| 510 |
+
["Artificial intelligence is revolutionizing technology."],
|
| 511 |
+
["Would you like a cup of coffee or tea this morning?"],
|
| 512 |
+
["This text-to-speech system converts written text into spoken words."]
|
| 513 |
],
|
| 514 |
inputs=text_input,
|
| 515 |
label="Click any example to load it:",
|
|
|
|
| 520 |
with gr.Column(elem_classes="card"):
|
| 521 |
gr.Markdown("### ℹ️ About VibeVoice TTS")
|
| 522 |
gr.Markdown("""
|
| 523 |
+
**VibeVoice TTS** converts written text into natural-sounding speech.
|
| 524 |
|
| 525 |
+
**Features:**
|
| 526 |
+
- 🎵 High-quality audio output
|
| 527 |
+
- ⚡ Fast processing speed
|
| 528 |
+
- 🎭 Multiple voice styles
|
| 529 |
+
- ⚙️ Adjustable speaking rate
|
|
|
|
| 530 |
|
| 531 |
+
**Tips:**
|
| 532 |
1. Use clear, well-punctuated text
|
| 533 |
+
2. Keep text under 500 characters
|
| 534 |
3. Adjust speed to match your preference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
""")
|
| 536 |
|
| 537 |
# Footer
|
| 538 |
gr.HTML("""
|
| 539 |
<div class="footer">
|
| 540 |
<div style="margin-bottom: 1rem;">
|
| 541 |
+
<span style="color: #4F46E5; font-weight: 600;">VibeVoice TTS</span>
|
|
|
|
|
|
|
| 542 |
</div>
|
| 543 |
<div style="font-size: 0.9em; color: #9CA3AF;">
|
| 544 |
+
Made with Gradio
|
| 545 |
</div>
|
| 546 |
</div>
|
| 547 |
""")
|
|
|
|
| 593 |
outputs=[stats_display]
|
| 594 |
)
|
| 595 |
|
| 596 |
+
# Launch the app with Hugging Face Space-specific fix
|
| 597 |
if __name__ == "__main__":
|
| 598 |
try:
|
| 599 |
demo.launch(
|
|
|
|
| 601 |
server_port=7860,
|
| 602 |
show_error=True,
|
| 603 |
quiet=True,
|
| 604 |
+
debug=False,
|
| 605 |
+
# CRITICAL FIX for Hugging Face Spaces
|
| 606 |
+
# Prevents the "ValueError: Invalid file descriptor: -1" error
|
| 607 |
+
close_event_loop=False
|
| 608 |
)
|
| 609 |
except KeyboardInterrupt:
|
| 610 |
print("\n👋 Shutting down VibeVoice TTS...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 611 |
except Exception as e:
|
| 612 |
print(f"❌ Error: {e}")
|