Spaces:
Running
Running
Rivalcoder
commited on
Commit
·
adb03d1
1
Parent(s):
28868d4
Add
Browse files
app.py
CHANGED
@@ -1,40 +1,33 @@
|
|
1 |
import gradio as gr
|
2 |
from youtube_transcript_api import YouTubeTranscriptApi
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
'http://51.16.179.113:1080', # United States
|
12 |
-
'http://200.174.198.86:8888', # Brazil
|
13 |
-
'http://3.126.147.182:80', # Germany
|
14 |
-
'http://80.249.112.162:80' # Iran
|
15 |
-
]
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
import random
|
20 |
-
proxy = random.choice(proxies_list)
|
21 |
-
proxies = {
|
22 |
-
'http': proxy,
|
23 |
-
'https': proxy
|
24 |
-
}
|
25 |
-
|
26 |
try:
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
29 |
except Exception as e:
|
30 |
-
return f"Error: {str(e)}"
|
31 |
|
|
|
32 |
iface = gr.Interface(
|
33 |
-
fn=
|
34 |
-
inputs=gr.Textbox(label="YouTube Video ID"),
|
35 |
outputs=gr.Textbox(label="Transcript"),
|
36 |
-
|
37 |
-
description="Enter a YouTube video ID to fetch its transcript using a proxy."
|
38 |
)
|
39 |
|
|
|
40 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from youtube_transcript_api import YouTubeTranscriptApi
|
3 |
+
from youtube_transcript_api.proxies import WebshareProxyConfig
|
4 |
|
5 |
+
# Initialize the YouTubeTranscriptApi with proxy configuration
|
6 |
+
ytt_api = YouTubeTranscriptApi(
|
7 |
+
proxy_config=WebshareProxyConfig(
|
8 |
+
proxy_username="tlaukrdr", # Replace with your proxy username
|
9 |
+
proxy_password="mc1aumn9xbhb" # Replace with your proxy password
|
10 |
+
)
|
11 |
+
)
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
# Function to fetch YouTube transcript using the video ID
|
14 |
+
def fetch_transcript(video_id: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
try:
|
16 |
+
# Fetch transcript
|
17 |
+
transcript = ytt_api.fetch(video_id)
|
18 |
+
# Format the transcript into a readable text
|
19 |
+
transcript_text = "\n".join([entry['text'] for entry in transcript])
|
20 |
+
return transcript_text
|
21 |
except Exception as e:
|
22 |
+
return f"Error fetching transcript: {str(e)}"
|
23 |
|
24 |
+
# Gradio Interface
|
25 |
iface = gr.Interface(
|
26 |
+
fn=fetch_transcript,
|
27 |
+
inputs=gr.Textbox(label="Enter YouTube Video ID"),
|
28 |
outputs=gr.Textbox(label="Transcript"),
|
29 |
+
live=True
|
|
|
30 |
)
|
31 |
|
32 |
+
# Launch the Gradio app
|
33 |
iface.launch()
|