Spaces:
Sleeping
Sleeping
File size: 3,009 Bytes
87359bb 69bf66b 87359bb 69bf66b 651ae26 87359bb e31036d 651ae26 87359bb edcf95f 4f26484 edcf95f e31036d 651ae26 e31036d 651ae26 edcf95f 2212eea 87359bb 473fd7c 2d593aa 651ae26 2212eea 651ae26 2212eea edcf95f 2212eea 651ae26 204ee93 2212eea edcf95f 2212eea edcf95f e31036d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import whisper
from pytube import YouTube
from transformers import pipeline
import gradio as gr
import os
model = whisper.load_model("base")
summarizer = pipeline("summarization")
def get_audio(url):
yt = YouTube(url)
video = yt.streams.filter(only_audio=True).first()
out_file = video.download(output_path=".")
base, ext = os.path.splitext(out_file)
new_file = base + '.mp3'
os.rename(out_file, new_file)
return new_file
def get_text_from_url(url):
result = model.transcribe(get_audio(url))
return result['text']
def get_text_from_file(file):
# Assuming the uploaded file is already in MP3 format
result = model.transcribe(file.name)
return result['text']
def get_summary_from_url(url):
article = get_text_from_url(url)
b = summarizer(article)
return b[0]['summary_text']
def get_summary_from_file(file):
article = get_text_from_file(file)
b = summarizer(article)
return b[0]['summary_text']
def process_url(url):
transcription = get_text_from_url(url)
summary = get_summary_from_url(url)
return summary, transcription
def process_file(file):
transcription = get_text_from_file(file)
summary = get_summary_from_file(file)
return summary, transcription
with gr.Blocks() as demo:
gr.Markdown("<h1><center>Youtube and Video File Upload with Whisper Transcription and Summary</center></h1>")
gr.Textbox("Enter the link of any youtube video or upload an MP4 file to get the transcription and a summary in text form. I'm using a git trick in the requirements file to run this without an openai API Key, if you wnat a little more speed and want to do it with an openai API Key check out the code base at https://huggingface.co/spaces/eaglelandsonce/ChatGPT_Enhanced, if you want to interact live with folks on line check out my Meetup at https://www.meetup.com/florence-aws-user-group-meetup/.", Label="Note to User")
with gr.Tab('Youtube Video'):
with gr.Row():
input_text = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
output_summary = gr.Textbox(placeholder='Summary text of the Youtube Video', label='Summary')
output_transcription = gr.Textbox(placeholder='Transcription of the video', label='Transcription')
result_button = gr.Button('Process Youtube Video')
with gr.Tab('Uploaded MP4'):
with gr.Row():
input_file = gr.File(label='Upload MP4')
output_file_summary = gr.Textbox(placeholder='Summary text of the video', label='Summary')
output_file_transcription = gr.Textbox(placeholder='Transcription of the video', label='Transcription')
result_button_file = gr.Button('Process Uploaded MP4')
result_button.click(process_url, inputs=input_text, outputs=[output_summary, output_transcription])
result_button_file.click(process_file, inputs=input_file, outputs=[output_file_summary, output_file_transcription])
demo.launch(debug=True)
|