Update app.py
Browse files
app.py
CHANGED
|
@@ -5,11 +5,6 @@ from pydub import AudioSegment
|
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
import io
|
| 8 |
-
import requests
|
| 9 |
-
import execjs
|
| 10 |
-
import re
|
| 11 |
-
import json
|
| 12 |
-
import yt_dlp
|
| 13 |
|
| 14 |
# Function to convert video to audio
|
| 15 |
def video_to_audio(video_file):
|
|
@@ -56,36 +51,12 @@ def transcribe_audio(audio_file):
|
|
| 56 |
except sr.RequestError:
|
| 57 |
return "Could not request results from Google Speech Recognition service."
|
| 58 |
|
| 59 |
-
# Function to extract video download URL using yt-dlp with cookies
|
| 60 |
-
def extract_video_url(youtube_url, cookies_file=None):
|
| 61 |
-
try:
|
| 62 |
-
# Set up yt-dlp options with cookies if provided
|
| 63 |
-
ydl_opts = {
|
| 64 |
-
'format': 'bestaudio/best', # Get best audio or best video
|
| 65 |
-
'quiet': True, # Suppress output
|
| 66 |
-
'cookiefile': cookies_file if cookies_file else None, # Use cookies if provided
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
# Create a yt-dlp object with the provided options
|
| 70 |
-
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 71 |
-
# Extract the video information
|
| 72 |
-
info_dict = ydl.extract_info(youtube_url, download=False)
|
| 73 |
-
|
| 74 |
-
# Check if the video has an 'url' field and return it
|
| 75 |
-
if 'url' in info_dict:
|
| 76 |
-
return info_dict['url']
|
| 77 |
-
else:
|
| 78 |
-
raise ValueError("Unable to find download URL for the video.")
|
| 79 |
-
|
| 80 |
-
except Exception as e:
|
| 81 |
-
raise ValueError(f"Error occurred while extracting the download URL: {e}")
|
| 82 |
-
|
| 83 |
# Streamlit app layout
|
| 84 |
st.title("Video and Audio to Text Transcription")
|
| 85 |
-
st.write("Upload a video or audio file to convert it to transcription
|
| 86 |
|
| 87 |
-
# Create tabs to separate video
|
| 88 |
-
tab = st.selectbox("Select the type of file to upload
|
| 89 |
|
| 90 |
if tab == "Video":
|
| 91 |
# File uploader for video
|
|
@@ -202,25 +173,4 @@ elif tab == "Audio":
|
|
| 202 |
data=st.session_state.wav_audio_file_audio,
|
| 203 |
file_name="converted_audio_audio.wav",
|
| 204 |
mime="audio/wav"
|
| 205 |
-
)
|
| 206 |
-
|
| 207 |
-
# Streamlit UI for YouTube video download
|
| 208 |
-
elif tab == "YouTube":
|
| 209 |
-
st.title("YouTube Video Downloader")
|
| 210 |
-
st.write("""This app allows you to download YouTube videos in various formats. Simply enter the YouTube URL below and click "Get Download Link".""")
|
| 211 |
-
|
| 212 |
-
youtube_url = st.text_input("Enter YouTube Video URL", "https://www.youtube.com/watch?v=YPvtz1lHRiw")
|
| 213 |
-
|
| 214 |
-
cookies_file = st.file_uploader("Upload Cookies File", type=["txt"])
|
| 215 |
-
|
| 216 |
-
if st.button("Get Download Link"):
|
| 217 |
-
if youtube_url:
|
| 218 |
-
try:
|
| 219 |
-
download_url = extract_video_url(youtube_url, cookies_file=cookies_file)
|
| 220 |
-
st.success("Download link generated successfully!")
|
| 221 |
-
st.write("Click below to download the video:")
|
| 222 |
-
st.markdown(f"[Download Video]({download_url})", unsafe_allow_html=True)
|
| 223 |
-
except Exception as e:
|
| 224 |
-
st.error(f"Error occurred: {e}")
|
| 225 |
-
else:
|
| 226 |
-
st.error("Please enter a valid YouTube URL.")
|
|
|
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
import io
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Function to convert video to audio
|
| 10 |
def video_to_audio(video_file):
|
|
|
|
| 51 |
except sr.RequestError:
|
| 52 |
return "Could not request results from Google Speech Recognition service."
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
# Streamlit app layout
|
| 55 |
st.title("Video and Audio to Text Transcription")
|
| 56 |
+
st.write("Upload a video or audio file to convert it to transcription.")
|
| 57 |
|
| 58 |
+
# Create tabs to separate video and audio uploads
|
| 59 |
+
tab = st.selectbox("Select the type of file to upload", ["Video", "Audio"])
|
| 60 |
|
| 61 |
if tab == "Video":
|
| 62 |
# File uploader for video
|
|
|
|
| 173 |
data=st.session_state.wav_audio_file_audio,
|
| 174 |
file_name="converted_audio_audio.wav",
|
| 175 |
mime="audio/wav"
|
| 176 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|