rajistics commited on
Commit
54d9bd0
1 Parent(s): 6a6f517

tried refactoring code

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -4,7 +4,20 @@ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassifica
4
  import gradio as gr
5
  import spacy
6
  nlp = spacy.load('en_core_web_sm')
 
7
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  auth_token = os.environ.get("HF_Token")
9
 
10
  ##Speech Recognition
@@ -37,19 +50,9 @@ def fin_ner(text):
37
 
38
  ##Fiscal Sentiment by Sentence
39
  def fin_ext(text):
40
- doc = nlp(text)
41
- doc_sents = [sent for sent in doc.sents]
42
- sents_list = []
43
- for sent in doc.sents:
44
- sents_list.append(sent.text)
45
- results = fin_model(sents_list)
46
- results_list = []
47
- for i in range(len(results)):
48
- results_list.append(results[i]['label'])
49
- fin_spans = []
50
- fin_spans = list(zip(sents_list,results_list))
51
- return fin_spans
52
-
53
  ##Forward Looking Statement
54
  def fls(text):
55
  doc = nlp(text)
 
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]
12
+
13
+ def make_spans(text,results):
14
+ results_list = []
15
+ for i in range(len(results)):
16
+ results_list.append(results[i]['label'])
17
+ facts_spans = []
18
+ facts_spans = list(zip(split_in_sentences(text),results_list))
19
+ return facts_spans
20
+
21
  auth_token = os.environ.get("HF_Token")
22
 
23
  ##Speech Recognition
 
50
 
51
  ##Fiscal Sentiment by Sentence
52
  def fin_ext(text):
53
+ results = fin_model(split_in_sentences(text))
54
+ return make_spans(text,results)
55
+
 
 
 
 
 
 
 
 
 
 
56
  ##Forward Looking Statement
57
  def fls(text):
58
  doc = nlp(text)