knkarthick commited on
Commit
a1b7ef7
1 Parent(s): 1ca9d41

First Model Version

Browse files
Files changed (2) hide show
  1. .ipynb_checkpoints/app-checkpoint.py +28 -0
  2. app.py +28 -0
.ipynb_checkpoints/app-checkpoint.py CHANGED
@@ -1,11 +1,32 @@
1
  import os
2
  os.system("pip install gradio==3.0.18")
 
3
  from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification
4
  import gradio as gr
 
5
  import spacy
6
  nlp = spacy.load('en_core_web_sm')
7
  nlp.add_pipe('sentencizer')
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  def split_in_sentences(text):
10
  doc = nlp(text)
11
  return [str(sent).strip() for sent in doc.sents]
@@ -72,6 +93,13 @@ with demo:
72
  with gr.Row():
73
  text = gr.Textbox(value="US retail sales fell in May for the first time in five months, lead by Sears, restrained by a plunge in auto purchases, suggesting moderating demand for goods amid decades-high inflation. The value of overall retail purchases decreased 0.3%, after a downwardly revised 0.7% gain in April, Commerce Department figures showed Wednesday. Excluding Tesla vehicles, sales rose 0.5% last month. The department expects inflation to continue to rise.")
74
  b1.click(speech_to_text, inputs=audio_file, outputs=text)
 
 
 
 
 
 
 
75
  with gr.Row():
76
  b2 = gr.Button("Overall Sentiment Analysis of Dialogues")
77
  fin_spans = gr.HighlightedText()
1
  import os
2
  os.system("pip install gradio==3.0.18")
3
+ os.system("pip install git+https://github.com/openai/whisper.git")
4
  from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification
5
  import gradio as gr
6
+ import whisper
7
  import spacy
8
  nlp = spacy.load('en_core_web_sm')
9
  nlp.add_pipe('sentencizer')
10
 
11
+
12
+ model = whisper.load_model("small")
13
+ def inference(audio):
14
+ audio = whisper.load_audio(audio)
15
+ audio = whisper.pad_or_trim(audio)
16
+
17
+ mel = whisper.log_mel_spectrogram(audio).to(model.device)
18
+
19
+ _, probs = model.detect_language(mel)
20
+
21
+ options = whisper.DecodingOptions(fp16 = False)
22
+ result = whisper.decode(model, mel, options)
23
+
24
+ return result["text"]
25
+
26
+ def inference-full(audio):
27
+ result = model.transcribe(audio)
28
+ return result["text"]
29
+
30
  def split_in_sentences(text):
31
  doc = nlp(text)
32
  return [str(sent).strip() for sent in doc.sents]
93
  with gr.Row():
94
  text = gr.Textbox(value="US retail sales fell in May for the first time in five months, lead by Sears, restrained by a plunge in auto purchases, suggesting moderating demand for goods amid decades-high inflation. The value of overall retail purchases decreased 0.3%, after a downwardly revised 0.7% gain in April, Commerce Department figures showed Wednesday. Excluding Tesla vehicles, sales rose 0.5% last month. The department expects inflation to continue to rise.")
95
  b1.click(speech_to_text, inputs=audio_file, outputs=text)
96
+ with gr.Row():
97
+ text = gr.Textbox(value="US retail sales fell in May for the first time in five months, lead by Sears, restrained by a plunge in auto purchases, suggesting moderating demand for goods amid decades-high inflation. The value of overall retail purchases decreased 0.3%, after a downwardly revised 0.7% gain in April, Commerce Department figures showed Wednesday. Excluding Tesla vehicles, sales rose 0.5% last month. The department expects inflation to continue to rise.")
98
+ b1.click(inference, inputs=audio_file, outputs=text)
99
+ with gr.Row():
100
+ text = gr.Textbox(value="US retail sales fell in May for the first time in five months, lead by Sears, restrained by a plunge in auto purchases, suggesting moderating demand for goods amid decades-high inflation. The value of overall retail purchases decreased 0.3%, after a downwardly revised 0.7% gain in April, Commerce Department figures showed Wednesday. Excluding Tesla vehicles, sales rose 0.5% last month. The department expects inflation to continue to rise.")
101
+ b1.click(inference-full, inputs=audio_file, outputs=text)
102
+
103
  with gr.Row():
104
  b2 = gr.Button("Overall Sentiment Analysis of Dialogues")
105
  fin_spans = gr.HighlightedText()
app.py CHANGED
@@ -1,11 +1,32 @@
1
  import os
2
  os.system("pip install gradio==3.0.18")
 
3
  from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification
4
  import gradio as gr
 
5
  import spacy
6
  nlp = spacy.load('en_core_web_sm')
7
  nlp.add_pipe('sentencizer')
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  def split_in_sentences(text):
10
  doc = nlp(text)
11
  return [str(sent).strip() for sent in doc.sents]
@@ -72,6 +93,13 @@ with demo:
72
  with gr.Row():
73
  text = gr.Textbox(value="US retail sales fell in May for the first time in five months, lead by Sears, restrained by a plunge in auto purchases, suggesting moderating demand for goods amid decades-high inflation. The value of overall retail purchases decreased 0.3%, after a downwardly revised 0.7% gain in April, Commerce Department figures showed Wednesday. Excluding Tesla vehicles, sales rose 0.5% last month. The department expects inflation to continue to rise.")
74
  b1.click(speech_to_text, inputs=audio_file, outputs=text)
 
 
 
 
 
 
 
75
  with gr.Row():
76
  b2 = gr.Button("Overall Sentiment Analysis of Dialogues")
77
  fin_spans = gr.HighlightedText()
1
  import os
2
  os.system("pip install gradio==3.0.18")
3
+ os.system("pip install git+https://github.com/openai/whisper.git")
4
  from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification
5
  import gradio as gr
6
+ import whisper
7
  import spacy
8
  nlp = spacy.load('en_core_web_sm')
9
  nlp.add_pipe('sentencizer')
10
 
11
+
12
+ model = whisper.load_model("small")
13
+ def inference(audio):
14
+ audio = whisper.load_audio(audio)
15
+ audio = whisper.pad_or_trim(audio)
16
+
17
+ mel = whisper.log_mel_spectrogram(audio).to(model.device)
18
+
19
+ _, probs = model.detect_language(mel)
20
+
21
+ options = whisper.DecodingOptions(fp16 = False)
22
+ result = whisper.decode(model, mel, options)
23
+
24
+ return result["text"]
25
+
26
+ def inference-full(audio):
27
+ result = model.transcribe(audio)
28
+ return result["text"]
29
+
30
  def split_in_sentences(text):
31
  doc = nlp(text)
32
  return [str(sent).strip() for sent in doc.sents]
93
  with gr.Row():
94
  text = gr.Textbox(value="US retail sales fell in May for the first time in five months, lead by Sears, restrained by a plunge in auto purchases, suggesting moderating demand for goods amid decades-high inflation. The value of overall retail purchases decreased 0.3%, after a downwardly revised 0.7% gain in April, Commerce Department figures showed Wednesday. Excluding Tesla vehicles, sales rose 0.5% last month. The department expects inflation to continue to rise.")
95
  b1.click(speech_to_text, inputs=audio_file, outputs=text)
96
+ with gr.Row():
97
+ text = gr.Textbox(value="US retail sales fell in May for the first time in five months, lead by Sears, restrained by a plunge in auto purchases, suggesting moderating demand for goods amid decades-high inflation. The value of overall retail purchases decreased 0.3%, after a downwardly revised 0.7% gain in April, Commerce Department figures showed Wednesday. Excluding Tesla vehicles, sales rose 0.5% last month. The department expects inflation to continue to rise.")
98
+ b1.click(inference, inputs=audio_file, outputs=text)
99
+ with gr.Row():
100
+ text = gr.Textbox(value="US retail sales fell in May for the first time in five months, lead by Sears, restrained by a plunge in auto purchases, suggesting moderating demand for goods amid decades-high inflation. The value of overall retail purchases decreased 0.3%, after a downwardly revised 0.7% gain in April, Commerce Department figures showed Wednesday. Excluding Tesla vehicles, sales rose 0.5% last month. The department expects inflation to continue to rise.")
101
+ b1.click(inference-full, inputs=audio_file, outputs=text)
102
+
103
  with gr.Row():
104
  b2 = gr.Button("Overall Sentiment Analysis of Dialogues")
105
  fin_spans = gr.HighlightedText()