Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -28,24 +28,21 @@ def analyze_sentiment(text):
|
|
| 28 |
|
| 29 |
def analyze_ner(text):
|
| 30 |
predictions = clf_ner(text)
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
keys.append(f'LABEL_{i}')
|
| 36 |
-
values.append(label)
|
| 37 |
-
|
| 38 |
-
label_mapping = {k: v for (k, v) in zip(keys, values)}
|
| 39 |
|
| 40 |
results = []
|
| 41 |
for pred in predictions:
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
)
|
| 47 |
|
| 48 |
return "\n".join(results)
|
|
|
|
| 49 |
def analyze_text(text):
|
| 50 |
sentiment_result = analyze_sentiment(text)
|
| 51 |
ner_result = analyze_ner(text)
|
|
|
|
| 28 |
|
| 29 |
def analyze_ner(text):
|
| 30 |
predictions = clf_ner(text)
|
| 31 |
+
print(predictions) # Debugging statement to see the structure of the output
|
| 32 |
|
| 33 |
+
# Create label mapping from id2label
|
| 34 |
+
label_mapping = {f'LABEL_{i}': label for i, label in enumerate(label_list)}
|
| 35 |
+
print(label_mapping) # Debugging statement to see the label mapping
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
results = []
|
| 38 |
for pred in predictions:
|
| 39 |
+
word = pred['word']
|
| 40 |
+
tag = label_mapping[pred['entity']]
|
| 41 |
+
confidence = pred['score']
|
| 42 |
+
results.append(f"Word: {word}\nPredicted Tag: {tag}\nConfidence Probability: {confidence:.2f}\n")
|
|
|
|
| 43 |
|
| 44 |
return "\n".join(results)
|
| 45 |
+
|
| 46 |
def analyze_text(text):
|
| 47 |
sentiment_result = analyze_sentiment(text)
|
| 48 |
ner_result = analyze_ner(text)
|