IanRonk commited on
Commit
bffc7a4
1 Parent(s): d48eb67

Add new function to retrieve yt data

Browse files
Files changed (2) hide show
  1. app.py +23 -1
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,9 +1,31 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
 
4
  def greet(name):
5
  return "Hello " + name + "!!"
6
 
7
 
8
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
9
  demo.launch(share=True)
 
1
  import gradio as gr
2
+ import requests
3
+ from youtube_transcript_api import YouTubeTranscriptApi
4
+ import json
5
+
6
+
7
+ def retrieve_url(vid_id):
8
+ try:
9
+ transcript = YouTubeTranscriptApi.get_transcript(vid_id)
10
+ except Exception as e:
11
+ raise e
12
+ req = requests.get(
13
+ f"https://yt.lemnoslife.com/noKey/videos?part=snippet&id={vid_id}"
14
+ )
15
+ if req.status_code == 200:
16
+ information = json.loads(req.content)
17
+ else:
18
+ # print(req.status_code)
19
+ information = None
20
+ return ""
21
+ # print(transcript)
22
+ text = " ".join([x["text"] for x in transcript])
23
+ return text
24
 
25
 
26
  def greet(name):
27
  return "Hello " + name + "!!"
28
 
29
 
30
+ demo = gr.Interface(fn=retrieve_url, inputs="text", outputs="text")
31
  demo.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ youtube_transcript_api