Spaces:
Runtime error
Runtime error
Commit
·
4e009c8
0
Parent(s):
Duplicate from darthPanda/youtube-video-to-text-generation
Browse filesCo-authored-by: Taaha Saleem Bajwa <[email protected]>
- .gitattributes +34 -0
- README.md +13 -0
- app.py +75 -0
- requirements.txt +3 -0
- temp.mp3 +0 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Youtube Video To Text Generation
|
3 |
+
emoji: 📊
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: purple
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.19.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: darthPanda/youtube-video-to-text-generation
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import re
|
4 |
+
import openai
|
5 |
+
from pytube import YouTube
|
6 |
+
import os
|
7 |
+
|
8 |
+
# Remove previous audio file
|
9 |
+
audio_filename = "temp.mp3"
|
10 |
+
if os.path.exists(audio_filename):
|
11 |
+
os.remove(audio_filename)
|
12 |
+
|
13 |
+
# Function to check if the provided OpenAI API key is valid
|
14 |
+
def is_valid_openai_key(api_key):
|
15 |
+
try:
|
16 |
+
openai.api_key = api_key
|
17 |
+
openai.Engine.list()
|
18 |
+
return True
|
19 |
+
except Exception as e:
|
20 |
+
st.write(f"Error: {e}")
|
21 |
+
return False
|
22 |
+
|
23 |
+
# Function to check if a provided link is a valid YouTube video link
|
24 |
+
def is_valid_youtube_link(url):
|
25 |
+
youtube_regex = re.compile(
|
26 |
+
r'(https?://)?(www\.)?'
|
27 |
+
r'(youtube|youtu|youtube-nocookie)\.(com|be)/'
|
28 |
+
r'(watch\?v=|embed/|v/|.+\?v=)?([^&=%\?]{11})'
|
29 |
+
)
|
30 |
+
return youtube_regex.match(url) is not None
|
31 |
+
|
32 |
+
# Define the application layout
|
33 |
+
st.set_page_config(page_title="YouTube Video to Text", layout="wide")
|
34 |
+
|
35 |
+
# Add the application header
|
36 |
+
st.title("YouTube Video to Text")
|
37 |
+
|
38 |
+
# Add the side panel
|
39 |
+
with st.sidebar:
|
40 |
+
st.header("Settings")
|
41 |
+
openai_api_key = st.text_input("OpenAI API Key", type="password")
|
42 |
+
youtube_video_link = st.text_input("YouTube Video Link")
|
43 |
+
st.caption('Note: Only videos in english language are currently supported.')
|
44 |
+
|
45 |
+
# In the main section of the app, add the following code:
|
46 |
+
if openai_api_key and youtube_video_link and is_valid_youtube_link(youtube_video_link):
|
47 |
+
if is_valid_openai_key(openai_api_key):
|
48 |
+
# Your code to process the YouTube video using the OpenAI API goes here
|
49 |
+
print(youtube_video_link)
|
50 |
+
youtube_video = YouTube(youtube_video_link, use_oauth=True, allow_oauth_cache=True)
|
51 |
+
st.markdown(f"Title: **{youtube_video.title}**")
|
52 |
+
streams=youtube_video.streams.filter(only_audio=True)
|
53 |
+
stream=streams.last()
|
54 |
+
with st.spinner('Downloading Audio'):
|
55 |
+
stream.download(filename='temp.mp3')
|
56 |
+
audio_file= open("temp.mp3", "rb")
|
57 |
+
with st.spinner('Transcribing Text'):
|
58 |
+
transcript_json = openai.Audio.transcribe("whisper-1", audio_file)
|
59 |
+
transcript = transcript_json["text"]
|
60 |
+
st.markdown("**Text:**")
|
61 |
+
st.markdown(transcript)
|
62 |
+
else:
|
63 |
+
st.warning("Invalid OpenAI API Key. Please enter a valid API key.")
|
64 |
+
else:
|
65 |
+
st.warning("Please enter a valid YouTube video link and OpenAI API key.")
|
66 |
+
|
67 |
+
# Add the footer with the creator's name and GitHub link
|
68 |
+
st.markdown(
|
69 |
+
"""
|
70 |
+
<div style="position: fixed; bottom: 10px; right: 10px; width: auto; height: auto; background-color: white; border: 1px solid #f0f2f6; border-radius: 5px; padding: 1rem;">
|
71 |
+
Created by Taaha Bajwa - <a href="https://github.com/yourusername/yourrepository" target="_blank">Source Code</a>
|
72 |
+
</div>
|
73 |
+
""",
|
74 |
+
unsafe_allow_html=True
|
75 |
+
)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit==1.17.0
|
2 |
+
openai
|
3 |
+
pytube
|
temp.mp3
ADDED
Binary file (925 kB). View file
|
|