Spaces:
Runtime error
Runtime error
krishnasai99
commited on
Commit
•
d41c42c
1
Parent(s):
a89bf70
Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,62 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
st.
|
13 |
-
|
14 |
-
if
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
%%writefile app.py
|
2 |
+
import streamlit as st
|
3 |
+
import soundfile as sf
|
4 |
+
import librosa
|
5 |
+
from transformers import HubertForCTC, Wav2Vec2Processor , pipeline , Wav2Vec2ForCTC , Wav2Vec2Tokenizer
|
6 |
+
import torch
|
7 |
+
import spacy
|
8 |
+
from spacy import displacy
|
9 |
+
|
10 |
+
st.title('Audio-to-Text')
|
11 |
+
|
12 |
+
audio_file = st.file_uploader('Upload Audio' , type=['wav' , 'mp3','m4a'])
|
13 |
+
|
14 |
+
if st.button('Trascribe Audio'):
|
15 |
+
if audio_file is not None:
|
16 |
+
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-960h")
|
17 |
+
model = HubertForCTC.from_pretrained("facebook/hubert-large-ls960-ft")
|
18 |
+
speech, rate = librosa.load(audio_file, sr=16000)
|
19 |
+
input_values = processor(speech, return_tensors="pt", padding="longest", sampling_rate=rate).input_values
|
20 |
+
logits = model(input_values).logits
|
21 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
22 |
+
text = processor.batch_decode(predicted_ids)
|
23 |
+
st.write(text)
|
24 |
+
else:
|
25 |
+
st.error('please upload the audio file')
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
if st.button('Summarize'):
|
30 |
+
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-960h")
|
31 |
+
model = HubertForCTC.from_pretrained("facebook/hubert-large-ls960-ft")
|
32 |
+
speech, rate = librosa.load(audio_file, sr=16000)
|
33 |
+
input_values = processor(speech, return_tensors="pt", padding="longest", sampling_rate=rate).input_values
|
34 |
+
logits = model(input_values).logits
|
35 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
36 |
+
text = processor.batch_decode(predicted_ids)
|
37 |
+
summarize = pipeline("summarization")
|
38 |
+
st.write(summarize(text))
|
39 |
+
|
40 |
+
if st.button('sentiment-analysis'):
|
41 |
+
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-960h")
|
42 |
+
model = HubertForCTC.from_pretrained("facebook/hubert-large-ls960-ft")
|
43 |
+
speech, rate = librosa.load(audio_file, sr=16000)
|
44 |
+
input_values = processor(speech, return_tensors="pt", padding="longest", sampling_rate=rate).input_values
|
45 |
+
logits = model(input_values).logits
|
46 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
47 |
+
text = processor.batch_decode(predicted_ids)
|
48 |
+
nlp_sa = pipeline("sentiment-analysis")
|
49 |
+
st.write(nlp_sa(text))
|
50 |
+
|
51 |
+
if st.button('Name'):
|
52 |
+
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-960h")
|
53 |
+
model = HubertForCTC.from_pretrained("facebook/hubert-large-ls960-ft")
|
54 |
+
speech, rate = librosa.load(audio_file, sr=16000)
|
55 |
+
input_values = processor(speech, return_tensors="pt", padding="longest", sampling_rate=rate).input_values
|
56 |
+
logits = model(input_values).logits
|
57 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
58 |
+
text = processor.batch_decode(predicted_ids)
|
59 |
+
str = ''.join(text)
|
60 |
+
trf = spacy.load('en_core_web_trf')
|
61 |
+
doc=trf(str)
|
62 |
+
print(displacy.render(doc,style='ent'))
|