Spaces:
Sleeping
Sleeping
Ibrahim Olanigan commited on
Commit ·
50148fc
1
Parent(s): 31c4e79
Fix import
Browse files
app.py
CHANGED
|
@@ -1,11 +1,8 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import pytube as pt
|
| 3 |
import os
|
| 4 |
import subprocess
|
| 5 |
import re
|
| 6 |
import whisper
|
| 7 |
-
from langchain.document_loaders import YoutubeLoader
|
| 8 |
-
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 9 |
|
| 10 |
URL = 'URL'
|
| 11 |
TEXT = 'TEXT'
|
|
@@ -19,14 +16,8 @@ model = ''
|
|
| 19 |
st.title('Youtube Audio+Text')
|
| 20 |
|
| 21 |
def init_state():
|
| 22 |
-
|
| 23 |
-
st.session_state[
|
| 24 |
-
|
| 25 |
-
if TEXT not in st.session_state:
|
| 26 |
-
st.session_state[TEXT] = ''
|
| 27 |
-
|
| 28 |
-
if WHISPER not in st.session_state:
|
| 29 |
-
st.session_state[WHISPER] = ''
|
| 30 |
|
| 31 |
if AUDIO_EXISTS not in st.session_state:
|
| 32 |
st.session_state[AUDIO_EXISTS] = False
|
|
@@ -39,15 +30,8 @@ def clear_old_files():
|
|
| 39 |
if file.endswith(".mp3") or file == 'transcript.txt':
|
| 40 |
os.remove(file)
|
| 41 |
print(f"Removed old files::{file}")
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
def extract_youtube_video_id(url):
|
| 45 |
-
regex = r"v=([^&]+)"
|
| 46 |
-
match = re.search(regex, url)
|
| 47 |
-
if match:
|
| 48 |
-
return match.group(1)
|
| 49 |
-
else:
|
| 50 |
-
return None
|
| 51 |
|
| 52 |
|
| 53 |
def load_whisper():
|
|
@@ -90,6 +74,7 @@ def display():
|
|
| 90 |
input_submit_button = st.form_submit_button(label='Send')
|
| 91 |
|
| 92 |
if input_submit_button and user_input:
|
|
|
|
| 93 |
download()
|
| 94 |
load_whisper()
|
| 95 |
|
|
@@ -100,7 +85,6 @@ def display():
|
|
| 100 |
value=st.session_state[WHISPER])
|
| 101 |
|
| 102 |
def download():
|
| 103 |
-
id = extract_youtube_video_id(st.session_state[URL])
|
| 104 |
command = [f"yt-dlp --no-config -v --extract-audio --audio-format mp3 {st.session_state[URL]} -o audio.mp3"]
|
| 105 |
print(command)
|
| 106 |
out = subprocess.run(command, shell=True)
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import os
|
| 3 |
import subprocess
|
| 4 |
import re
|
| 5 |
import whisper
|
|
|
|
|
|
|
| 6 |
|
| 7 |
URL = 'URL'
|
| 8 |
TEXT = 'TEXT'
|
|
|
|
| 16 |
st.title('Youtube Audio+Text')
|
| 17 |
|
| 18 |
def init_state():
|
| 19 |
+
for state in STATES:
|
| 20 |
+
st.session_state[state] = ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
if AUDIO_EXISTS not in st.session_state:
|
| 23 |
st.session_state[AUDIO_EXISTS] = False
|
|
|
|
| 30 |
if file.endswith(".mp3") or file == 'transcript.txt':
|
| 31 |
os.remove(file)
|
| 32 |
print(f"Removed old files::{file}")
|
| 33 |
+
#Refresh audio state
|
| 34 |
+
load_audio()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
def load_whisper():
|
|
|
|
| 74 |
input_submit_button = st.form_submit_button(label='Send')
|
| 75 |
|
| 76 |
if input_submit_button and user_input:
|
| 77 |
+
clear_old_files()
|
| 78 |
download()
|
| 79 |
load_whisper()
|
| 80 |
|
|
|
|
| 85 |
value=st.session_state[WHISPER])
|
| 86 |
|
| 87 |
def download():
|
|
|
|
| 88 |
command = [f"yt-dlp --no-config -v --extract-audio --audio-format mp3 {st.session_state[URL]} -o audio.mp3"]
|
| 89 |
print(command)
|
| 90 |
out = subprocess.run(command, shell=True)
|