File size: 11,315 Bytes
1d877da
b2b0b49
1d877da
 
 
b2b0b49
1d877da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2b0b49
 
1d877da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2b0b49
1d877da
 
 
 
 
 
 
 
 
 
b2b0b49
1d877da
 
 
 
 
 
 
 
 
 
 
 
 
 
b2b0b49
1d877da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2b0b49
 
 
 
 
 
 
1d877da
 
b2b0b49
 
1d877da
 
 
 
 
 
 
 
 
 
b2b0b49
1d877da
 
 
 
 
 
 
 
 
 
 
b2b0b49
1d877da
 
 
 
 
 
 
b2b0b49
1d877da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2b0b49
1d877da
 
b2b0b49
 
 
 
 
 
 
 
 
 
1d877da
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import streamlit as st
from gradio_client import Client
import tempfile
import os
import time
import shutil

# Page configuration
st.set_page_config(
    page_title="VibeVoice TTS Tester",
    page_icon="🎀",
    layout="wide",
    initial_sidebar_state="expanded"
)

# Custom CSS for modern styling
st.markdown("""
<style>
    .main-header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        padding: 2rem;
        border-radius: 15px;
        margin-bottom: 2rem;
        text-align: center;
        color: white;
    }
    .main-header h1 {
        margin: 0;
        font-size: 2.5rem;
    }
    .main-header p {
        margin: 0.5rem 0 0 0;
        opacity: 0.9;
    }
    .main-header a {
        color: #ffd700;
        text-decoration: none;
        font-weight: bold;
    }
    .main-header a:hover {
        text-decoration: underline;
    }
    .stButton > button {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border: none;
        padding: 0.75rem 2rem;
        font-size: 1.1rem;
        border-radius: 10px;
        transition: all 0.3s ease;
        width: 100%;
    }
    .stButton > button:hover {
        transform: translateY(-2px);
        box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
    }
    .info-box {
        background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        padding: 1.5rem;
        border-radius: 10px;
        margin: 1rem 0;
    }
    .audio-container {
        background: #f8f9fa;
        padding: 1.5rem;
        border-radius: 10px;
        margin: 1rem 0;
        border: 2px solid #667eea;
    }
    .status-success {
        color: #28a745;
        font-weight: bold;
    }
    .status-error {
        color: #dc3545;
        font-weight: bold;
    }
    .example-text {
        background: #f0f2f6;
        padding: 0.5rem 1rem;
        border-radius: 5px;
        margin: 0.25rem 0;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    .example-text:hover {
        background: #e0e2e6;
    }
</style>
""", unsafe_allow_html=True)

# Header
st.markdown("""
<div class="main-header">
    <h1>🎀 VibeVoice TTS Tester</h1>
    <p>Test the VibeVoice-Realtime-0.5B Text-to-Speech Model</p>
    <p style="margin-top: 1rem; font-size: 0.9rem;">
        <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a>
    </p>
</div>
""", unsafe_allow_html=True)

# Initialize session state
if 'audio_history' not in st.session_state:
    st.session_state.audio_history = []
if 'client' not in st.session_state:
    st.session_state.client = None
if 'connection_status' not in st.session_state:
    st.session_state.connection_status = None
if 'current_text' not in st.session_state:
    st.session_state.current_text = ""

# Sidebar
with st.sidebar:
    st.markdown("### βš™οΈ Settings")
    
    # Connection status
    st.markdown("---")
    st.markdown("### πŸ”Œ Connection Status")
    
    if st.button("πŸ”„ Test Connection", use_container_width=True):
        with st.spinner("Connecting to VibeVoice API..."):
            try:
                client = Client("anycoderapps/VibeVoice-Realtime-0.5B")
                st.session_state.client = client
                st.session_state.connection_status = "connected"
                st.success("βœ… Connected successfully!")
            except Exception as e:
                st.session_state.connection_status = "error"
                st.error(f"❌ Connection failed: {str(e)}")
    
    if st.session_state.connection_status == "connected":
        st.markdown('<p class="status-success">● Connected</p>', unsafe_allow_html=True)
    elif st.session_state.connection_status == "error":
        st.markdown('<p class="status-error">● Disconnected</p>', unsafe_allow_html=True)
    else:
        st.markdown('<p style="color: #6c757d;">● Not tested</p>', unsafe_allow_html=True)
    
    st.markdown("---")
    st.markdown("### πŸ“š About")
    st.markdown("""
    This app allows you to test the **VibeVoice-Realtime-0.5B** 
    text-to-speech model hosted on Hugging Face Spaces.
    
    **Features:**
    - 🎯 Real-time TTS generation
    - 🎡 Audio playback & download
    - πŸ“ Example prompts
    - πŸ“Š Generation history
    """)
    
    st.markdown("---")
    st.markdown("### πŸ”— Links")
    st.markdown("[VibeVoice Space](https://huggingface.co/spaces/anycoderapps/VibeVoice-Realtime-0.5B)")
    
    # Clear history button
    st.markdown("---")
    if st.button("πŸ—‘οΈ Clear History", use_container_width=True):
        st.session_state.audio_history = []
        st.rerun()

# Main content
col1, col2 = st.columns([2, 1])

with col1:
    st.markdown("### πŸ“ Enter Your Text")
    
    # Text input
    text_input = st.text_area(
        "Text to synthesize",
        value=st.session_state.current_text,
        placeholder="Enter the text you want to convert to speech...",
        height=150,
        help="Enter any text and the TTS model will convert it to natural-sounding speech."
    )
    
    # Character count
    char_count = len(text_input)
    st.caption(f"Characters: {char_count}")
    
    # Generate button
    generate_button = st.button("🎀 Generate Speech", use_container_width=True, type="primary")

with col2:
    st.markdown("### πŸ’‘ Example Prompts")
    
    example_texts = [
        "Hello! Welcome to VibeVoice, the next generation text-to-speech system.",
        "The quick brown fox jumps over the lazy dog.",
        "Artificial intelligence is transforming the way we interact with technology.",
        "Good morning! I hope you have a wonderful day ahead.",
        "This is a test of the emergency broadcast system.",
    ]
    
    for i, example in enumerate(example_texts):
        if st.button(f"πŸ“Œ Example {i+1}", key=f"example_{i}", use_container_width=True):
            st.session_state.current_text = example
            st.rerun()

# Generate speech
if generate_button:
    if not text_input.strip():
        st.error("⚠️ Please enter some text to synthesize.")
    else:
        with st.spinner("🎡 Generating speech... This may take a moment."):
            try:
                # Initialize client if not already done
                if st.session_state.client is None:
                    st.session_state.client = Client("anycoderapps/VibeVoice-Realtime-0.5B")
                    st.session_state.connection_status = "connected"
                
                client = st.session_state.client
                
                # Call the API
                start_time = time.time()
                result = client.predict(
                    text=text_input,
                    api_name="/predict"
                )
                end_time = time.time()
                
                generation_time = round(end_time - start_time, 2)
                
                # Handle the result
                if result:
                    st.success(f"βœ… Speech generated successfully in {generation_time}s!")
                    
                    # Read audio bytes for storage
                    audio_bytes = None
                    if os.path.exists(result):
                        with open(result, 'rb') as audio_file:
                            audio_bytes = audio_file.read()
                    
                    # Store in history with audio bytes
                    st.session_state.audio_history.insert(0, {
                        'text': text_input[:100] + "..." if len(text_input) > 100 else text_input,
                        'full_text': text_input,
                        'audio_bytes': audio_bytes,
                        'timestamp': time.strftime("%H:%M:%S"),
                        'generation_time': generation_time
                    })
                    
                    # Keep only last 10 items
                    st.session_state.audio_history = st.session_state.audio_history[:10]
                    
                    # Display audio
                    st.markdown("### 🎡 Generated Audio")
                    
                    if audio_bytes:
                        st.audio(audio_bytes, format='audio/wav')
                        
                        # Download button
                        st.download_button(
                            label="⬇️ Download Audio",
                            data=audio_bytes,
                            file_name="vibevoice_output.wav",
                            mime="audio/wav",
                            use_container_width=True
                        )
                    else:
                        st.warning("Audio file path returned but file not accessible.")
                        st.info(f"Result path: {result}")
                else:
                    st.error("❌ No audio was generated. Please try again.")
                    
            except Exception as e:
                st.error(f"❌ Error generating speech: {str(e)}")
                st.session_state.connection_status = "error"
                st.session_state.client = None  # Reset client on error
                
                # Show troubleshooting tips
                with st.expander("πŸ”§ Troubleshooting Tips"):
                    st.markdown("""
                    1. **Check the Space**: Make sure the [VibeVoice Space](https://huggingface.co/spaces/anycoderapps/VibeVoice-Realtime-0.5B) is running.
                    2. **Wait and Retry**: The Space might be starting up. Wait a minute and try again.
                    3. **Shorter Text**: Try with a shorter text input.
                    4. **Refresh Connection**: Click "Test Connection" in the sidebar.
                    """)

# Display history
st.markdown("---")
st.markdown("### πŸ“Š Generation History")

if st.session_state.audio_history:
    for i, item in enumerate(st.session_state.audio_history):
        with st.expander(f"πŸ• {item['timestamp']} - {item['text']}", expanded=(i == 0)):
            col_a, col_b = st.columns([3, 1])
            with col_a:
                st.markdown(f"**Text:** {item.get('full_text', item['text'])}")
                st.caption(f"Generation time: {item['generation_time']}s")
            with col_b:
                if item.get('audio_bytes'):
                    st.audio(item['audio_bytes'], format='audio/wav')
                    st.download_button(
                        label="⬇️",
                        data=item['audio_bytes'],
                        file_name=f"vibevoice_{item['timestamp'].replace(':', '-')}.wav",
                        mime="audio/wav",
                        key=f"download_{i}",
                        use_container_width=True
                    )
else:
    st.info("No audio generated yet. Enter some text and click 'Generate Speech' to get started!")

# Footer
st.markdown("---")
st.markdown("""
<div style="text-align: center; color: #6c757d; padding: 1rem;">
    <p>Powered by <a href="https://huggingface.co/spaces/anycoderapps/VibeVoice-Realtime-0.5B" target="_blank">VibeVoice-Realtime-0.5B</a></p>
    <p style="font-size: 0.9rem;">
        <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a>
    </p>
</div>
""", unsafe_allow_html=True)