ALL_NLP_Tasks / Text_Script_from_YouTube.py
ipvikas's picture
Update Text_Script_from_YouTube.py
f6865a1
#!pip install -q transformers
#!pip install -q youtube_transcript_api
import gradio as gr
from transformers import pipeline
from youtube_transcript_api import YouTubeTranscriptApi
def TextScript_demo(input_text):
#youtube_video = "https://www.youtube.com/watch?v=7gTpHugdUWc"
youtube_video=input_text
video_id = youtube_video.split("=")[1]
YouTubeTranscriptApi.get_transcript(video_id)
transcript = YouTubeTranscriptApi.get_transcript(video_id)
result = ""
for i in transcript:
result += ' ' + i['text']
#print(result)
# print(len(result))
summarizer = pipeline('summarization')
num_iters = int(len(result)/1000)
summarized_text = []
for i in range(0, num_iters + 1):
start = 0
start = i * 1000
end = (i + 1) * 1000
#print("input text \n" + result[start:end])
out = summarizer(result[start:end])
#out = out[0]
#out = out['summary_text']
#print("Summarized text\n"+out)
#summarized_text.append(out)
return out
title ='Text Script Generation from YouTube Link'
description = "Extract Script"
textScript_demo= gr.Interface(fn=TextScript_demo, inputs = 'text', outputs='text', title = title, description = description)