Ytt / app.py
Ashrafb's picture
Rename app (42).py to app.py
97e90c5
import streamlit as st
from pytube import YouTube
import os
import re
import logging
import whisper
logging.basicConfig(level=logging.INFO)
model = whisper.load_model("base")
def get_text(url):
if url != '':
output_text_transcribe = ''
yt = YouTube(url)
video = yt.streams.filter(only_audio=True).first()
out_file = video.download(output_path=".")
file_stats = os.stat(out_file)
logging.info(f'Size of audio file in Bytes: {file_stats.st_size}')
if file_stats.st_size <= 30000000:
base, ext = os.path.splitext(out_file)
new_file = base+'.mp3'
os.rename(out_file, new_file)
a = new_file
result = model.transcribe(a)
return result['text'].strip()
else:
logging.error('Videos for transcription on this space are limited to about 1.5 hours. Sorry about this limit but some joker thought they could stop this tool from working by transcribing many extremely long videos.')
st.markdown('<p style="color:blue;text-align:center;font-size:30px;">Aiconvert.online</p>', unsafe_allow_html=True)
st.title("AIconvert Fast YouTube URL Video-to-Text ")
st.markdown('<style>h1{color: Crimson; text-align: center;}</style>', unsafe_allow_html=True)
st.markdown("Transcription takes about 30 seconds per minute of the video (bad audio/hard accents slow it down a bit). #patience")
url = st.text_input("YouTube URL")
if st.button("Transcribe"):
with st.spinner('Transcribing...'):
result = get_text(url)
if result:
st.subheader("Transcript")
st.write(result)