Spaces:
Runtime error
Runtime error
Add new function to retrieve yt data
Browse files- app.py +23 -1
- 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=
|
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
|