KAHRAMAN42 commited on
Commit
75a79b3
·
verified ·
1 Parent(s): 03b26d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -15
app.py CHANGED
@@ -1,26 +1,80 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
  from youtube_transcript_api import YouTubeTranscriptApi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- def youtube(url):
7
- video_id=url.split("=")[1]
8
- transcript=YouTubeTranscriptApi.get_transcript(video_id,"tr","en")
9
- result=""
10
- for i in transcript[0:100]:
11
- result+=i["text"]+" "+"\n"
12
- summarization=pipeline("summarization",model="facebook/bart-large-cnn",max_length=60,min_length=10)
13
- list_summarize=summarization(result)[0]["summary_text"].split(". ")
14
- result= ". ".join(list_summarize)
15
- return result
16
 
17
  iface = gr.Interface(
18
- fn=youtube,
19
  inputs="text",
20
  outputs="text",
21
- layout="vertical",
22
  title="Video Özeti Oluşturucu",
23
  description="Bir YouTube videosunun URL'sini girin ve özetini alın."
24
  )
25
 
26
- iface.launch(share=True)
 
 
 
1
  from youtube_transcript_api import YouTubeTranscriptApi
2
+ from openai import OpenAI
3
+ import gradio as gr
4
+ import os
5
+ from dotenv import load_dotenv
6
+
7
+ load_dotenv()
8
+
9
+ api_key= os.getenv("api_key")
10
+
11
+ def youtube_url(url):
12
+
13
+ """
14
+ Function to retrieve the transcript of a YouTube video based on the provided URL.
15
+
16
+ Parameters:
17
+ url (str): The URL of the YouTube video.
18
+
19
+ Returns:
20
+ str: The transcript of the video.
21
+ """
22
+
23
+ transcript = ""
24
+ list=url.split("=")
25
+ video_id = list[1]
26
+ list = YouTubeTranscriptApi.get_transcript(video_id, languages=['tr', 'en',"de"])
27
+ for dict in list:
28
+ transcript += dict["text"] + "\n"
29
+ return transcript
30
+
31
+
32
+ def chat(prompt):
33
+
34
+ """
35
+ This function takes a prompt as input and uses the OpenAI API to generate a chat completion based on the prompt. It returns the summary of the chat completion.
36
+ """
37
+
38
+ system_msg = "you are a youtube transcript summarizer."
39
+
40
+ client = OpenAI(api_key = api_key, base_url="https://api.deepseek.com/v1")
41
+
42
+ completion = client.chat.completions.create(
43
+ model="deepseek-chat",
44
+ messages=[
45
+ {"role": "system", "content": system_msg},
46
+ {"role": "user", "content": prompt}
47
+ ]
48
+ )
49
+ summary = completion.choices[0].message.content
50
+ return summary
51
+
52
+
53
+ def main(url):
54
 
55
+ """
56
+ Function to summarize the transcript of a YouTube video using the provided URL.
57
+
58
+ Parameters:
59
+ url (str): The URL of the YouTube video.
60
+
61
+ Returns:
62
+ str: The summary of the video transcript.
63
+ """
64
+
65
+ transcript = youtube_url(url)
66
+ query=f"summarize this {transcript} transcript"
67
+ summary = chat(query)
68
+ return summary
69
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  iface = gr.Interface(
72
+ fn=main,
73
  inputs="text",
74
  outputs="text",
75
+
76
  title="Video Özeti Oluşturucu",
77
  description="Bir YouTube videosunun URL'sini girin ve özetini alın."
78
  )
79
 
80
+ iface.launch(debug = True)