Cachoups commited on
Commit
99d35a2
·
verified ·
1 Parent(s): cca76af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -81,10 +81,15 @@ def process_paragraph_1_sent(paragraph):
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
- formatted_results = "\n".join([f"{result['label']}: {result['score']:.2f}" for result in results])
85
- return formatted_results
 
 
 
 
 
86
  except (IndexError, ValueError):
87
- return "Error"
88
  def process_paragraph_1_sent_tone(paragraph):
89
  try:
90
  paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
@@ -114,10 +119,15 @@ def process_paragraph_2_sent(paragraph):
114
  paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
115
  selected_paragraph = stored_paragraphs_2[paragraph_index]
116
  results = text_to_sentiment(selected_paragraph)
117
- formatted_results = "\n".join([f"{result['label']}: {result['score']:.2f}" for result in results])
118
- return formatted_results
 
 
 
 
 
119
  except (IndexError, ValueError):
120
- return "Error"
121
  def process_paragraph_2_sent_tone(paragraph):
122
  try:
123
  paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
 
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
+ if isinstance(results, list) and isinstance(results[0], dict):
85
+ # Create a dictionary from the results
86
+ output = {result['label']: result['score'] for result in results}
87
+ else:
88
+ output = {"Error": "Unexpected output format"}
89
+
90
+ return output
91
  except (IndexError, ValueError):
92
+ return {"Error": "Unexpected output format"}
93
  def process_paragraph_1_sent_tone(paragraph):
94
  try:
95
  paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
 
119
  paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
120
  selected_paragraph = stored_paragraphs_2[paragraph_index]
121
  results = text_to_sentiment(selected_paragraph)
122
+ if isinstance(results, list) and isinstance(results[0], dict):
123
+ # Create a dictionary from the results
124
+ output = {result['label']: result['score'] for result in results}
125
+ else:
126
+ output = {"Error": "Unexpected output format"}
127
+
128
+ return output
129
  except (IndexError, ValueError):
130
+ {"Error": "Unexpected output format"}
131
  def process_paragraph_2_sent_tone(paragraph):
132
  try:
133
  paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1