Spaces:
Runtime error
Runtime error
| from youtube_transcript_api import YouTubeTranscriptApi | |
| from openai import OpenAI | |
| import gradio as gr | |
| def youtube_url(url): | |
| """ | |
| Function to retrieve the transcript of a YouTube video based on the provided URL. | |
| Parameters: | |
| url (str): The URL of the YouTube video. | |
| Returns: | |
| str: The transcript of the video. | |
| """ | |
| transcript = "" | |
| list=url.split("=") | |
| video_id = list[1] | |
| list = YouTubeTranscriptApi.get_transcript(video_id, languages=['tr', 'en',"de"]) | |
| for dict in list: | |
| transcript += dict["text"] + "\n" | |
| return transcript | |
| def summarizer(prompt, base_url, model, api_key): | |
| """ | |
| This function takes a prompt, base_url, model, and api_key as parameters and uses the OpenAI API or DeepSeek API to generate a summary based on the prompt. It returns the generated summary. | |
| """ | |
| system_msg = "you are a youtube transcript summarizer." | |
| client = OpenAI(api_key = api_key, base_url=base_url) | |
| completion = client.chat.completions.create( | |
| model=model, | |
| messages=[ | |
| {"role": "system", "content": system_msg}, | |
| {"role": "user", "content": prompt} | |
| ] | |
| ) | |
| summary = completion.choices[0].message.content | |
| return summary | |
| def main(url, model, api_key): | |
| """ | |
| This function takes in a URL, model, and API key as parameters and returns a summary of the given transcript. | |
| """ | |
| if model == "deepseek-chat": | |
| base_url = "https://api.deepseek.com/v1" | |
| else: | |
| base_url = None | |
| transcript = youtube_url(url) | |
| query=f"summarize this {transcript} transcript" | |
| summary = summarizer(query, base_url, model, api_key) | |
| return summary | |
| iface = gr.Interface( | |
| fn=main, | |
| inputs=[ | |
| gr.Textbox(label="YouTube URL", type="text"), | |
| gr.Dropdown(label="Model Seçimi", choices = ["deepseek-chat", "gpt-3 turbo", "gpt-3.5-turbo"]), | |
| gr.Textbox(label="Api Key", type="text") | |
| ], | |
| outputs="text", | |
| title="Video Özeti Oluşturucu", | |
| description="Bir YouTube videosunun URL'sini girin ve özetini alın." | |
| ) | |
| iface.launch(debug = True) | |