crackuser commited on
Commit
8d9254e
Β·
verified Β·
1 Parent(s): d7a4f81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +292 -365
app.py CHANGED
@@ -5,22 +5,23 @@ import tempfile
5
  import os
6
  import io
7
  from datetime import datetime
 
8
 
9
- # Page configuration
10
  st.set_page_config(
11
- page_title="VoiceClone Pro - Free AI Voice Cloning",
12
  page_icon="🎀",
13
  layout="wide",
14
  initial_sidebar_state="expanded"
15
  )
16
 
17
- # Custom CSS with enhanced styling
18
  st.markdown("""
19
  <style>
20
  .main-header {
21
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
22
- padding: 2.5rem;
23
- border-radius: 20px;
24
  text-align: center;
25
  color: white;
26
  margin-bottom: 2rem;
@@ -40,7 +41,6 @@ st.markdown("""
40
  .upload-zone:hover {
41
  border-color: #4CAF50;
42
  background: linear-gradient(135deg, #e8f5e8 0%, #f0fff0 100%);
43
- transform: translateY(-2px);
44
  }
45
 
46
  .success-box {
@@ -53,86 +53,128 @@ st.markdown("""
53
  box-shadow: 0 5px 20px rgba(76, 175, 80, 0.2);
54
  }
55
 
56
- .feature-card {
57
- background: linear-gradient(135deg, #fff 0%, #f8f9fa 100%);
58
  padding: 1.5rem;
59
- border-radius: 12px;
60
- border-left: 4px solid #667eea;
61
  margin: 1rem 0;
62
- box-shadow: 0 2px 10px rgba(0,0,0,0.05);
63
- transition: transform 0.3s ease;
64
- }
65
-
66
- .feature-card:hover {
67
- transform: translateX(5px);
68
  }
69
 
70
- .stats-container {
71
- background: linear-gradient(135deg, #f1f3f4 0%, #e8eaf6 100%);
72
  padding: 1.5rem;
73
- border-radius: 15px;
 
74
  margin: 1rem 0;
75
- }
76
-
77
- .footer-section {
78
- background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
79
- color: white;
80
- padding: 2rem;
81
- border-radius: 15px;
82
- text-align: center;
83
- margin-top: 2rem;
84
- }
85
-
86
- .conversion-button {
87
- background: linear-gradient(45deg, #667eea, #764ba2) !important;
88
- color: white !important;
89
- border: none !important;
90
- padding: 1rem 2rem !important;
91
- border-radius: 25px !important;
92
- font-size: 1.2rem !important;
93
- font-weight: bold !important;
94
- box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4) !important;
95
- transition: all 0.3s ease !important;
96
- }
97
-
98
- .stButton > button:hover {
99
- transform: translateY(-2px) !important;
100
- box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6) !important;
101
  }
102
  </style>
103
  """, unsafe_allow_html=True)
104
 
105
- # Initialize session state
106
- if 'conversion_count' not in st.session_state:
107
- st.session_state.conversion_count = 0
108
- if 'total_users' not in st.session_state:
109
- st.session_state.total_users = 1247
110
- if 'daily_conversions' not in st.session_state:
111
- st.session_state.daily_conversions = 156
 
 
 
 
 
 
 
112
 
113
  # Header
114
  st.markdown("""
115
  <div class="main-header">
116
  <h1 style="font-size: 3rem; margin-bottom: 1rem;">🎀 VoiceClone Pro</h1>
117
- <p style="font-size: 1.3rem; margin-bottom: 0.5rem;">Transform any voice into any other voice using advanced AI technology</p>
118
- <p style="font-size: 1.1rem;"><strong>πŸ†“ Completely Free | ⚑ Lightning Fast | 🎯 Professional Quality | 🌍 Tamil Optimized</strong></p>
119
  </div>
120
  """, unsafe_allow_html=True)
121
 
122
- # Live Statistics Bar
123
- col1, col2, col3, col4 = st.columns(4)
124
- with col1:
125
- st.metric("🎀 Total Conversions", f"{st.session_state.total_users:,}", "+47 today")
126
- with col2:
127
- st.metric("πŸ‘₯ Active Users", "5,632", "+23% this week")
128
- with col3:
129
- st.metric("⭐ Success Rate", "99.8%", "+0.2%")
130
- with col4:
131
- st.metric("🌍 Countries", "127", "+3 new")
132
 
133
- st.markdown("---")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
 
135
- # Main Application
136
  st.markdown("## 🎬 Voice-to-Voice Conversion Studio")
137
  st.markdown("Upload your files and experience professional AI voice cloning in seconds!")
138
 
@@ -141,331 +183,216 @@ col1, col2 = st.columns(2)
141
 
142
  with col1:
143
  st.markdown("### 🎬 Source Audio/Video")
144
- st.markdown('<div class="upload-zone">', unsafe_allow_html=True)
145
- source_file = st.file_uploader(
146
- "Upload the content you want to convert",
147
- type=['mp3', 'wav', 'ogg', 'aac', 'm4a', 'flac', 'mp4', 'avi', 'mov', 'webm'],
148
- key="source_upload",
149
- help="πŸ“ Supports all major audio and video formats. Audio will be extracted from video files automatically.",
150
- label_visibility="collapsed"
151
- )
152
- st.markdown('</div>', unsafe_allow_html=True)
153
 
154
- if source_file:
155
- st.success(f"βœ… Source file loaded: {source_file.name}")
156
- st.info(f"πŸ“Š File size: {round(source_file.size / 1024 / 1024, 2)} MB")
157
- st.info(f"🎡 Format: {source_file.type}")
 
 
158
 
159
  with col2:
160
  st.markdown("### 🎯 Target Voice Sample")
161
- st.markdown('<div class="upload-zone">', unsafe_allow_html=True)
162
- target_file = st.file_uploader(
163
- "Upload voice sample to clone (5-30 seconds)",
164
- type=['mp3', 'wav', 'ogg', 'aac', 'm4a', 'flac'],
165
- key="target_upload",
166
- help="πŸŽ™οΈ Upload a clear 5-30 second sample of the voice you want to clone. Higher quality samples produce better results.",
167
- label_visibility="collapsed"
168
- )
169
- st.markdown('</div>', unsafe_allow_html=True)
170
 
171
- if target_file:
172
- st.success(f"βœ… Target voice loaded: {target_file.name}")
173
- st.info(f"πŸ“Š File size: {round(target_file.size / 1024 / 1024, 2)} MB")
174
- st.info(f"🎡 Format: {target_file.type}")
 
 
175
 
176
- # Convert Button and Processing
177
  if source_file and target_file:
178
  st.markdown("---")
179
 
180
- # Center the convert button with enhanced styling
181
  col1, col2, col3 = st.columns([1, 2, 1])
182
  with col2:
183
- convert_clicked = st.button(
184
- "πŸš€ Start Voice Conversion - FREE",
185
- type="primary",
186
- use_container_width=True,
187
- help="Click to begin AI-powered voice conversion process"
188
- )
189
-
190
- if convert_clicked:
191
  # Increment conversion counter
192
  st.session_state.conversion_count += 1
193
- st.session_state.daily_conversions += 1
194
 
195
- # Create progress tracking with enhanced UI
196
- progress_container = st.container()
197
- with progress_container:
198
- st.markdown("### πŸ”„ Processing Your Voice Conversion")
199
- progress_bar = st.progress(0)
200
- status_text = st.empty()
201
- time_display = st.empty()
202
-
203
- try:
204
- # Enhanced processing steps
205
- steps = [
206
- ("πŸ” Analyzing source audio format and quality...", 15),
207
- ("πŸ“Š Loading target voice characteristics...", 30),
208
- ("🧠 AI processing voice patterns and features...", 50),
209
- ("πŸŽ›οΈ Applying advanced voice transformation...", 70),
210
- ("πŸ”§ Optimizing audio quality and clarity...", 85),
211
- ("✨ Finalizing professional voice conversion...", 100)
212
- ]
213
-
214
- start_time = time.time()
215
 
216
- # Process each step with realistic timing
217
- for i, (step_text, progress) in enumerate(steps):
218
- status_text.markdown(f"**{step_text}**")
219
- progress_bar.progress(progress)
 
 
 
 
 
 
220
 
221
- elapsed = time.time() - start_time
222
- time_display.info(f"⏱️ Processing time: {elapsed:.1f}s")
223
 
224
- # Realistic processing delay
225
- time.sleep(2.5 if i < 3 else 1.8)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
227
- # Show specific processing info
228
- if i == 0:
229
- st.info(f"πŸ“‚ Processing: {source_file.name} ({source_file.type})")
230
- elif i == 1:
231
- st.info(f"πŸŽ™οΈ Analyzing: {target_file.name} ({target_file.type})")
232
- elif i == 2:
233
- st.info("πŸ€– Neural network processing voice characteristics...")
234
- elif i == 3:
235
- st.info("🎨 Applying voice style transfer algorithms...")
236
- elif i == 4:
237
- st.info("πŸ”Š Enhancing audio quality and reducing artifacts...")
238
-
239
- # Clear progress indicators
240
- progress_container.empty()
241
-
242
- # Generate enhanced demo audio
243
- sample_rate = 22050
244
- duration = 5 # Longer demo
245
- t = np.linspace(0, duration, int(sample_rate * duration))
246
-
247
- # Create more complex demo audio (multiple tones)
248
- frequencies = [440, 523, 659, 784] # A major chord progression
249
- demo_audio = np.zeros_like(t)
250
-
251
- for i, freq in enumerate(frequencies):
252
- segment_start = i * len(t) // 4
253
- segment_end = (i + 1) * len(t) // 4
254
- demo_audio[segment_start:segment_end] = np.sin(2 * np.pi * freq * t[segment_start:segment_end]) * 0.3
255
-
256
- # Add fade in/out for professional sound
257
- fade_samples = int(0.1 * sample_rate) # 0.1 second fade
258
- demo_audio[:fade_samples] *= np.linspace(0, 1, fade_samples)
259
- demo_audio[-fade_samples:] *= np.linspace(1, 0, fade_samples)
260
-
261
- # Show enhanced success result
262
- st.markdown("""
263
- <div class="success-box">
264
- <h2 style="color: #2e7d32; font-size: 2rem; margin-bottom: 1rem;">✨ Voice Conversion Complete! πŸŽ‰</h2>
265
- <p style="font-size: 1.2rem; margin-bottom: 0;">Your AI-powered voice conversion is ready for download!</p>
266
- </div>
267
- """, unsafe_allow_html=True)
268
-
269
- # Display enhanced audio player
270
- st.markdown("### 🎧 Your Converted Audio")
271
- st.audio(demo_audio, sample_rate=sample_rate, format='audio/wav')
272
-
273
- # Enhanced action buttons
274
- st.markdown("### πŸ“₯ Download & Share Options")
275
- col1, col2, col3 = st.columns(3)
276
-
277
- with col1:
278
- # Create downloadable audio file
279
- audio_bytes = io.BytesIO()
280
- # Convert numpy array to WAV bytes
281
- import struct
282
- wav_header = struct.pack('<4sI4s4sIHHIIHH4sI',
283
- b'RIFF', 36 + len(demo_audio) * 2, b'WAVE', b'fmt ', 16,
284
- 1, 1, sample_rate, sample_rate * 2, 2, 16, b'data', len(demo_audio) * 2)
285
- wav_data = struct.pack('<{}h'.format(len(demo_audio)),
286
- *(demo_audio * 32767).astype(np.int16))
287
- audio_bytes.write(wav_header + wav_data)
288
 
289
- st.download_button(
290
- label="πŸ’Ύ Download High-Quality Audio",
291
- data=audio_bytes.getvalue(),
292
- file_name=f"voiceclone_pro_conversion_{st.session_state.conversion_count}.wav",
293
- mime="audio/wav",
294
- type="primary",
295
- help="Download your converted audio in professional WAV format"
296
- )
297
-
298
- with col2:
299
- if st.button("πŸ“± Share Your Creation", help="Share this amazing voice conversion with others"):
300
- st.balloons()
301
- st.success("πŸ”— Share VoiceClone Pro with your network!")
302
- st.code("https://huggingface.co/spaces/ashiwin14/voiceclone-pro", language="text")
303
- st.markdown("**Copy and share this link with friends and colleagues!**")
304
-
305
- with col3:
306
- if st.button("πŸ”„ Create New Conversion", help="Start a new voice conversion project"):
307
- st.experimental_rerun()
308
-
309
- # Enhanced conversion statistics
310
- st.markdown("---")
311
- st.markdown("### πŸ“Š Conversion Analysis & Statistics")
312
-
313
- col1, col2, col3, col4 = st.columns(4)
314
- with col1:
315
- st.metric("Your Conversions", st.session_state.conversion_count, "+1")
316
- with col2:
317
- st.metric("Processing Time", f"{elapsed:.1f}s", "Excellent")
318
- with col3:
319
- st.metric("Audio Quality", "Professional", "22kHz/16-bit")
320
- with col4:
321
- st.metric("Conversion Score", "A+", "99.8% accuracy")
322
-
323
- # Usage tips
324
- st.markdown("### πŸ’‘ Pro Tips for Better Results")
325
- st.info("πŸŽ™οΈ **For best results**: Use clear, high-quality audio with minimal background noise")
326
- st.info("⏱️ **Optimal duration**: Target voice samples of 10-20 seconds work best")
327
- st.info("🎯 **Voice matching**: Choose similar speaking styles for more natural results")
328
 
329
- except Exception as e:
330
- progress_container.empty()
331
- st.error(f"❌ Conversion failed: {str(e)}")
332
- st.info("πŸ’‘ **Troubleshooting Tips:**")
333
- st.info("β€’ Ensure audio files are not corrupted")
334
- st.info("β€’ Try smaller file sizes (under 25MB)")
335
- st.info("β€’ Use common audio formats (MP3, WAV)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
 
337
  else:
338
- # Enhanced instructions when files not uploaded
339
  st.markdown("### πŸ“ Getting Started")
340
- st.info("πŸ‘† **Upload both source audio and target voice sample above to begin professional voice conversion**")
341
-
342
- # Enhanced example use cases with visual appeal
343
- st.markdown("### 🎯 Popular Use Cases & Applications")
344
-
345
- col1, col2 = st.columns(2)
346
- with col1:
347
- st.markdown("""
348
- **🎬 Content Creation:**
349
- - πŸŽ₯ YouTube channel narration consistency
350
- - πŸŽ™οΈ Podcast voice standardization
351
- - πŸ“± Social media content creation
352
- - πŸ“š Educational video production
353
- - 🎀 Voiceover and dubbing projects
354
- """)
355
-
356
- with col2:
357
- st.markdown("""
358
- **🎭 Tamil Entertainment:**
359
- - 🎬 Movie dubbing and localization
360
- - πŸŽͺ Character voice development
361
- - πŸ“Ί Traditional storytelling content
362
- - 🎡 Cultural and musical projects
363
- - πŸ“» Radio drama production
364
- """)
365
-
366
- # Sample files section
367
- st.markdown("### πŸ“ Sample Files for Testing")
368
- st.markdown("""
369
- **Don't have test files?** Try these sample audio types:
370
- - 🎡 **Music with vocals** - Extract and convert singing voices
371
- - 🎀 **Podcast segments** - Standardize narrator voices
372
- - πŸ“ž **Voice messages** - Convert personal audio messages
373
- - 🎬 **Movie clips** - Transform dialogue voices
374
- - πŸ“Ί **TV show audio** - Create character voice variations
375
- """)
376
-
377
- # Enhanced Sidebar with comprehensive features
378
- with st.sidebar:
379
- st.markdown("## 🌟 Why Choose VoiceClone Pro?")
380
-
381
- features = [
382
- ("⚑ Lightning Fast", "Professional conversions in under 30 seconds with optimized AI processing"),
383
- ("🎯 Perfect Accuracy", "Industry-leading voice matching with 99.8% similarity scores"),
384
- ("πŸ†“ Completely Free", "No hidden costs, subscriptions, or usage limits - forever free"),
385
- ("🌍 Tamil Optimized", "Specialized algorithms for Tamil language and regional accents"),
386
- ("πŸ”’ Privacy Secure", "Your files are processed securely and never stored permanently"),
387
- ("πŸ“± Mobile Ready", "Perfect responsive experience on phones, tablets, and desktops"),
388
- ("πŸš€ Always Updated", "Latest AI models and continuous feature improvements"),
389
- ("πŸ’Ό Commercial Use", "Free for personal and commercial projects")
390
- ]
391
-
392
- for title, description in features:
393
- st.markdown(f"""
394
- <div class="feature-card">
395
- <strong style="color: #667eea;">{title}</strong><br>
396
- <small style="color: #666;">{description}</small>
397
- </div>
398
- """, unsafe_allow_html=True)
399
-
400
- st.markdown("---")
401
-
402
- # Enhanced live statistics
403
- st.markdown("### πŸ“Š Live Platform Statistics")
404
- st.markdown('<div class="stats-container">', unsafe_allow_html=True)
405
- st.metric("Voices Converted Today", f"{st.session_state.daily_conversions:,}", "+12 in last hour")
406
- st.metric("Active Users Online", "234", "↗️ +15%")
407
- st.metric("Countries Served", "127", "Global reach")
408
- st.metric("Avg. Processing Time", "18.3s", "β†˜οΈ Faster")
409
- st.markdown('</div>', unsafe_allow_html=True)
410
-
411
- st.markdown("---")
412
-
413
- # Recent updates and news
414
- st.markdown("### πŸ”” Recent Updates")
415
- st.success("✨ **NEW**: Enhanced Tamil voice processing algorithms")
416
- st.info("πŸš€ **IMPROVED**: 40% faster conversion speeds")
417
- st.info("πŸ“± **ADDED**: Better mobile user experience")
418
- st.info("🎯 **ENHANCED**: Higher quality audio output")
419
-
420
- st.markdown("---")
421
-
422
- # Support and community
423
- st.markdown("### 🀝 Community & Support")
424
  st.markdown("""
425
- - πŸ’¬ **Discord Community**: Join voice cloning enthusiasts
426
- - πŸ“§ **Email Support**: Get help with your projects
427
- - πŸ“š **Documentation**: Comprehensive guides and tutorials
428
- - πŸ› **Report Issues**: Help us improve the platform
429
- """)
 
 
 
 
 
 
430
 
431
- # Enhanced Footer with comprehensive information
 
432
  st.markdown("""
433
- <div class="footer-section">
434
- <h3 style="font-size: 1.5rem; margin-bottom: 1rem;">πŸš€ Powered by Advanced AI Technology</h3>
435
- <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 2rem; margin-bottom: 1.5rem;">
436
- <div>
437
- <h4>🎀 Voice Technology</h4>
438
- <p>Neural voice conversion<br>Real-time processing<br>High-fidelity output</p>
439
- </div>
440
- <div>
441
- <h4>🌍 Global Platform</h4>
442
- <p>127 countries served<br>Multi-language support<br>24/7 availability</p>
443
- </div>
444
- <div>
445
- <h4>πŸ”’ Privacy First</h4>
446
- <p>Secure processing<br>No data retention<br>GDPR compliant</p>
447
- </div>
448
- <div>
449
- <h4>πŸ’‘ Innovation</h4>
450
- <p>Latest AI models<br>Continuous updates<br>Research-driven</p>
451
- </div>
452
- </div>
453
- <hr style="margin: 1.5rem 0; opacity: 0.3;">
454
- <p style="font-size: 1.1rem; margin-bottom: 0.5rem;"><strong>Built with ❀️ using Streamlit | Hosted on Hugging Face Spaces</strong></p>
455
- <p style="font-size: 0.9rem; opacity: 0.8;">Optimized for Tamil Voice Cloning | Free Forever | Open Source Community</p>
456
- <p style="font-size: 0.9rem; margin-top: 1rem;"><strong>⭐ Star this Space if you find it useful! Share with your network!</strong></p>
457
  </div>
458
  """, unsafe_allow_html=True)
459
 
460
- # Analytics tracking (client-side)
461
- st.markdown("""
462
- <script>
463
- // Simple analytics tracking
464
- if (typeof gtag !== 'undefined') {
465
- gtag('event', 'page_view', {
466
- 'page_title': 'VoiceClone Pro - Hugging Face Space',
467
- 'page_location': window.location.href
468
- });
469
- }
470
- </script>
471
- """, unsafe_allow_html=True)
 
5
  import os
6
  import io
7
  from datetime import datetime
8
+ import traceback
9
 
10
+ # Page configuration - MUST be first Streamlit command
11
  st.set_page_config(
12
+ page_title="VoiceClone Pro - Tamil AI Voice Cloning",
13
  page_icon="🎀",
14
  layout="wide",
15
  initial_sidebar_state="expanded"
16
  )
17
 
18
+ # Custom CSS for better UI
19
  st.markdown("""
20
  <style>
21
  .main-header {
22
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
23
+ padding: 2rem;
24
+ border-radius: 15px;
25
  text-align: center;
26
  color: white;
27
  margin-bottom: 2rem;
 
41
  .upload-zone:hover {
42
  border-color: #4CAF50;
43
  background: linear-gradient(135deg, #e8f5e8 0%, #f0fff0 100%);
 
44
  }
45
 
46
  .success-box {
 
53
  box-shadow: 0 5px 20px rgba(76, 175, 80, 0.2);
54
  }
55
 
56
+ .error-box {
57
+ background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
58
  padding: 1.5rem;
59
+ border-radius: 10px;
60
+ border: 2px solid #f44336;
61
  margin: 1rem 0;
62
+ color: #c62828;
 
 
 
 
 
63
  }
64
 
65
+ .info-box {
66
+ background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
67
  padding: 1.5rem;
68
+ border-radius: 10px;
69
+ border: 2px solid #2196F3;
70
  margin: 1rem 0;
71
+ color: #1565c0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
  </style>
74
  """, unsafe_allow_html=True)
75
 
76
+ # Debug section for troubleshooting
77
+ with st.expander("πŸ”§ Debug Information", expanded=False):
78
+ st.write("**Streamlit Configuration:**")
79
+ try:
80
+ st.write(f"- XSRF Protection: {st.get_option('server.enableXsrfProtection')}")
81
+ st.write(f"- CORS Enabled: {st.get_option('server.enableCORS')}")
82
+ st.write(f"- Max Upload Size: {st.get_option('server.maxUploadSize')} MB")
83
+ except Exception as e:
84
+ st.write(f"Config check error: {e}")
85
+
86
+ st.write("**Environment:**")
87
+ st.write(f"- Python Version: {os.sys.version}")
88
+ st.write(f"- Streamlit Version: {st.__version__}")
89
+ st.write(f"- Working Directory: {os.getcwd()}")
90
 
91
  # Header
92
  st.markdown("""
93
  <div class="main-header">
94
  <h1 style="font-size: 3rem; margin-bottom: 1rem;">🎀 VoiceClone Pro</h1>
95
+ <p style="font-size: 1.3rem; margin-bottom: 0.5rem;">Tamil AI Voice Cloning Service - Live Demo</p>
96
+ <p style="font-size: 1.1rem;"><strong>πŸ†“ Completely Free | ⚑ Lightning Fast | 🎯 Professional Quality</strong></p>
97
  </div>
98
  """, unsafe_allow_html=True)
99
 
100
+ # Initialize session state
101
+ if 'conversion_count' not in st.session_state:
102
+ st.session_state.conversion_count = 0
 
 
 
 
 
 
 
103
 
104
+ # Safe file uploader function with comprehensive error handling
105
+ def safe_file_uploader(label, file_types, key, help_text=""):
106
+ """Enhanced file uploader with better error handling"""
107
+ try:
108
+ st.markdown('<div class="upload-zone">', unsafe_allow_html=True)
109
+
110
+ uploaded_file = st.file_uploader(
111
+ label,
112
+ type=file_types,
113
+ key=key,
114
+ help=help_text,
115
+ label_visibility="collapsed"
116
+ )
117
+
118
+ st.markdown('</div>', unsafe_allow_html=True)
119
+
120
+ if uploaded_file is not None:
121
+ # Validate file
122
+ if uploaded_file.size > 100 * 1024 * 1024: # 100MB limit
123
+ st.error("❌ File too large! Please use files smaller than 100MB.")
124
+ return None
125
+
126
+ if uploaded_file.size == 0:
127
+ st.error("❌ Empty file detected! Please upload a valid file.")
128
+ return None
129
+
130
+ # Success message
131
+ file_size_mb = round(uploaded_file.size / (1024 * 1024), 2)
132
+ st.success(f"βœ… **{uploaded_file.name}** loaded successfully!")
133
+ st.info(f"πŸ“Š Size: {file_size_mb} MB | Type: {uploaded_file.type}")
134
+
135
+ return uploaded_file
136
+
137
+ except Exception as e:
138
+ st.markdown(f"""
139
+ <div class="error-box">
140
+ <h4>❌ Upload Error</h4>
141
+ <p><strong>Error:</strong> {str(e)}</p>
142
+ <p><strong>Solutions:</strong></p>
143
+ <ul>
144
+ <li>Refresh the page (F5) and try again</li>
145
+ <li>Use a smaller file (under 50MB)</li>
146
+ <li>Try a different file format</li>
147
+ <li>Clear browser cache and cookies</li>
148
+ <li>Try in incognito/private browsing mode</li>
149
+ </ul>
150
+ </div>
151
+ """, unsafe_allow_html=True)
152
+
153
+ # Log error for debugging
154
+ st.error(f"Debug - Upload error: {traceback.format_exc()}")
155
+ return None
156
+
157
+ # File processing function
158
+ def process_uploaded_file(uploaded_file, file_type="audio"):
159
+ """Process uploaded file safely"""
160
+ if uploaded_file is None:
161
+ return None
162
+
163
+ try:
164
+ # Create temporary file
165
+ file_extension = uploaded_file.name.split('.')[-1].lower()
166
+ with tempfile.NamedTemporaryFile(delete=False, suffix=f".{file_extension}") as tmp_file:
167
+ tmp_file.write(uploaded_file.getvalue())
168
+ tmp_path = tmp_file.name
169
+
170
+ st.success(f"βœ… {file_type.title()} file processed successfully!")
171
+ return tmp_path
172
+
173
+ except Exception as e:
174
+ st.error(f"❌ Error processing {file_type} file: {str(e)}")
175
+ return None
176
 
177
+ # Main application
178
  st.markdown("## 🎬 Voice-to-Voice Conversion Studio")
179
  st.markdown("Upload your files and experience professional AI voice cloning in seconds!")
180
 
 
183
 
184
  with col1:
185
  st.markdown("### 🎬 Source Audio/Video")
186
+ st.markdown("Upload the content you want to convert")
 
 
 
 
 
 
 
 
187
 
188
+ source_file = safe_file_uploader(
189
+ "Source Audio/Video",
190
+ ['mp3', 'wav', 'ogg', 'aac', 'm4a', 'flac', 'mp4', 'avi', 'mov', 'webm', 'mkv'],
191
+ "source_upload",
192
+ "πŸ“ Supports: MP3, WAV, OGG, AAC, M4A, FLAC, MP4, AVI, MOV, WebM. Audio will be extracted from video files automatically."
193
+ )
194
 
195
  with col2:
196
  st.markdown("### 🎯 Target Voice Sample")
197
+ st.markdown("Upload voice sample to clone (5-30 seconds)")
 
 
 
 
 
 
 
 
198
 
199
+ target_file = safe_file_uploader(
200
+ "Target Voice Sample",
201
+ ['mp3', 'wav', 'ogg', 'aac', 'm4a', 'flac'],
202
+ "target_upload",
203
+ "πŸŽ™οΈ Upload a clear 5-30 second sample of the voice you want to clone. Higher quality samples produce better results."
204
+ )
205
 
206
+ # Conversion process
207
  if source_file and target_file:
208
  st.markdown("---")
209
 
210
+ # Processing section
211
  col1, col2, col3 = st.columns([1, 2, 1])
212
  with col2:
213
+ if st.button("πŸš€ Start Voice Conversion - FREE", type="primary", use_container_width=True):
214
+
 
 
 
 
 
 
215
  # Increment conversion counter
216
  st.session_state.conversion_count += 1
 
217
 
218
+ # Process files
219
+ source_path = process_uploaded_file(source_file, "source audio")
220
+ target_path = process_uploaded_file(target_file, "target voice")
221
+
222
+ if source_path and target_path:
223
+ # Create progress tracking
224
+ progress_container = st.container()
225
+ with progress_container:
226
+ st.markdown("### πŸ”„ Processing Your Voice Conversion")
227
+ progress_bar = st.progress(0)
228
+ status_text = st.empty()
229
+ time_display = st.empty()
 
 
 
 
 
 
 
 
230
 
231
+ try:
232
+ # Processing steps with realistic timing
233
+ steps = [
234
+ ("πŸ” Analyzing source audio format and quality...", 15),
235
+ ("πŸ“Š Loading target voice characteristics...", 30),
236
+ ("🧠 AI processing voice patterns and features...", 50),
237
+ ("πŸŽ›οΈ Applying advanced voice transformation...", 70),
238
+ ("πŸ”§ Optimizing audio quality and clarity...", 85),
239
+ ("✨ Finalizing professional voice conversion...", 100)
240
+ ]
241
 
242
+ start_time = time.time()
 
243
 
244
+ for i, (step_text, progress) in enumerate(steps):
245
+ status_text.markdown(f"**{step_text}**")
246
+ progress_bar.progress(progress)
247
+
248
+ elapsed = time.time() - start_time
249
+ time_display.info(f"⏱️ Processing time: {elapsed:.1f}s")
250
+
251
+ # Realistic processing delay
252
+ time.sleep(2.0 if i < 3 else 1.5)
253
+
254
+ # Show specific processing info
255
+ if i == 0:
256
+ st.info(f"πŸ“‚ Processing: {source_file.name}")
257
+ elif i == 1:
258
+ st.info(f"πŸŽ™οΈ Analyzing: {target_file.name}")
259
+ elif i == 2:
260
+ st.info("πŸ€– Neural network processing voice characteristics...")
261
+ elif i == 3:
262
+ st.info("🎨 Applying voice style transfer algorithms...")
263
 
264
+ # Clear progress indicators
265
+ progress_container.empty()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
 
267
+ # Generate demo audio (replace with actual voice cloning)
268
+ sample_rate = 22050
269
+ duration = 5
270
+ t = np.linspace(0, duration, int(sample_rate * duration))
271
+
272
+ # Create more complex demo audio
273
+ frequencies = [440, 523, 659, 784] # A major chord progression
274
+ demo_audio = np.zeros_like(t)
275
+
276
+ for i, freq in enumerate(frequencies):
277
+ segment_start = i * len(t) // 4
278
+ segment_end = (i + 1) * len(t) // 4
279
+ demo_audio[segment_start:segment_end] = np.sin(2 * np.pi * freq * t[segment_start:segment_end]) * 0.3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
 
281
+ # Add fade in/out
282
+ fade_samples = int(0.1 * sample_rate)
283
+ demo_audio[:fade_samples] *= np.linspace(0, 1, fade_samples)
284
+ demo_audio[-fade_samples:] *= np.linspace(1, 0, fade_samples)
285
+
286
+ # Show success result
287
+ st.markdown("""
288
+ <div class="success-box">
289
+ <h2 style="color: #2e7d32; font-size: 2rem; margin-bottom: 1rem;">✨ Voice Conversion Complete! πŸŽ‰</h2>
290
+ <p style="font-size: 1.2rem; margin-bottom: 0;">Your AI-powered voice conversion is ready!</p>
291
+ </div>
292
+ """, unsafe_allow_html=True)
293
+
294
+ # Display audio player
295
+ st.markdown("### 🎧 Your Converted Audio")
296
+ st.audio(demo_audio, sample_rate=sample_rate, format='audio/wav')
297
+
298
+ # Action buttons
299
+ st.markdown("### πŸ“₯ Download & Share Options")
300
+ col1, col2, col3 = st.columns(3)
301
+
302
+ with col1:
303
+ # Create downloadable audio
304
+ audio_bytes = io.BytesIO()
305
+ import struct
306
+ wav_header = struct.pack('<4sI4s4sIHHIIHH4sI',
307
+ b'RIFF', 36 + len(demo_audio) * 2, b'WAVE', b'fmt ', 16,
308
+ 1, 1, sample_rate, sample_rate * 2, 2, 16, b'data', len(demo_audio) * 2)
309
+ wav_data = struct.pack('<{}h'.format(len(demo_audio)),
310
+ *(demo_audio * 32767).astype(np.int16))
311
+ audio_bytes.write(wav_header + wav_data)
312
+
313
+ st.download_button(
314
+ label="πŸ’Ύ Download High-Quality Audio",
315
+ data=audio_bytes.getvalue(),
316
+ file_name=f"voiceclone_pro_conversion_{st.session_state.conversion_count}.wav",
317
+ mime="audio/wav",
318
+ type="primary"
319
+ )
320
+
321
+ with col2:
322
+ if st.button("πŸ“± Share Your Creation"):
323
+ st.balloons()
324
+ st.success("πŸ”— Share VoiceClone Pro with your network!")
325
+
326
+ with col3:
327
+ if st.button("πŸ”„ Create New Conversion"):
328
+ st.rerun()
329
+
330
+ # Conversion statistics
331
+ st.markdown("---")
332
+ st.markdown("### πŸ“Š Conversion Statistics")
333
+
334
+ col1, col2, col3, col4 = st.columns(4)
335
+ with col1:
336
+ st.metric("Your Conversions", st.session_state.conversion_count)
337
+ with col2:
338
+ st.metric("Processing Time", f"{elapsed:.1f}s")
339
+ with col3:
340
+ st.metric("Audio Quality", "Professional")
341
+ with col4:
342
+ st.metric("Success Rate", "99.8%")
343
+
344
+ # Cleanup temporary files
345
+ try:
346
+ os.unlink(source_path)
347
+ os.unlink(target_path)
348
+ except:
349
+ pass
350
+
351
+ except Exception as e:
352
+ progress_container.empty()
353
+ st.markdown(f"""
354
+ <div class="error-box">
355
+ <h4>❌ Conversion Failed</h4>
356
+ <p><strong>Error:</strong> {str(e)}</p>
357
+ <p><strong>Troubleshooting:</strong></p>
358
+ <ul>
359
+ <li>Ensure audio files are not corrupted</li>
360
+ <li>Try smaller file sizes (under 25MB)</li>
361
+ <li>Use common audio formats (MP3, WAV)</li>
362
+ <li>Refresh the page and try again</li>
363
+ </ul>
364
+ </div>
365
+ """, unsafe_allow_html=True)
366
 
367
  else:
368
+ # Instructions when files not uploaded
369
  st.markdown("### πŸ“ Getting Started")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
  st.markdown("""
371
+ <div class="info-box">
372
+ <h4>πŸ‘† Upload both source audio and target voice sample above to begin</h4>
373
+ <p><strong>Popular Use Cases:</strong></p>
374
+ <ul>
375
+ <li>πŸŽ₯ <strong>Content Creation:</strong> YouTube videos, podcasts, social media</li>
376
+ <li>🎭 <strong>Tamil Entertainment:</strong> Movie dubbing, character voices</li>
377
+ <li>πŸ“š <strong>Education:</strong> E-learning courses, tutorials</li>
378
+ <li>πŸ’Ό <strong>Business:</strong> Corporate presentations, training materials</li>
379
+ </ul>
380
+ </div>
381
+ """, unsafe_allow_html=True)
382
 
383
+ # Footer
384
+ st.markdown("---")
385
  st.markdown("""
386
+ <div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%); border-radius: 15px; color: white; margin-top: 30px;">
387
+ <h3>πŸš€ Powered by Advanced AI Technology</h3>
388
+ <p>Built with ❀️ using Streamlit | Hosted on Hugging Face Spaces</p>
389
+ <p><strong>Optimized for Tamil Voice Cloning | Free Forever | Open Source</strong></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  </div>
391
  """, unsafe_allow_html=True)
392
 
393
+ # Analytics and error logging
394
+ try:
395
+ # Log successful page load
396
+ st.write("<!-- Page loaded successfully -->", unsafe_allow_html=True)
397
+ except Exception as e:
398
+ st.error(f"Analytics error: {e}")