Update app.py
Browse files
app.py
CHANGED
|
@@ -7,12 +7,26 @@ from pydub import AudioSegment
|
|
| 7 |
from pydub.silence import split_on_silence
|
| 8 |
import io
|
| 9 |
import os
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Load the transcription model
|
| 12 |
transcription_pipeline = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")
|
| 13 |
|
| 14 |
def download_audio_from_url(url):
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
audio_bytes = response.content
|
| 17 |
return audio_bytes
|
| 18 |
|
|
|
|
| 7 |
from pydub.silence import split_on_silence
|
| 8 |
import io
|
| 9 |
import os
|
| 10 |
+
from bs4 import BeautifulSoup
|
| 11 |
+
import re
|
| 12 |
|
| 13 |
# Load the transcription model
|
| 14 |
transcription_pipeline = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")
|
| 15 |
|
| 16 |
def download_audio_from_url(url):
|
| 17 |
+
if "share" in url:
|
| 18 |
+
# Extract the direct MP4 URL from the shareable link
|
| 19 |
+
response = requests.get(url)
|
| 20 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
| 21 |
+
video_tag = soup.find('video')
|
| 22 |
+
if video_tag and 'src' in video_tag.attrs:
|
| 23 |
+
video_url = video_tag['src']
|
| 24 |
+
else:
|
| 25 |
+
raise ValueError("Direct video URL not found in the shareable link.")
|
| 26 |
+
else:
|
| 27 |
+
video_url = url
|
| 28 |
+
|
| 29 |
+
response = requests.get(video_url)
|
| 30 |
audio_bytes = response.content
|
| 31 |
return audio_bytes
|
| 32 |
|