Cachoups commited on
Commit
9e963c0
·
verified ·
1 Parent(s): e853829

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -31,8 +31,8 @@ def summarize_text(text):
31
  resp = summarizer(text)
32
  return resp[0]['summary_text']
33
 
34
- def text_to_sentiment(text):
35
- sentiment = fin_model(text)[0]["label"]
36
  return sentiment
37
 
38
  def fin_ext(text):
@@ -80,8 +80,13 @@ def process_paragraph_1_sent(paragraph):
80
  try:
81
  paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
82
  selected_paragraph = stored_paragraphs_1[paragraph_index]
83
- results = text_to_sentiment(selected_paragraph)
84
- return results
 
 
 
 
 
85
  except (IndexError, ValueError):
86
  return {"Error": "Unexpected output format"}
87
  def process_paragraph_1_sent_tone(paragraph):
@@ -112,8 +117,13 @@ def process_paragraph_2_sent(paragraph):
112
  try:
113
  paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
114
  selected_paragraph = stored_paragraphs_2[paragraph_index]
115
- results = text_to_sentiment(selected_paragraph)
116
- return results
 
 
 
 
 
117
  except (IndexError, ValueError):
118
  return {"Error": "Unexpected output format"}
119
  def process_paragraph_2_sent_tone(paragraph):
 
31
  resp = summarizer(text)
32
  return resp[0]['summary_text']
33
 
34
+ def text_to_sentiment(text, all_score=False):
35
+ sentiment = fin_model(text, return_all_scores=all_score))[0]["label"]
36
  return sentiment
37
 
38
  def fin_ext(text):
 
80
  try:
81
  paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
82
  selected_paragraph = stored_paragraphs_1[paragraph_index]
83
+ results = text_to_sentiment(selected_paragraph, True)
84
+ if isinstance(results, list) and isinstance(results[0], list):
85
+ # We unpack the list of dictionaries to get all labels
86
+ output = {result['label']: result['score'] for result in results[0]}
87
+ else:
88
+ output = {"Error": "Unexpected output format"}
89
+ return output
90
  except (IndexError, ValueError):
91
  return {"Error": "Unexpected output format"}
92
  def process_paragraph_1_sent_tone(paragraph):
 
117
  try:
118
  paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
119
  selected_paragraph = stored_paragraphs_2[paragraph_index]
120
+ results = text_to_sentiment(selected_paragraph, True)
121
+ if isinstance(results, list) and isinstance(results[0], list):
122
+ # We unpack the list of dictionaries to get all labels
123
+ output = {result['label']: result['score'] for result in results[0]}
124
+ else:
125
+ output = {"Error": "Unexpected output format"}
126
+ return output
127
  except (IndexError, ValueError):
128
  return {"Error": "Unexpected output format"}
129
  def process_paragraph_2_sent_tone(paragraph):