Spaces:
Sleeping
Sleeping
Kartik Basavaraj commited on
Commit Β·
1bb32f5
1
Parent(s): 57bccdb
Updated UI
Browse files4 unmodified lines5678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310415 unmodified lines1201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851864 unmodified linesVM_ENDPOINT = os.environ.get("VM_ENDPOINT", "")SAMPLES = [{"transcript": "Hello, this is Priya from customer support. [clears throat] I'm calling regarding your refund request. The amount has been processed and should appear in your account within three business days.","file": "samples/sample_01.wav"},{"transcript": "Hey Rahul, are we still meeting for dinner tonight? [chuckles] I actually reached early for once, [m_laugh] so don't make me wait outside again.","file": "samples/sample_02.wav"},{"transcript": "Good morning. [m_clear throat] You have a meeting with the research team at 10 A.M., followed by a dentist appointment in the evening.","file": "samples/sample_03.wav"},{"transcript": "The current temperature is twenty-seven degrees Celsius. [clears throat] Light rain is expected after 4 P.M., so carrying an umbrella is recommended.","file": "samples/sample_04.wav"},{"transcript": "Did you finish your homework before watching videos? [sigh] Dinner is almost ready, and I've reminded you several times already.","file": "samples/sample_05.wav"},{"transcript": "Your order is currently being prepared and should arrive soon. [m_clear throat] Thank you for choosing our delivery service today.","file": "samples/sample_06.wav"},{"transcript": "Hello, this is a reminder for your appointment tomorrow at 11:30 A.M. [clears throat] Please arrive ten minutes early for registration.","file": "samples/sample_07.wav"},{"transcript": "We need to finalize the evaluation report before Friday. [m_sigh] Can you also review the benchmark results after lunch?","file": "samples/sample_08.wav"},{"transcript": "Attention passengers traveling to Bengaluru. [clears throat] Your flight has been delayed due to weather conditions. We regret the inconvenience.","file": "samples/sample_09.wav"},{"transcript": "This is an automated security notification. [m_clear throat] A login attempt was detected from a new device associated with your account.","file": "samples/sample_10.wav"},{"transcript": "Hey, you sounded stressed yesterday. [m_sigh] I just wanted to know if you're feeling any better today.","file": "samples/sample_11.wav"},{"transcript": "The living room lights are now turned off. [clears throat] Your washing machine cycle will finish in approximately twelve minutes.","file": "samples/sample_12.wav"},{"transcript": "Please submit your assignments before midnight today. [sigh] Late submissions may receive reduced marks without prior approval.","file": "samples/sample_13.wav"},{"transcript": "Hi, I ordered a laptop last week and it still hasn't arrived. [sigh] I need an update because this delay is affecting my work.","file": "samples/sample_14.wav"},{"transcript": "Warning. Heavy rainfall may cause flooding in nearby areas tonight. [m_clear throat] Residents are advised to avoid unnecessary travel.","file": "samples/sample_15.wav"},{"transcript": "We should leave early on Saturday morning to avoid traffic. [s_laugh] Last time we spent four hours stuck on the highway.","file": "samples/sample_16.wav"},{"transcript": "Hello, I'm calling regarding your interview for the machine learning engineer role. [clears throat] We'd like to schedule a technical discussion this week.","file": "samples/sample_17.wav"},{"transcript": "I found three products matching your search query. [m_clear throat] The highest-rated option currently has a fifteen percent discount.","file": "samples/sample_18.wav"},{"transcript": "[m_laugh] When I was your age, we walked to school every day. Even during heavy rain, we carried books in plastic covers.","file": "samples/sample_19.wav"},{"transcript": "Did you watch the new AI demo yesterday? [chuckles] The response speed looked impressive, [m_sigh] though a few answers were inaccurate.","file": "samples/sample_20.wav"},]SSML_TAGS = """| Tag | Effect | Example Usage ||-----|--------|----------------|| `[clear_throat]` | Clear throat β highest intensity | `[clear_throat] Hello, welcome.` || `[m_clear_throat]` | Clear throat β medium intensity | `[m_clear_throat] Let me explain.` || `[sighs]` | Sigh β highest intensity | `I can't believe it. [sighs]` || `[m_sighs]` | Sigh β medium intensity | `[m_sighs] That was a long day.` || `[laugh]` | Laugh β highest intensity | `That's so funny! [laugh]` || `[s_laugh]` | Laugh β subtle intensity | `Oh really? [s_laugh] Interesting.` || `[chuckles]` | Chuckles β highest intensity | `Well [chuckles] that was unexpected.` |"""def run_tts(text):if not text.strip():return None, "β οΈ Please enter some text."15 unmodified linesexcept Exception as e:return None, f"β Error: {str(e)}"css = """.sample-row { border: 1px solid #e0e0e0; border-radius: 8px; padding: 12px; margin-bottom: 8px; }.ssml-table { font-size: 0.85em; }footer { display: none !important; }"""with gr.Blocks(title="TTS Demo") as demo:gr.Markdown("""# π£οΈ TTS Demo**Single female voice Β· English Β· Paralinguistic tags supported** | [π Paper](#) | [π» Code](#)""")with gr.Row(equal_height=True):with gr.Column(scale=1):gr.Markdown("### βοΈ Input Text")text_input = gr.Textbox(label="",placeholder="Type your text here...\nYou can use tags from the reference below.",lines=8,max_lines=12,)gr.Markdown("#### π·οΈ Supported Paralinguistic Tags")gr.Markdown(SSML_TAGS, elem_classes=["ssml-table"])with gr.Row():submit_btn = gr.Button("π Generate Audio", variant="primary", scale=2)clear_btn = gr.Button("ποΈ Clear", scale=1)status_msg = gr.Markdown("")with gr.Column(scale=1):gr.Markdown("### π§ Generated Audio")audio_output = gr.Audio(label="",interactive=False,)gr.Markdown("""**Tips:**- Use tags for expressive speech control- Max 500 characters per request- Audio will auto-play after generation""")submit_btn.click(fn=run_tts, inputs=[text_input], outputs=[audio_output, status_msg])clear_btn.click(fn=lambda: ("", None, ""), outputs=[text_input, audio_output, status_msg])gr.Markdown("---")gr.Markdown("### π Audio Samples")gr.Markdown("Reference outputs from our test set.")for i, sample in enumerate(SAMPLES):with gr.Row(elem_classes=["sample-row"]):with gr.Column(scale=3):gr.Markdown(f"**Sample {i+1}**")gr.Markdown(f"*\"{sample['transcript']}\"*")with gr.Column(scale=2):gr.Audio(value=sample["file"],label="",interactive=False,)demo.launch(theme=gr.themes.Soft(), css=css)4 unmodified lines5678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111215 unmodified lines1281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312324 unmodified linesVM_ENDPOINT = os.environ.get("VM_ENDPOINT", "")SAMPLES = [{"transcript": "Hello, this is Priya from customer support. [clear_throat] I'm calling regarding your refund request. The amount has been processed and should appear in your account within three business days.", "file": "samples/sample_01.wav"},{"transcript": "Hey Rahul, are we still meeting for dinner tonight? [chuckles] I actually reached early for once, [s_laugh] so don't make me wait outside again.", "file": "samples/sample_02.wav"},{"transcript": "Good morning. [m_clear_throat] You have a meeting with the research team at 10 A.M., followed by a dentist appointment in the evening.", "file": "samples/sample_03.wav"},{"transcript": "The current temperature is twenty-seven degrees Celsius. [clear_throat] Light rain is expected after 4 P.M., so carrying an umbrella is recommended.", "file": "samples/sample_04.wav"},{"transcript": "Did you finish your homework before watching videos? [sighs] Dinner is almost ready, and I've reminded you several times already.", "file": "samples/sample_05.wav"},{"transcript": "Your order is currently being prepared and should arrive soon. [m_clear_throat] Thank you for choosing our delivery service today.", "file": "samples/sample_06.wav"},{"transcript": "Hello, this is a reminder for your appointment tomorrow at 11:30 A.M. [clear_throat] Please arrive ten minutes early for registration.", "file": "samples/sample_07.wav"},{"transcript": "We need to finalize the evaluation report before Friday. [m_sighs] Can you also review the benchmark results after lunch?", "file": "samples/sample_08.wav"},{"transcript": "Attention passengers traveling to Bengaluru. [clear_throat] Your flight has been delayed due to weather conditions. We regret the inconvenience.", "file": "samples/sample_09.wav"},{"transcript": "This is an automated security notification. [m_clear_throat] A login attempt was detected from a new device associated with your account.", "file": "samples/sample_10.wav"},{"transcript": "Hey, you sounded stressed yesterday. [m_sighs] I just wanted to know if you're feeling any better today.", "file": "samples/sample_11.wav"},{"transcript": "The living room lights are now turned off. [clear_throat] Your washing machine cycle will finish in approximately twelve minutes.", "file": "samples/sample_12.wav"},{"transcript": "Please submit your assignments before midnight today. [sighs] Late submissions may receive reduced marks without prior approval.", "file": "samples/sample_13.wav"},{"transcript": "Hi, I ordered a laptop last week and it still hasn't arrived. [sighs] I need an update because this delay is affecting my work.", "file": "samples/sample_14.wav"},{"transcript": "Warning. Heavy rainfall may cause flooding in nearby areas tonight. [m_clear_throat] Residents are advised to avoid unnecessary travel.", "file": "samples/sample_15.wav"},{"transcript": "We should leave early on Saturday morning to avoid traffic. [s_laugh] Last time we spent four hours stuck on the highway.", "file": "samples/sample_16.wav"},{"transcript": "Hello, I'm calling regarding your interview for the machine learning engineer role. [clear_throat] We'd like to schedule a technical discussion this week.", "file": "samples/sample_17.wav"},{"transcript": "I found three products matching your search query. [m_clear_throat] The highest-rated option currently has a fifteen percent discount.", "file": "samples/sample_18.wav"},{"transcript": "[s_laugh] When I was your age, we walked to school every day. Even during heavy rain, we carried books in plastic covers.", "file": "samples/sample_19.wav"},{"transcript": "Did you watch the new AI demo yesterday? [chuckles] The response speed looked impressive, [m_sighs] though a few answers were inaccurate.", "file": "samples/sample_20.wav"},]# ββ CSS β defined separately, passed to launch() per Gradio 6.0 ββcss = """body, .gradio-container {background-color: #0f0f0f !important;color: #e0e0e0 !important;font-family: 'Segoe UI', sans-serif;}.header-box {background: #1a1a1a;border: 1px solid #2a2a2a;border-radius: 8px;padding: 16px 20px;margin-bottom: 16px;}.section-label {font-size: 0.78em !important;font-weight: 600 !important;color: #888 !important;text-transform: uppercase;letter-spacing: 0.08em;margin-bottom: 6px !important;}textarea {background: #111 !important;color: #e0e0e0 !important;border: 1px solid #2a2a2a !important;border-radius: 6px !important;font-size: 0.95em !important;}.ssml-box {background: #111;border: 1px solid #2a2a2a;border-radius: 6px;padding: 10px 14px;margin-top: 8px;}.ssml-box table {width: 100%;font-size: 0.78em !important;border-collapse: collapse;}.ssml-box th {color: #888;font-weight: 600;text-align: left;padding: 4px 8px;border-bottom: 1px solid #2a2a2a;}.ssml-box td {padding: 3px 8px;color: #ccc;vertical-align: top;}.ssml-box code {background: #1f1f1f;border-radius: 3px;padding: 1px 5px;color: #e8a87c;font-size: 0.9em;}.sample-row {border: 1px solid #222 !important;border-radius: 6px !important;padding: 8px 12px !important;margin-bottom: 6px !important;background: #161616 !important;align-items: center !important;}.sample-row p {font-size: 0.82em !important;color: #bbb !important;margin: 0 !important;line-height: 1.4 !important;}.status-msg p { font-size: 0.85em !important; margin-top: 6px !important; }hr { border-color: #222 !important; margin: 20px 0 !important; }footer { display: none !important; }"""# ββ Inference ββββββββββββββββββββββββββββββββββββββββββββββββdef run_tts(text):if not text.strip():return None, "β οΈ Please enter some text."15 unmodified linesexcept Exception as e:return None, f"β Error: {str(e)}"def clear_all():# Explicit function instead of lambda β safer for Gradio 6.0return "", None, ""# ββ UI β title only in Blocks, theme+css in launch() per Gradio 6.0 ββwith gr.Blocks(title="SL TTS Demo") as demo:# Headergr.HTML("""<div class="header-box"><div style="font-weight:700; font-size:1.05em; margin-bottom:4px;">StyleTTS2 with SSML Support β Female Voice</div><div style="color:#aaa; font-size:0.88em;">SL TTS Demo Β· English Β· Single Female Voice | <a href="#" style="color:#e8640a; text-decoration:none;">π Paper</a></div></div>""")# Main row: Left input | Right outputwith gr.Row(equal_height=True):# LEFT β Text inputwith gr.Column(scale=1):gr.HTML('<div class="section-label">Input Text</div>')gr.HTML('<div style="color:#666; font-size:0.8em; margin-bottom:6px;">Up to ~500 characters</div>')text_input = gr.Textbox(label="",placeholder="Type your text here. You can use paralinguistic tags from the reference below.",lines=7,max_lines=10,)# Collapsed SSML accordion β no show_download_button, no deprecated argswith gr.Accordion("π·οΈ Supported Paralinguistic Tags", open=False):gr.HTML("""<div class="ssml-box"><table><tr><th>Tag</th><th>Effect</th><th>Example</th></tr><tr><td><code>[clear_throat]</code></td><td>Clear throat β high intensity</td><td><code>[clear_throat] Hello, welcome.</code></td></tr><tr><td><code>[m_clear_throat]</code></td><td>Clear throat β medium intensity</td><td><code>[m_clear_throat] Let me explain.</code></td></tr><tr><td><code>[sighs]</code></td><td>Sigh β high intensity</td><td><code>I can't believe it. [sighs]</code></td></tr><tr><td><code>[m_sighs]</code></td><td>Sigh β medium intensity</td><td><code>[m_sighs] That was a long day.</code></td></tr><tr><td><code>[laugh]</code></td><td>Laugh β high intensity</td><td><code>That's funny! [laugh]</code></td></tr><tr><td><code>[s_laugh]</code></td><td>Laugh β subtle intensity</td><td><code>Oh really? [s_laugh] Interesting.</code></td></tr><tr><td><code>[chuckles]</code></td><td>Chuckles β high intensity</td><td><code>Well [chuckles] that was unexpected.</code></td></tr></table></div>""")clear_btn = gr.Button("ποΈ Clear", variant="secondary")# RIGHT β Audio output + generatewith gr.Column(scale=1):gr.HTML('<div class="section-label">Output Audio</div>')# gr.Audio β no show_download_button (removed in Gradio 6.0)audio_output = gr.Audio(label="",interactive=False,)status_msg = gr.Markdown("", elem_classes=["status-msg"])# Generate button β variant="primary" only, no custom elem_classes neededsubmit_btn = gr.Button("π Generate", variant="primary")# Button wiringsubmit_btn.click(fn=run_tts,inputs=[text_input],outputs=[audio_output, status_msg],)clear_btn.click(fn=clear_all,inputs=[],outputs=[text_input, audio_output, status_msg],)gr.HTML("<hr/>")gr.HTML('<div class="section-label" style="margin-bottom:10px;">π Audio Samples</div>')# Sample rows β compact, no show_download_buttonfor i, sample in enumerate(SAMPLES):with gr.Row(elem_classes=["sample-row"]):with gr.Column(scale=4, min_width=200):gr.Markdown(f"**{i+1}.** {sample['transcript']}")with gr.Column(scale=3, min_width=180):gr.Audio(value=sample["file"],label="",interactive=False,)# ββ Launch β theme and css go HERE in Gradio 6.0, not in Blocks() ββdemo.launch(theme=gr.themes.Base(),css=css,)
app.py+173-127