Update functions.py
Browse files- functions.py +18 -1
functions.py
CHANGED
@@ -65,12 +65,29 @@ def inference(link, upload):
|
|
65 |
results = asr_model.transcribe(upload)
|
66 |
|
67 |
return results, "Transcribed Earnings Audio"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
@st.experimental_memo(suppress_st_warning=True)
|
70 |
def sentiment_pipe(earnings_text):
|
71 |
'''Determine the sentiment of the text'''
|
72 |
|
73 |
-
earnings_sentences =
|
74 |
earnings_sentiment = sent_pipe(earnings_sentences)
|
75 |
|
76 |
return earnings_sentiment, earnings_sentences
|
|
|
65 |
results = asr_model.transcribe(upload)
|
66 |
|
67 |
return results, "Transcribed Earnings Audio"
|
68 |
+
|
69 |
+
@st.experimental_memo(suppress_st_warning=True)
|
70 |
+
def chunk_long_text(text,threshold):
|
71 |
+
'''Chunk long text'''
|
72 |
+
sentences = sent_tokenize(text)
|
73 |
+
out = []
|
74 |
+
|
75 |
+
for chunk in sentences:
|
76 |
+
if len(chunk.split()) < threshold:
|
77 |
+
out.append(chunk)
|
78 |
+
else:
|
79 |
+
words = chunk.split()
|
80 |
+
num = int(len(words)/threshold)
|
81 |
+
for i in range(0,num*threshold+1,threshold):
|
82 |
+
out.append(' '.join(words[i:threshold+i]))
|
83 |
+
|
84 |
+
return out
|
85 |
|
86 |
@st.experimental_memo(suppress_st_warning=True)
|
87 |
def sentiment_pipe(earnings_text):
|
88 |
'''Determine the sentiment of the text'''
|
89 |
|
90 |
+
earnings_sentences = chunk_long_text(earnings_text,400)
|
91 |
earnings_sentiment = sent_pipe(earnings_sentences)
|
92 |
|
93 |
return earnings_sentiment, earnings_sentences
|