Spaces:
Runtime error
Runtime error
add url_upload func
Browse files- app.py +41 -16
- css/index.css +12 -0
- requirements.txt +1 -1
app.py
CHANGED
@@ -1,43 +1,68 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import transformers
|
3 |
transformers.utils.move_cache()
|
4 |
from transformers import pipeline
|
|
|
5 |
|
6 |
auto_speech_recog = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")
|
7 |
-
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
8 |
|
9 |
-
def
|
10 |
-
|
|
|
|
|
11 |
|
12 |
-
def
|
13 |
return auto_speech_recog(input_file, chunk_length_s=10, stride_length_s=(2, 2))['text'].lower()
|
14 |
|
15 |
def text_summerization(text_input):
|
16 |
-
return summarizer(text_input, max_length=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
with gr.Blocks(css = "css/index.css") as iface:
|
19 |
gr.Markdown(elem_id="logo" , value="")
|
20 |
with gr.Column():
|
21 |
with gr.Tab("Record Audio"):
|
22 |
-
|
23 |
-
|
24 |
|
25 |
with gr.Tab("Upload Audio as File"):
|
26 |
-
|
27 |
-
|
28 |
|
29 |
with gr.Tab("URL"):
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
asr_out = gr.Textbox(label="Text transcribe")
|
34 |
-
|
35 |
summerize_btn = gr.Button("Summerize")
|
36 |
summerize_out = gr.Textbox(label="Summrization")
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
summerize_btn.click(text_summerization, asr_out, summerize_out)
|
42 |
|
43 |
iface.launch(debug=True)
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
import transformers
|
4 |
transformers.utils.move_cache()
|
5 |
from transformers import pipeline
|
6 |
+
from pytube import YouTube
|
7 |
|
8 |
auto_speech_recog = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")
|
9 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn", max_length="5000")
|
10 |
|
11 |
+
def transcribe_upload(input_file):
|
12 |
+
out = auto_speech_recog(input_file, chunk_length_s=10, stride_length_s=(2, 2))['text'].lower()
|
13 |
+
print("/n", out.count(" "), "\n")
|
14 |
+
return out
|
15 |
|
16 |
+
def transcribe_record(input_file):
|
17 |
return auto_speech_recog(input_file, chunk_length_s=10, stride_length_s=(2, 2))['text'].lower()
|
18 |
|
19 |
def text_summerization(text_input):
|
20 |
+
return summarizer(text_input, max_length=1432, min_length=300, do_sample=False, truncation=True)
|
21 |
+
|
22 |
+
def load_video_url(video, url):
|
23 |
+
video = gr.Video()
|
24 |
+
current_dir = os.getcwd()
|
25 |
+
|
26 |
+
try:
|
27 |
+
yt = YouTube(url)
|
28 |
+
except:
|
29 |
+
print("Connection Error")
|
30 |
+
try:
|
31 |
+
highest_audio = yt.streams.filter(progressive=False).get_highest_resolution().itag
|
32 |
+
file_url = os.path.join(current_dir, "audio", "test.mp4")
|
33 |
+
yt.streams.get_by_itag(highest_audio).download(output_path=os.path.join(current_dir, "audio"), filename = "test.mp4")
|
34 |
+
except :
|
35 |
+
print("error")
|
36 |
+
|
37 |
+
return file_url
|
38 |
|
39 |
with gr.Blocks(css = "css/index.css") as iface:
|
40 |
gr.Markdown(elem_id="logo" , value="")
|
41 |
with gr.Column():
|
42 |
with gr.Tab("Record Audio"):
|
43 |
+
input_record = gr.Audio(label = 'Record Audio Input',source="microphone",type="filepath")
|
44 |
+
gr_transcribe_record = gr.Button('Transcribe')
|
45 |
|
46 |
with gr.Tab("Upload Audio as File"):
|
47 |
+
input_upload = gr.Audio(label = 'Upload Audio',source="upload",type="filepath")
|
48 |
+
gr_transcribe_upload = gr.Button('Transcribe')
|
49 |
|
50 |
with gr.Tab("URL"):
|
51 |
+
with gr.Row():
|
52 |
+
with gr.Column():
|
53 |
+
input_url = gr.Textbox(elem_id="url_input",label="URL", show_label=False)
|
54 |
+
video_url = gr.Video(elem_id="video_elem", show_label=False, interactive = False)
|
55 |
+
video_url.style(width=600, height=400)
|
56 |
+
input_url.submit(load_video_url, [video_url, input_url], video_url)
|
57 |
+
gr_transcribe_url = gr.Button('Transcribe')
|
58 |
|
59 |
asr_out = gr.Textbox(label="Text transcribe")
|
|
|
60 |
summerize_btn = gr.Button("Summerize")
|
61 |
summerize_out = gr.Textbox(label="Summrization")
|
62 |
+
|
63 |
+
gr_transcribe_url.click(transcribe_upload, video_url, asr_out)
|
64 |
+
gr_transcribe_record.click(transcribe_record, input_record, asr_out)
|
65 |
+
gr_transcribe_upload.click(transcribe_upload, input_upload, asr_out)
|
66 |
summerize_btn.click(text_summerization, asr_out, summerize_out)
|
67 |
|
68 |
iface.launch(debug=True)
|
css/index.css
CHANGED
@@ -15,4 +15,16 @@
|
|
15 |
#img-id{
|
16 |
display: block;
|
17 |
margin-left: 40px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
}
|
|
|
15 |
#img-id{
|
16 |
display: block;
|
17 |
margin-left: 40px;
|
18 |
+
}
|
19 |
+
|
20 |
+
#video_elem {
|
21 |
+
margin-left: 300px !important;
|
22 |
+
}
|
23 |
+
|
24 |
+
#url_input {
|
25 |
+
display: flex;
|
26 |
+
justify-content: center !important;
|
27 |
+
justify-items: center !important;
|
28 |
+
/* width: 900px; */
|
29 |
+
|
30 |
}
|
requirements.txt
CHANGED
@@ -3,4 +3,4 @@ transformers
|
|
3 |
torch
|
4 |
tensorflow
|
5 |
ffmpeg
|
6 |
-
|
|
|
3 |
torch
|
4 |
tensorflow
|
5 |
ffmpeg
|
6 |
+
pytube
|