| import streamlit as st | |
| import requests | |
| st.title("π€ Text-to-Speech (Hugging Face API)") | |
| message = st.text_area("Enter Message", "Happy Birthday! Wishing you a joyful day filled with love and laughter.") | |
| emotion = st.text_input("Emotion", "happy") | |
| voice = st.text_input("Voice", "coral") | |
| if st.button("Generate Audio"): | |
| with st.spinner("Generating audio from Hugging Face..."): | |
| # Replace with the actual API endpoint | |
| API_URL = "https://nihalgazi-text-to-speech-unlimited.hf.space/run/predict" | |
| # Gradio-style input | |
| payload = { | |
| "data": [message, emotion, voice] | |
| } | |
| try: | |
| response = requests.post(API_URL, json=payload).json() | |
| audio_url = response["data"][0] # assuming this contains a URL or base64 audio | |
| if audio_url.startswith("http"): | |
| st.audio(audio_url) | |
| st.success("β Audio generated!") | |
| st.markdown(f"[π Download Audio]({audio_url})", unsafe_allow_html=True) | |
| else: | |
| st.error("Unexpected audio format returned.") | |
| except Exception as e: | |
| st.error(f"Error: {e}") |