File size: 1,534 Bytes
51306d7 2819be2 ad28e9f 8626295 4261a30 8626295 51306d7 2819be2 8626295 51306d7 ec4b4c0 51306d7 9ea458e cc5f787 51306d7 d8caea7 2819be2 51306d7 |
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 |
from youtubesearchpython import VideosSearch, Transcript # Changed import statement
import gradio as gr # Added import statement for Gradio
import openai
import os
openai.api_key = os.getenv('O_API_KEY')
def search_youtube_videos(keyword):
videos_search = VideosSearch(keyword, limit=5)
results = videos_search.result()
video_urls = [video['link'] for video in results['result']]
return video_urls
# Function to get the transcript for a given list of video URLs
def get_transcript(urls):
contents = ''
for url in urls:
data = Transcript.get(url)
text = ""
for segment in data['segments']:
text += segment['text']
contents += text
return contents
# Function to summarize text using OpenAI's API
def summarize_text(contents):
response = openai.ChatCompletion.create(
engine="gpt-3.5-turbo-0125",
prompt=f"์์ฝ: {contents}",
max_tokens=150
)
return response.choices[0].text.strip()
# Function to integrate all the functionalities
def summarize_youtube_videos(keyword):
urls = search_youtube_videos(keyword)
contents = get_transcript(urls)
summary = summarize_text(contents)
return summary
# Define Gradio interface
iface = gr.Interface(
fn=summarize_youtube_videos,
inputs="text", # Changed input to "text" (user input)
outputs="text",
title="Summarize YouTube Videos",
description="Enter a keyword to summarize related YouTube videos.",
)
# Launch Gradio interface
iface.launch()
|