AhmedTaha012 commited on
Commit
b54a28b
1 Parent(s): e898e49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
- from transformers import AutoTokenizer,AutoModelForTokenClassification,AutoModelForSequenceClassification
4
  import math
5
  import nltk
6
  import torch
@@ -15,7 +15,8 @@ nltk.download('stopwords')
15
 
16
  similarityModel = SentenceTransformer('BAAI/bge-small-en')
17
  sentiment_model = pipeline("text-classification", model="AhmedTaha012/managersFeedback-V1.0.7")
18
- increase_decrease_model = pipeline("text-classification", model="AhmedTaha012/nextQuarter-status-V1.1.9")
 
19
  tokenizerTopic = AutoTokenizer.from_pretrained("nickmuchi/finbert-tone-finetuned-finance-topic-classification",use_fast=True,token="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")
20
  modelTopic = AutoModelForSequenceClassification.from_pretrained("nickmuchi/finbert-tone-finetuned-finance-topic-classification",token="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")
21
  # torch.compile(modelTopic)
@@ -224,6 +225,13 @@ def selectedCorpusForNextQuarterModel(x,quarter,year):
224
  sents=[des]+courpus
225
  rest=[sents[f] for f in [list(cosine_similarity(embeddings_1)[0][1:]).index(value)+1 for value in sorted(list(cosine_similarity(embeddings_1)[0][1:]),reverse=True)][:3]]
226
  return ",".join(rest)
 
 
 
 
 
 
 
227
 
228
  st.header("Transcript Analysis", divider='rainbow')
229
  mainTranscript = st.text_area("Enter the transcript:", height=100)
@@ -246,8 +254,7 @@ if st.button("Analyze"):
246
  st.markdown(f'<span style="color:{sentiment_color}">{sentiment}</span>', unsafe_allow_html=True)
247
  st.subheader("Next Quarter Perdiction", divider='rainbow')
248
  # increase_decrease = [increase_decrease_model(x)[0]['label'] for x in chunks]
249
- increase_decrease=increase_decrease_model(selectedCorpusForNextQuarterModel(mainTranscript,quarter,year))[0]['label']
250
- increase_decrease=max(increase_decrease,key=increase_decrease.count)
251
  increase_decrease_color = "green" if increase_decrease == "Increase" else "red"
252
  st.markdown(f'<span style="color:{increase_decrease_color}">{increase_decrease}</span>', unsafe_allow_html=True)
253
  st.subheader("Financial Metrics", divider='rainbow')
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+ from transformers import AutoTokenizer,AutoModelForTokenClassification,AutoModelForSequenceClassification,BertForSequenceClassification
4
  import math
5
  import nltk
6
  import torch
 
15
 
16
  similarityModel = SentenceTransformer('BAAI/bge-small-en')
17
  sentiment_model = pipeline("text-classification", model="AhmedTaha012/managersFeedback-V1.0.7")
18
+ tokenizerQuarter = AutoTokenizer.from_pretrained('AhmedTaha012/nextQuarter-status-V1.1.9')
19
+ modelQuarter = BertForSequenceClassification.from_pretrained('AhmedTaha012/nextQuarter-status-V1.1.9')
20
  tokenizerTopic = AutoTokenizer.from_pretrained("nickmuchi/finbert-tone-finetuned-finance-topic-classification",use_fast=True,token="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")
21
  modelTopic = AutoModelForSequenceClassification.from_pretrained("nickmuchi/finbert-tone-finetuned-finance-topic-classification",token="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")
22
  # torch.compile(modelTopic)
 
225
  sents=[des]+courpus
226
  rest=[sents[f] for f in [list(cosine_similarity(embeddings_1)[0][1:]).index(value)+1 for value in sorted(list(cosine_similarity(embeddings_1)[0][1:]),reverse=True)][:3]]
227
  return ",".join(rest)
228
+ def getQuarterPrediction(text):
229
+ tokens=tokenizerQuarter(text,padding=True,max_length=512,return_overflowing_tokens=False,add_special_tokens=True,truncation=True,return_tensors="pt")
230
+ with torch.no_grad():
231
+ logits = modelQuarter(**tokens).logits
232
+ predicted_class_id = logits.argmax().item()
233
+ return modelQuarter.config.id2label[predicted_class_id]
234
+
235
 
236
  st.header("Transcript Analysis", divider='rainbow')
237
  mainTranscript = st.text_area("Enter the transcript:", height=100)
 
254
  st.markdown(f'<span style="color:{sentiment_color}">{sentiment}</span>', unsafe_allow_html=True)
255
  st.subheader("Next Quarter Perdiction", divider='rainbow')
256
  # increase_decrease = [increase_decrease_model(x)[0]['label'] for x in chunks]
257
+ increase_decrease=getQuarterPrediction(selectedCorpusForNextQuarterModel(mainTranscript,quarter,year))
 
258
  increase_decrease_color = "green" if increase_decrease == "Increase" else "red"
259
  st.markdown(f'<span style="color:{increase_decrease_color}">{increase_decrease}</span>', unsafe_allow_html=True)
260
  st.subheader("Financial Metrics", divider='rainbow')