Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -36,21 +36,29 @@ def analyze_text(icelandic_text):
|
|
36 |
formality_label, formality_score = analyze_formality(icelandic_text)
|
37 |
sentiment_label, sentiment_score = analyze_sentiment(icelandic_text)
|
38 |
|
|
|
|
|
|
|
39 |
translated_text = translate_text(icelandic_text)
|
40 |
|
41 |
toxicity_results = analyze_toxicity(translated_text)
|
42 |
if isinstance(toxicity_results, list):
|
43 |
toxicity_results = toxicity_results[0]
|
|
|
|
|
|
|
44 |
|
45 |
politeness_label, politeness_score = analyze_politeness(translated_text)
|
|
|
|
|
46 |
|
47 |
-
analysis_results =
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
return analysis_results
|
55 |
|
56 |
demo = gr.Interface(fn=analyze_text,
|
|
|
36 |
formality_label, formality_score = analyze_formality(icelandic_text)
|
37 |
sentiment_label, sentiment_score = analyze_sentiment(icelandic_text)
|
38 |
|
39 |
+
# Convert sentiment label
|
40 |
+
sentiment_label = sentiment_label.replace("LABEL_", "")
|
41 |
+
|
42 |
translated_text = translate_text(icelandic_text)
|
43 |
|
44 |
toxicity_results = analyze_toxicity(translated_text)
|
45 |
if isinstance(toxicity_results, list):
|
46 |
toxicity_results = toxicity_results[0]
|
47 |
+
|
48 |
+
# Determine toxicity label based on score
|
49 |
+
toxicity_label = '1' if toxicity_results['score'] >= 0.5 else '0'
|
50 |
|
51 |
politeness_label, politeness_score = analyze_politeness(translated_text)
|
52 |
+
# Convert politeness label to binary
|
53 |
+
politeness_label = '1' if politeness_label.lower() == 'polite' else '0'
|
54 |
|
55 |
+
analysis_results = (
|
56 |
+
f"Translated Text: {translated_text}\n\n"
|
57 |
+
f"Sentiment: Label: {sentiment_label}, Score: {round(sentiment_score, 2)}\n"
|
58 |
+
f"Formality: Label: {round(formality_score, 2)}, Score: {round(formality_score, 2)}\n"
|
59 |
+
f"Toxicity: Label: {toxicity_label}, Score: {round(toxicity_results['score'], 2)}\n"
|
60 |
+
f"Politeness: Label: {politeness_label}, Score: {round(politeness_score, 2)}"
|
61 |
+
)
|
62 |
return analysis_results
|
63 |
|
64 |
demo = gr.Interface(fn=analyze_text,
|