Update functions.py
Browse files- functions.py +7 -7
functions.py
CHANGED
@@ -6,7 +6,7 @@ import plotly_express as px
|
|
6 |
import nltk
|
7 |
import plotly.graph_objects as go
|
8 |
from optimum.onnxruntime import ORTModelForSequenceClassification
|
9 |
-
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification
|
10 |
from sentence_transformers import SentenceTransformer, CrossEncoder, util
|
11 |
import streamlit as st
|
12 |
import en_core_web_lg
|
@@ -29,8 +29,8 @@ margin-bottom: 2.5rem">{}</div> """
|
|
29 |
|
30 |
@st.experimental_singleton(suppress_st_warning=True)
|
31 |
def load_models():
|
32 |
-
|
33 |
-
asr_pipe = pipeline("automatic-speech-recognition",model = "openai/whisper-small")
|
34 |
q_model = ORTModelForSequenceClassification.from_pretrained("nickmuchi/quantized-optimum-finbert-tone")
|
35 |
ner_model = AutoModelForTokenClassification.from_pretrained("xlm-roberta-large-finetuned-conll03-english")
|
36 |
q_tokenizer = AutoTokenizer.from_pretrained("nickmuchi/quantized-optimum-finbert-tone")
|
@@ -41,7 +41,7 @@ def load_models():
|
|
41 |
sbert = SentenceTransformer("all-mpnet-base-v2")
|
42 |
cross_encoder = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-12-v2')
|
43 |
|
44 |
-
return
|
45 |
|
46 |
@st.experimental_singleton(suppress_st_warning=True)
|
47 |
def get_spacy():
|
@@ -57,12 +57,12 @@ def inference(link, upload):
|
|
57 |
yt = YouTube(link)
|
58 |
title = yt.title
|
59 |
path = yt.streams.filter(only_audio=True)[0].download(filename="audio.mp4")
|
60 |
-
results =
|
61 |
|
62 |
return results['text'], yt.title
|
63 |
|
64 |
elif upload:
|
65 |
-
results =
|
66 |
|
67 |
return results['text'], "Transcribed Earnings Audio"
|
68 |
|
@@ -306,4 +306,4 @@ def fin_ext(text):
|
|
306 |
return make_spans(text,results)
|
307 |
|
308 |
nlp = get_spacy()
|
309 |
-
|
|
|
6 |
import nltk
|
7 |
import plotly.graph_objects as go
|
8 |
from optimum.onnxruntime import ORTModelForSequenceClassification
|
9 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification
|
10 |
from sentence_transformers import SentenceTransformer, CrossEncoder, util
|
11 |
import streamlit as st
|
12 |
import en_core_web_lg
|
|
|
29 |
|
30 |
@st.experimental_singleton(suppress_st_warning=True)
|
31 |
def load_models():
|
32 |
+
asr_model = whisper.load_model("base")
|
33 |
+
#asr_pipe = pipeline("automatic-speech-recognition",model = "openai/whisper-small")
|
34 |
q_model = ORTModelForSequenceClassification.from_pretrained("nickmuchi/quantized-optimum-finbert-tone")
|
35 |
ner_model = AutoModelForTokenClassification.from_pretrained("xlm-roberta-large-finetuned-conll03-english")
|
36 |
q_tokenizer = AutoTokenizer.from_pretrained("nickmuchi/quantized-optimum-finbert-tone")
|
|
|
41 |
sbert = SentenceTransformer("all-mpnet-base-v2")
|
42 |
cross_encoder = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-12-v2')
|
43 |
|
44 |
+
return asr_model, sent_pipe, sum_pipe, ner_pipe, sbert, cross_encoder
|
45 |
|
46 |
@st.experimental_singleton(suppress_st_warning=True)
|
47 |
def get_spacy():
|
|
|
57 |
yt = YouTube(link)
|
58 |
title = yt.title
|
59 |
path = yt.streams.filter(only_audio=True)[0].download(filename="audio.mp4")
|
60 |
+
results = asr_model.transcribe(path)
|
61 |
|
62 |
return results['text'], yt.title
|
63 |
|
64 |
elif upload:
|
65 |
+
results = asr_model.trasncribe(upload)
|
66 |
|
67 |
return results['text'], "Transcribed Earnings Audio"
|
68 |
|
|
|
306 |
return make_spans(text,results)
|
307 |
|
308 |
nlp = get_spacy()
|
309 |
+
asr_model, sent_pipe, sum_pipe, ner_pipe, sbert, cross_encoder = load_models()
|