saad177 commited on
Commit
d7d5bfb
1 Parent(s): 4ca2965

changes in ui

Browse files
Files changed (1) hide show
  1. app.py +63 -41
app.py CHANGED
@@ -4,44 +4,66 @@ from youtube_dl import YoutubeDL
4
 
5
 
6
  # Function to download audio from YouTube link
7
- def download_audio(youtube_link, output_path):
8
- ydl_opts = {
9
- "format": "bestaudio/best",
10
- "outtmpl": output_path,
11
- "postprocessors": [
12
- {
13
- "key": "FFmpegExtractAudio",
14
- "preferredcodec": "mp3",
15
- "preferredquality": "192",
16
- }
17
- ],
18
- }
19
- with YoutubeDL(ydl_opts) as ydl:
20
- ydl.download([youtube_link])
21
-
22
-
23
- # Function to transcribe audio
24
- def transcribe_audio(audio_path):
25
- model = pipeline(model="SofiaK/checkpoints")
26
- return model(audio_path)["text"]
27
-
28
-
29
- interface = gr.Interface(
30
- fn=lambda input_type, audio_or_link: transcribe_audio(audio_or_link)
31
- if input_type == "audio"
32
- else transcribe_audio(download_audio(audio_or_link, "temp.mp3")),
33
- inputs=[
34
- gr.Radio(["audio", "youtube"], label="Select Input Type"),
35
- gr.Audio(
36
- sources=["upload", "microphone"],
37
- type="filepath",
38
- label="Upload Audio, or speak in the microphone",
39
- ),
40
- gr.Textbox(value="https://www.youtube.com/", label="Youtube Link"),
41
- ],
42
- outputs=gr.Text(label="Model output"),
43
- title="Whisper-RU",
44
- description="Fine-tuned Whisper for Russian language",
45
- )
46
-
47
- interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
 
6
  # Function to download audio from YouTube link
7
+ # def download_audio(youtube_link, output_path):
8
+ # ydl_opts = {
9
+ # "format": "bestaudio/best",
10
+ # "outtmpl": output_path,
11
+ # "postprocessors": [
12
+ # {
13
+ # "key": "FFmpegExtractAudio",
14
+ # "preferredcodec": "mp3",
15
+ # "preferredquality": "192",
16
+ # }
17
+ # ],
18
+ # }
19
+ # with YoutubeDL(ydl_opts) as ydl:
20
+ # ydl.download([youtube_link])
21
+
22
+
23
+ # def update_visibility(interface, input_type):
24
+ # if input_type == "audio":
25
+ # interface.set_visibility("audio_input", True)
26
+ # interface.set_visibility("youtube_input", False)
27
+ # elif input_type == "youtube":
28
+ # interface.set_visibility("audio_input", False)
29
+ # interface.set_visibility("youtube_input", True)
30
+ def transcribe_audio(input_type, audio_path):
31
+ if input_type == "Audio":
32
+ model = pipeline(model="SofiaK/checkpoints")
33
+ return model(audio_path)["text"]
34
+
35
+
36
+ with gr.Blocks() as demo:
37
+ radio = gr.Radio(
38
+ choices=["Audio", "Youtube"], label="Choose your input type", value="Audio"
39
+ )
40
+ audio_input = gr.Audio(
41
+ sources=["upload", "microphone"],
42
+ type="filepath",
43
+ label="Upload Audio, or speak in the microphone",
44
+ visible=True,
45
+ interactive=True,
46
+ )
47
+ youtube_input = gr.Textbox(
48
+ value="https://www.youtube.com/",
49
+ label="Youtube Link",
50
+ visible=False,
51
+ interactive=True,
52
+ )
53
+ btn = gr.Button(
54
+ "Transcript",
55
+ )
56
+
57
+ def make_visible(val):
58
+ audio_visible = val == "Audio"
59
+ return {
60
+ audio_input: {"visible": audio_visible, "__type__": "update"},
61
+ youtube_input: {"visible": not audio_visible, "__type__": "update"},
62
+ }
63
+
64
+ radio.change(make_visible, inputs=radio, outputs=[audio_input, youtube_input])
65
+
66
+ output = gr.Text(label="Model output")
67
+ btn.click(fn=transcribe_audio, inputs=[radio, audio_input], outputs=output)
68
+
69
+ demo.launch()