krishnasai99 commited on
Commit
d41c42c
1 Parent(s): a89bf70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -41
app.py CHANGED
@@ -1,41 +1,62 @@
1
- import streamlit as st
2
- from transformers import pipeline
3
-
4
- #def load_summarizer():#
5
- # whisper = pipeline('automatic-speech-recognition') #audio-to-text
6
- # summarize = pipeline("summarization", device=0)
7
- # senti = pipeline("sentiment-analysis",device=0)
8
- #nameentity = pipeline("ner",device=0)
9
- #translate = pipeline("translation", device=0)
10
- #return whisper, summarize, senti, nameentity, translate
11
-
12
- st.subheader("Choose a mp3 file that you extracted from the work site")
13
- uploaded_file = st.file_uploader("Select file from your directory")
14
- if uploaded_file is not None:
15
- audio_bytes = uploaded_file.read()
16
- text = st.audio(audio_bytes, format='audio/mp3')
17
-
18
-
19
- pipe = pipeline("automatic-speech-recognition")
20
- #text = st.text_area('Enter some Text!')
21
-
22
-
23
- #summarizer = load_summarizer()
24
- #st.title("Summarize Text")
25
- #sentence = st.text_area('Please paste your article :', height=30)
26
- button = st.button("Click")
27
-
28
-
29
-
30
- if text:
31
- out=pipe(text)
32
- st.json(out)
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'))