mgokg commited on
Commit
d748d51
·
verified ·
1 Parent(s): 8603361

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -1,25 +1,25 @@
1
  import gradio as gr
2
  from youtube_transcript_api import YouTubeTranscriptApi
3
 
4
- def get_transcript(link):
 
5
  try:
6
- video_id = link
 
 
 
7
 
8
- #video_id = link.split("v=")[1].split("&")[0] # Extract the video ID from the link
9
- transcript = YouTubeTranscriptApi.get_transcript(video_id, languages=['de'])
10
- final_transcript = ' '.join([i['text'] for i in transcript])
11
- return final_transcript
12
  except Exception as e:
13
- return f"An error occurred: {str(e)}"
14
 
15
- # Create the Gradio interface
16
  iface = gr.Interface(
17
- fn=get_transcript,
18
- inputs=gr.Textbox(label="YouTube Video Link", placeholder="Enter the YouTube video link here..."),
19
- outputs=gr.Textbox(label="Transcript"),
20
- title="YouTube Transcript Fetcher",
21
- description="Enter a YouTube video link to fetch and display its transcript."
22
  )
23
 
24
- # Launch the Gradio app
25
  iface.launch()
 
1
  import gradio as gr
2
  from youtube_transcript_api import YouTubeTranscriptApi
3
 
4
+
5
+ def transkribiere_youtube_video(video_url):
6
  try:
7
+ video_id = video_url.split("v=")[1]
8
+ if "&" in video_id:
9
+ video_id = video_id.split("&")[0] # falls zusätzliche Parameter in URL
10
+ transcript = YouTubeTranscriptApi.get_transcript(video_id, languages=['de', 'en']) # Transkripte in DE & EN (falls vorhanden)
11
 
12
+ text = " ".join([entry['text'] for entry in transcript])
13
+ return text
 
 
14
  except Exception as e:
15
+ return f"Fehler: {str(e)}. Stelle sicher, dass ein Transkript für das Video verfügbar ist und der Link korrekt ist."
16
 
 
17
  iface = gr.Interface(
18
+ fn=transkribiere_youtube_video,
19
+ inputs=gr.Textbox(lines=1, placeholder="Gib hier den YouTube Video-Link ein"),
20
+ outputs=gr.Textbox(lines=20, label="Transkript"),
21
+ title="YouTube Transkription",
22
+ description="Gib einen YouTube-Videolink ein und erhalte den transkribierten Text."
23
  )
24
 
 
25
  iface.launch()