Spaces:
Running
Running
Commit
Β·
8460a05
1
Parent(s):
a6b8c53
init space app
Browse files
app.py
CHANGED
@@ -1,4 +1,46 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import base64
|
4 |
+
from io import BytesIO
|
5 |
|
6 |
+
# Backend API URL
|
7 |
+
API_URL = "https://www.neuralaudio.solutions/api/zyphra-tts"
|
8 |
+
|
9 |
+
st.set_page_config(page_title="NeuralAudioAI TTS", layout="centered")
|
10 |
+
st.image("https://storage.googleapis.com/crypto-utils-1/Header%20with%20Pattern.png", use_container_width=True)
|
11 |
+
st.title("π Neural Audio AI - TTS Demo")
|
12 |
+
st.write("Enter text and generate speech using **NeuralAudioAI/NA_base**.")
|
13 |
+
|
14 |
+
# Text Input
|
15 |
+
text = st.text_area("π Enter text to synthesize:", "Hello! This is Neural Audio AI speaking.")
|
16 |
+
|
17 |
+
if st.button("ποΈ Generate Speech"):
|
18 |
+
if not text.strip():
|
19 |
+
st.warning("β οΈ Please enter some text.")
|
20 |
+
else:
|
21 |
+
with st.spinner("Generating audio... πΆ"):
|
22 |
+
try:
|
23 |
+
# Mimic the working frontend FormData:
|
24 |
+
# - "text" field with the text value.
|
25 |
+
# - "speaker_audio" left empty so backend uses its default.
|
26 |
+
files = {
|
27 |
+
"text": (None, text),
|
28 |
+
"speaker_audio": (None, "") # This will be treated as not provided.
|
29 |
+
}
|
30 |
+
|
31 |
+
response = requests.post(API_URL, files=files)
|
32 |
+
|
33 |
+
if response.status_code == 200:
|
34 |
+
audio_bytes = response.content
|
35 |
+
|
36 |
+
# Use BytesIO so st.audio plays the file directly from memory.
|
37 |
+
audio_io = BytesIO(audio_bytes)
|
38 |
+
st.audio(audio_io, format="audio/mpeg")
|
39 |
+
else:
|
40 |
+
try:
|
41 |
+
error_message = response.json().get("error", "Unknown error occurred")
|
42 |
+
except Exception:
|
43 |
+
error_message = response.text
|
44 |
+
st.error(f"β Failed to generate speech: {error_message}")
|
45 |
+
except requests.RequestException as e:
|
46 |
+
st.error(f"β Error communicating with the server: {e}")
|