File size: 2,994 Bytes
cdd6e6b b4f0b8c c1726ec cdd6e6b c1726ec c96a37a c1726ec cdd6e6b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
import gradio as gr
from youtube_transcript_api import YouTubeTranscriptApi as yta
import re
# Define the extract_video_id function
def extract_video_id(youtube_url):
if "youtube.com/watch" not in youtube_url:
print("Invalid YouTube URL")
return None
index_v = youtube_url.find('v=')
if index_v == -1:
print("Video ID not found in the URL")
return None
video_id_start = index_v + 2
video_id_end = youtube_url.find('&', video_id_start)
video_id = youtube_url[video_id_start:video_id_end] if video_id_end != -1 else youtube_url[video_id_start:]
return video_id
# Set the input and output components
input_component = gr.Textbox(label="YouTube URL")
output_component = gr.Textbox(label="Transcription")
# Set the function
def transcribe_video(youtube_url):
video_id = extract_video_id(youtube_url)
if video_id is None:
return "Invalid YouTube URL"
transcript = yta.get_transcript(video_id, languages=('us', 'en'))
data1 = [t['text'] for t in transcript]
data2 = [re.sub(r"[^a-zA-Z0-9-1sg��çiISGÖÜçï ]", "", line) for line in data1]
return "\n".join(data2)
# Create the app
app = gr.Interface(
fn=transcribe_video,
inputs=input_component,
outputs=output_component,
theme={
"base_color": "#333333",
"font": "Courier New",
"font_size": 18,
"font_weight": "bold",
"font_style": "italic",
"button_color": "#FFA500",
"button_hover_color": "#FFC0CB",
"button_active_color": "#FFD700",
"button_border_color": "#333333",
"button_border_width": 2,
"button_border_radius": 5,
"input_border_color": "#333333",
"input_border_width": 2,
"input_border_radius": 5,
"input_background_color": "#FFFFFF",
"input_text_color": "#333333",
"output_border_color": "#333333",
"output_border_width": 2,
"output_border_radius": 5,
"output_background_color": "#FFFFFF",
"output_text_color": "#333333",
"label_color": "#333333",
"label_font_size": 16,
"label_font_weight": "bold",
"label_font_style": "italic",
"label_background_color": "#FFFFFF",
"label_border_color": "#333333",
"label_border_width": 2,
"label_border_radius": 5,
"header_color": "#333333",
"header_font_size": 24,
"header_font_weight": "bold",
"header_font_style": "italic",
"header_background_color": "#FFFFFF",
"header_border_color": "#333333",
"header_border_width": 2,
"header_border_radius": 5,
"footer_color": "#333333",
"footer_font_size": 14,
"footer_font_weight": "bold",
"footer_font_style": "italic",
"footer_background_color": "#FFFFFF",
"footer_border_color": "#333333",
"footer_border_width": 2,
"footer_border_radius": 5,
},
)
# Launch the app
app.launch() |