jmparejaz commited on
Commit
e4a6674
1 Parent(s): 8e06a33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -2
app.py CHANGED
@@ -2,10 +2,21 @@ import os
2
  os.system("pip install git+https://github.com/openai/whisper.git")
3
  import gradio as gr
4
  import whisper
 
 
5
 
 
 
 
 
 
 
 
6
  model = whisper.load_model("small")
7
 
8
- def inference(audio):
 
 
9
  audio = whisper.load_audio(audio)
10
  audio = whisper.pad_or_trim(audio)
11
 
@@ -19,6 +30,15 @@ def inference(audio):
19
  print(result.text)
20
  return result.text, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
21
 
 
 
 
 
 
 
 
 
 
22
  block = gr.Blocks()
23
  with block:
24
  with gr.Group():
@@ -37,9 +57,14 @@ with block:
37
 
38
 
39
 
40
- btn.click(inference, inputs=[audio], outputs=[text])
41
 
42
 
43
  block.launch()
44
 
45
 
 
 
 
 
 
 
2
  os.system("pip install git+https://github.com/openai/whisper.git")
3
  import gradio as gr
4
  import whisper
5
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
6
+ from transformers import pipeline
7
 
8
+
9
+ #call tokenizer and NLP model for text classification
10
+ tokenizer = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment-latest")
11
+ model_nlp = AutoModelForSequenceClassification.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment-latest")
12
+ config = AutoConfig.from_pretrained(model_nlp)
13
+
14
+ # call whisper model for audio/speech processing
15
  model = whisper.load_model("small")
16
 
17
+
18
+
19
+ def inference_audio(audio):
20
  audio = whisper.load_audio(audio)
21
  audio = whisper.pad_or_trim(audio)
22
 
 
30
  print(result.text)
31
  return result.text, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
32
 
33
+ def inference_text(audio):
34
+ text,_,_,_ =inference_audio(audio)
35
+
36
+ sentiment_task = pipeline("sentiment-analysis", model=model_nlp, tokenizer=tokenizer)
37
+ result=sentiment_task(text)
38
+ return result
39
+
40
+
41
+
42
  block = gr.Blocks()
43
  with block:
44
  with gr.Group():
 
57
 
58
 
59
 
60
+ btn.click(inference_text, inputs=[audio], outputs=[text])
61
 
62
 
63
  block.launch()
64
 
65
 
66
+
67
+ from transformers import pipeline
68
+ sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
69
+ sentiment_task("Covid cases are increasing fast!")
70
+