Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -1,3 +1,4 @@ | |
|  | |
| 1 | 
             
            import gradio as gr
         | 
| 2 | 
             
            import edge_tts
         | 
| 3 | 
             
            import asyncio
         | 
| @@ -24,7 +25,7 @@ async def _text_to_speech(text, short_name, rate_str, pitch_str): | |
| 24 | 
             
            # 3) Sync wrapper for Gradio callback
         | 
| 25 | 
             
            def tts_interface(text, voice_choice, rate, pitch):
         | 
| 26 | 
             
                if not text.strip():
         | 
| 27 | 
            -
                    return None, "🚨 Please enter  | 
| 28 | 
             
                if not voice_choice:
         | 
| 29 | 
             
                    return None, "🚨 Please select a voice."
         | 
| 30 | 
             
                short_name = voice_choice.split(" - ")[0]
         | 
| @@ -36,9 +37,9 @@ def tts_interface(text, voice_choice, rate, pitch): | |
| 36 | 
             
                    )
         | 
| 37 | 
             
                    return audio_path, ""
         | 
| 38 | 
             
                except Exception as e:
         | 
| 39 | 
            -
                    return None, f"❌ TTS  | 
| 40 |  | 
| 41 | 
            -
            # 4) Build the UI
         | 
| 42 | 
             
            def create_demo():
         | 
| 43 | 
             
                with gr.Blocks(analytics_enabled=False) as demo:
         | 
| 44 | 
             
                    gr.Markdown("# 🎙️ Edge TTS on Hugging Face Spaces")
         | 
| @@ -49,13 +50,13 @@ def create_demo(): | |
| 49 | 
             
                    )
         | 
| 50 |  | 
| 51 | 
             
                    with gr.Row():
         | 
| 52 | 
            -
                        txt   = gr.Textbox(label="Input Text", lines=5, placeholder="Type  | 
| 53 | 
             
                        vox   = gr.Dropdown(choices=list(VOICES.keys()), label="Voice")
         | 
| 54 | 
             
                        rate  = gr.Slider(-50, 50, value=0, label="Rate (%)")
         | 
| 55 | 
             
                        pitch = gr.Slider(-20, 20, value=0, label="Pitch (Hz)")
         | 
| 56 |  | 
| 57 | 
             
                    btn       = gr.Button("Generate Speech")
         | 
| 58 | 
            -
                    audio_out = gr.Audio(type="filepath", label="Audio | 
| 59 | 
             
                    warn_md   = gr.Markdown("", label="Warnings / Errors")
         | 
| 60 |  | 
| 61 | 
             
                    btn.click(
         | 
| @@ -64,12 +65,17 @@ def create_demo(): | |
| 64 | 
             
                        outputs=[audio_out, warn_md]
         | 
| 65 | 
             
                    )
         | 
| 66 |  | 
| 67 | 
            -
                    #  | 
| 68 | 
             
                    demo.queue()
         | 
| 69 |  | 
| 70 | 
             
                return demo
         | 
| 71 |  | 
| 72 | 
            -
            # 5) Launch with SSR disabled
         | 
| 73 | 
             
            if __name__ == "__main__":
         | 
| 74 | 
             
                demo = create_demo()
         | 
| 75 | 
            -
                 | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            import os
         | 
| 2 | 
             
            import gradio as gr
         | 
| 3 | 
             
            import edge_tts
         | 
| 4 | 
             
            import asyncio
         | 
|  | |
| 25 | 
             
            # 3) Sync wrapper for Gradio callback
         | 
| 26 | 
             
            def tts_interface(text, voice_choice, rate, pitch):
         | 
| 27 | 
             
                if not text.strip():
         | 
| 28 | 
            +
                    return None, "🚨 Please enter text."
         | 
| 29 | 
             
                if not voice_choice:
         | 
| 30 | 
             
                    return None, "🚨 Please select a voice."
         | 
| 31 | 
             
                short_name = voice_choice.split(" - ")[0]
         | 
|  | |
| 37 | 
             
                    )
         | 
| 38 | 
             
                    return audio_path, ""
         | 
| 39 | 
             
                except Exception as e:
         | 
| 40 | 
            +
                    return None, f"❌ TTS error: {e}"
         | 
| 41 |  | 
| 42 | 
            +
            # 4) Build the Gradio UI
         | 
| 43 | 
             
            def create_demo():
         | 
| 44 | 
             
                with gr.Blocks(analytics_enabled=False) as demo:
         | 
| 45 | 
             
                    gr.Markdown("# 🎙️ Edge TTS on Hugging Face Spaces")
         | 
|  | |
| 50 | 
             
                    )
         | 
| 51 |  | 
| 52 | 
             
                    with gr.Row():
         | 
| 53 | 
            +
                        txt   = gr.Textbox(label="Input Text", lines=5, placeholder="Type here…")
         | 
| 54 | 
             
                        vox   = gr.Dropdown(choices=list(VOICES.keys()), label="Voice")
         | 
| 55 | 
             
                        rate  = gr.Slider(-50, 50, value=0, label="Rate (%)")
         | 
| 56 | 
             
                        pitch = gr.Slider(-20, 20, value=0, label="Pitch (Hz)")
         | 
| 57 |  | 
| 58 | 
             
                    btn       = gr.Button("Generate Speech")
         | 
| 59 | 
            +
                    audio_out = gr.Audio(type="filepath", label="Output Audio")
         | 
| 60 | 
             
                    warn_md   = gr.Markdown("", label="Warnings / Errors")
         | 
| 61 |  | 
| 62 | 
             
                    btn.click(
         | 
|  | |
| 65 | 
             
                        outputs=[audio_out, warn_md]
         | 
| 66 | 
             
                    )
         | 
| 67 |  | 
| 68 | 
            +
                    # Register API endpoints
         | 
| 69 | 
             
                    demo.queue()
         | 
| 70 |  | 
| 71 | 
             
                return demo
         | 
| 72 |  | 
|  | |
| 73 | 
             
            if __name__ == "__main__":
         | 
| 74 | 
             
                demo = create_demo()
         | 
| 75 | 
            +
                # 5) Bind to 0.0.0.0 and the port provided by HF Spaces (defaults to 7860 internally)
         | 
| 76 | 
            +
                port = int(os.environ.get("PORT", 7860))
         | 
| 77 | 
            +
                demo.launch(
         | 
| 78 | 
            +
                    server_name="0.0.0.0",
         | 
| 79 | 
            +
                    server_port=port,
         | 
| 80 | 
            +
                    share=False
         | 
| 81 | 
            +
                )
         |