Aziz3 commited on
Commit
a3bc287
·
1 Parent(s): 9154e2d

add file upload

Browse files
Files changed (1) hide show
  1. streamlit_app.py +24 -17
streamlit_app.py CHANGED
@@ -286,7 +286,14 @@ def main():
286
 
287
  # Input section
288
  st.subheader("📹 Video Input")
289
-
 
 
 
 
 
 
 
290
  # Sample URLs for testing
291
  with st.expander("🧪 Test with sample videos"):
292
  st.markdown("""
@@ -301,32 +308,32 @@ def main():
301
  placeholder="https://example.com/video.mp4",
302
  help="Must be a publicly accessible video URL"
303
  )
304
-
305
  # Process button
306
  if st.button("🚀 Analyze Accent", type="primary"):
307
- if not video_url.strip():
308
- st.error("⚠️ Please enter a video URL")
309
  return
310
-
311
- if not video_url.startswith(('http://', 'https://')):
312
  st.error("⚠️ Please enter a valid URL starting with http:// or https://")
313
  return
314
-
315
- # Initialize detector and progress tracking
316
  detector = get_detector()
317
  temp_files = []
318
-
319
  try:
320
- # Progress bar
321
  progress_bar = st.progress(0)
322
  status_text = st.empty()
323
-
324
- # Step 1: Download video
325
- status_text.text("📥 Downloading video...")
326
- progress_bar.progress(20)
327
- video_path = detector.download_video(video_url)
328
- temp_files.append(video_path)
329
-
 
 
 
 
 
330
  # Step 2: Extract audio
331
  status_text.text("🎵 Extracting audio...")
332
  progress_bar.progress(50)
 
286
 
287
  # Input section
288
  st.subheader("📹 Video Input")
289
+
290
+ # File upload option
291
+ uploaded_file = st.file_uploader(
292
+ "Or upload a local video/audio file (MP4, WAV, MP3, etc.):",
293
+ type=["mp4", "mov", "avi", "wav", "mp3", "m4a", "aac", "ogg"],
294
+ help="Upload a file directly if you can't use a public URL."
295
+ )
296
+
297
  # Sample URLs for testing
298
  with st.expander("🧪 Test with sample videos"):
299
  st.markdown("""
 
308
  placeholder="https://example.com/video.mp4",
309
  help="Must be a publicly accessible video URL"
310
  )
311
+
312
  # Process button
313
  if st.button("🚀 Analyze Accent", type="primary"):
314
+ if not video_url.strip() and not uploaded_file:
315
+ st.error("⚠️ Please enter a video URL or upload a file")
316
  return
317
+ if video_url and not video_url.startswith(('http://', 'https://')):
 
318
  st.error("⚠️ Please enter a valid URL starting with http:// or https://")
319
  return
 
 
320
  detector = get_detector()
321
  temp_files = []
 
322
  try:
 
323
  progress_bar = st.progress(0)
324
  status_text = st.empty()
325
+ if uploaded_file:
326
+ # Save uploaded file to a temp file
327
+ suffix = os.path.splitext(uploaded_file.name)[1]
328
+ with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as f:
329
+ f.write(uploaded_file.read())
330
+ video_path = f.name
331
+ temp_files.append(video_path)
332
+ else:
333
+ status_text.text("📥 Downloading video...")
334
+ progress_bar.progress(20)
335
+ video_path = detector.download_video(video_url)
336
+ temp_files.append(video_path)
337
  # Step 2: Extract audio
338
  status_text.text("🎵 Extracting audio...")
339
  progress_bar.progress(50)