7H4M3R commited on
Commit
1643a16
Β·
verified Β·
1 Parent(s): 8265a8e

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +23 -22
src/streamlit_app.py CHANGED
@@ -25,15 +25,15 @@ MAX_LENGTH = RATE_HZ * MAX_SECONDS
25
  def download_video(url, output_dir="/app/tmp"):
26
  os.makedirs(output_dir, exist_ok=True)
27
  ydl_opts = {
28
- 'format': 'worstvideo[ext=mp4]+bestaudio[ext=m4a]/bestaudio',
29
- "outtmpl": os.path.join(output_dir, "video.%(ext)s"),
30
- "quiet": True,
31
- 'merge_output_format': 'mp4',
32
- 'quiet': True,
33
- 'noplaylist': True,
34
- 'nocheckcertificate': True,
35
- 'retries': 3,
36
- }
37
 
38
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
39
  ydl.download([url])
@@ -43,12 +43,12 @@ def extract_audio(input_path, output_dir="/app/tmp"):
43
  os.makedirs(output_dir, exist_ok=True)
44
  output_path = os.path.join(output_dir, "audio.mp3")
45
  (
46
- ffmpeg
47
- .input(input_path)
48
- .output(output_path, format='mp3', acodec='libmp3lame', audio_bitrate='192k')
49
- .overwrite_output()
50
- .run(quiet=True)
51
- )
52
  return output_path
53
 
54
  # Split files by chunks with == MAX_LENGTH size
@@ -104,20 +104,21 @@ if st.button("Analyze"):
104
  video_path = None
105
  output_dir="/app/tmp"
106
  os.makedirs(output_dir, exist_ok=True)
107
-
108
  if uploaded_file:
109
  video_path = os.path.join(output_dir, "video.mp4")
110
  with open(video_path, "wb") as f:
111
- f.write(uploaded_file.read())
112
  st.success("βœ… Video uploaded successfully.")
113
  elif video_url.strip():
114
  with st.spinner("Downloading video from URL..."):
115
  try:
116
  video_path = download_video(video_url)
117
- st.success(f"βœ… Video downloaded: {video_path}")
118
  except Exception as e:
119
  st.error(f"❌ Failed to download video: {e}")
120
- st.warning("Please enter a valid URL.")
 
 
121
  else:
122
  st.warning("⚠️ Please upload a video file or enter a valid URL.")
123
 
@@ -129,7 +130,7 @@ if st.button("Analyze"):
129
  st.write("Exists:", os.path.exists(audio_path))
130
 
131
  # with st.spinner("Transcribing with Whisper..."):
132
- # whisper_model = whisper.load_model("base")
133
  # result = whisper_model.transcribe(audio_path)
134
  # transcription = result['text']
135
  # transcription = "Hello There"
@@ -143,10 +144,10 @@ if st.button("Analyze"):
143
  waves = f"{np.concatenate(audio_df["audio"][:5].to_list())}"
144
  st.markdown("**Audio waves:**")
145
  st.text_area("Audio waves", waves, height=200)
146
-
147
  # audio_df = split_audio(audio_path)
148
  # print(np.concatenate(audio_df["audio"][:50].to_list()))
149
-
150
  accent_data = {"label": "American", "score": 0.9}
151
  accent = accent_data.get("label", "American")
152
  confidence = accent_data.get("score", 0.0)
 
25
  def download_video(url, output_dir="/app/tmp"):
26
  os.makedirs(output_dir, exist_ok=True)
27
  ydl_opts = {
28
+ 'format': 'worstvideo[ext=mp4]+bestaudio[ext=m4a]/bestaudio',
29
+ "outtmpl": os.path.join(output_dir, "video.%(ext)s"),
30
+ "quiet": True,
31
+ 'merge_output_format': 'mp4',
32
+ 'quiet': True,
33
+ 'noplaylist': True,
34
+ 'nocheckcertificate': True,
35
+ 'retries': 3,
36
+ }
37
 
38
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
39
  ydl.download([url])
 
43
  os.makedirs(output_dir, exist_ok=True)
44
  output_path = os.path.join(output_dir, "audio.mp3")
45
  (
46
+ ffmpeg
47
+ .input(input_path)
48
+ .output(output_path, format='mp3', acodec='libmp3lame', audio_bitrate='192k')
49
+ .overwrite_output()
50
+ .run(quiet=True)
51
+ )
52
  return output_path
53
 
54
  # Split files by chunks with == MAX_LENGTH size
 
104
  video_path = None
105
  output_dir="/app/tmp"
106
  os.makedirs(output_dir, exist_ok=True)
107
+
108
  if uploaded_file:
109
  video_path = os.path.join(output_dir, "video.mp4")
110
  with open(video_path, "wb") as f:
111
+ f.write(uploaded_file.read())
112
  st.success("βœ… Video uploaded successfully.")
113
  elif video_url.strip():
114
  with st.spinner("Downloading video from URL..."):
115
  try:
116
  video_path = download_video(video_url)
 
117
  except Exception as e:
118
  st.error(f"❌ Failed to download video: {e}")
119
+ else:
120
+ st.success(f"βœ… Video downloaded: {video_path}")
121
+
122
  else:
123
  st.warning("⚠️ Please upload a video file or enter a valid URL.")
124
 
 
130
  st.write("Exists:", os.path.exists(audio_path))
131
 
132
  # with st.spinner("Transcribing with Whisper..."):
133
+ # whisper_model = whisper.load_model("base")
134
  # result = whisper_model.transcribe(audio_path)
135
  # transcription = result['text']
136
  # transcription = "Hello There"
 
144
  waves = f"{np.concatenate(audio_df["audio"][:5].to_list())}"
145
  st.markdown("**Audio waves:**")
146
  st.text_area("Audio waves", waves, height=200)
147
+
148
  # audio_df = split_audio(audio_path)
149
  # print(np.concatenate(audio_df["audio"][:50].to_list()))
150
+
151
  accent_data = {"label": "American", "score": 0.9}
152
  accent = accent_data.get("label", "American")
153
  confidence = accent_data.get("score", 0.0)