abidlabs HF Staff commited on
Commit
bb13dff
·
verified ·
1 Parent(s): 3619217

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def convert_to_embed_url(youtube_url):
4
+ if "youtube.com/watch?v=" in youtube_url:
5
+ video_id = youtube_url.split("v=")[1].split("&")[0]
6
+ elif "youtu.be/" in youtube_url:
7
+ video_id = youtube_url.split("youtu.be/")[1].split("?")[0]
8
+ else:
9
+ return ""
10
+ embed_url = f"https://www.youtube.com/embed/{video_id}"
11
+ return f'<iframe width="100%" height="200" src="{embed_url}" style="border-radius:10px"></iframe>'
12
+
13
+ from pytube import YouTube
14
+ import os
15
+ from pydub import AudioSegment
16
+
17
+ def download_audio_from_youtube(video_url):
18
+ try:
19
+ yt = YouTube(video_url)
20
+ audio_stream = yt.streams.filter(only_audio=True).first()
21
+ downloaded_file = audio_stream.download(".")
22
+ base, ext = os.path.splitext(downloaded_file)
23
+ mp3_file = base + '.mp3'
24
+ AudioSegment.from_file(downloaded_file).export(mp3_file, format='mp3')
25
+ os.remove(downloaded_file)
26
+ return base
27
+ except Exception as e:
28
+ gr.Error(f"An error occurred: {e}")
29
+
30
+ import ffmpeg
31
+
32
+ def convert_video_to_audio(input_file):
33
+ output_file = "audio.mp3"
34
+ try:
35
+ (
36
+ ffmpeg
37
+ .input(input_file)
38
+ .output(output_file)
39
+ .run()
40
+ )
41
+ return output_file
42
+ except ffmpeg.Error as e:
43
+ gr.Error(f"An error occurred: {e}")
44
+
45
+ def transcribe(source, file):
46
+ if source == "Audio":
47
+
48
+
49
+
50
+ with gr.Blocks(theme="freddyaboulton/test-blue") as demo:
51
+ gr.Markdown("<center><h1> 🔊 Transcribe Anything </h1></center>")
52
+ with gr.Tab("Input"):
53
+ with gr.Row():
54
+ with gr.Column():
55
+ source = gr.Radio(label="Source type", choices=[("Audio", "audio"), ("Video", "video"), ("YouTube URL", "youtube")], value="Audio")
56
+ @gr.render(inputs=source)
57
+ def show_source(s):
58
+ if s == "Audio":
59
+ gr.Audio()
60
+ elif s == "Video":
61
+ gr.Video()
62
+ elif s == "YouTube URL":
63
+ t = gr.Textbox(placeholder="https://www.youtube.com/watch?v=44vi31hehw4")
64
+ h = gr.HTML(label="Video preview")
65
+ t.change(convert_to_embed_url, t, h)
66
+
67
+ with gr.Column():
68
+ gr.Dropdown(label="Languages", choices=["(Autodetect)", "English"], value="(Autodetect)")
69
+ gr.CheckboxGroup(label="Cleanup Transcript with LLM", choices=["Remove typos", "Separate into paragraphs"])
70
+ gr.Checkbox(label="Diarize Speakers (coming soon)", interactive=False)
71
+ transcribe_btn = gr.Button("Transcribe!")
72
+
73
+ with gr.Tab("Result"):
74
+ pass
75
+ with gr.Tab("Summarize"):
76
+ pass
77
+ with gr.Tab("Chat"):
78
+ pass
79
+
80
+ demo.launch()