Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -25,10 +25,7 @@ politeness_bench = Benchmark(politeness_model, politeness_tokenizer)
|
|
25 |
|
26 |
# Initialize pipelines for translation and classifiers
|
27 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-is-en")
|
28 |
-
sentiment_classifier = pipeline("text-classification", model="Birkir/electra-base-igc-is-sentiment-analysis")
|
29 |
-
formality_classifier = pipeline("text-classification", model="svanhvit/formality-classification-icebert")
|
30 |
detoxify_pipeline = pipeline('text-classification', model='unitary/toxic-bert', tokenizer='bert-base-uncased', function_to_apply='sigmoid', top_k=None)
|
31 |
-
politeness_classifier = pipeline("text-classification", model="Genius1237/xlm-roberta-large-tydip")
|
32 |
|
33 |
def replace_encoding(tokens):
|
34 |
return [token.replace('臓', ' ')
|
@@ -64,26 +61,18 @@ def analyze_with_influence(text, bench):
|
|
64 |
|
65 |
def analyze_text(icelandic_text):
|
66 |
translated_text = translator(icelandic_text, max_length=512)[0]['translation_text']
|
67 |
-
sentiment_label, sentiment_score = analyze_sentiment(icelandic_text)
|
68 |
-
formality_label, formality_score = analyze_formality(icelandic_text)
|
69 |
-
toxicity_label, toxicity_score = analyze_toxicity(translated_text)
|
70 |
-
politeness_label, politeness_score = analyze_politeness(translated_text)
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
|
77 |
analysis_results = f"""
|
78 |
Translated Text: {translated_text}\n\n
|
79 |
-
Sentiment
|
80 |
-
Influential Words
|
81 |
-
|
82 |
-
Influential Words
|
83 |
-
Toxicity: {toxicity_label}, Score: {round(toxicity_score, 2)}\n
|
84 |
-
Influential Words in Toxicity: {toxicity_influential_words}\n
|
85 |
-
Politeness: {politeness_label}, Score: {round(politeness_score, 2)}\n
|
86 |
-
Influential Words in Politeness: {politeness_influential_words}
|
87 |
"""
|
88 |
return analysis_results.strip()
|
89 |
|
@@ -91,7 +80,7 @@ demo = gr.Interface(fn=analyze_text,
|
|
91 |
inputs=gr.Textbox(lines=2, placeholder="Enter Icelandic Text Here..."),
|
92 |
outputs=gr.Textbox(label="Analysis Results"),
|
93 |
title="Icelandic Text Analysis",
|
94 |
-
description="This app translates Icelandic text to English and performs sentiment, formality, toxicity, and politeness
|
95 |
|
96 |
if __name__ == "__main__":
|
97 |
demo.launch()
|
|
|
25 |
|
26 |
# Initialize pipelines for translation and classifiers
|
27 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-is-en")
|
|
|
|
|
28 |
detoxify_pipeline = pipeline('text-classification', model='unitary/toxic-bert', tokenizer='bert-base-uncased', function_to_apply='sigmoid', top_k=None)
|
|
|
29 |
|
30 |
def replace_encoding(tokens):
|
31 |
return [token.replace('臓', ' ')
|
|
|
61 |
|
62 |
def analyze_text(icelandic_text):
|
63 |
translated_text = translator(icelandic_text, max_length=512)[0]['translation_text']
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
sentiment_analysis = analyze_with_influence(icelandic_text, sentiment_bench)
|
66 |
+
formality_analysis = analyze_with_influence(icelandic_text, formality_bench)
|
67 |
+
toxicity_analysis = analyze_with_influence(translated_text, toxicity_bench)
|
68 |
+
politeness_analysis = analyze_with_influence(translated_text, politeness_bench)
|
69 |
|
70 |
analysis_results = f"""
|
71 |
Translated Text: {translated_text}\n\n
|
72 |
+
Sentiment Analysis with Influential Words: {sentiment_analysis}\n
|
73 |
+
Formality Analysis with Influential Words: {formality_analysis}\n
|
74 |
+
Toxicity Analysis with Influential Words: {toxicity_analysis}\n
|
75 |
+
Politeness Analysis with Influential Words: {politeness_analysis}
|
|
|
|
|
|
|
|
|
76 |
"""
|
77 |
return analysis_results.strip()
|
78 |
|
|
|
80 |
inputs=gr.Textbox(lines=2, placeholder="Enter Icelandic Text Here..."),
|
81 |
outputs=gr.Textbox(label="Analysis Results"),
|
82 |
title="Icelandic Text Analysis",
|
83 |
+
description="This app translates Icelandic text to English and performs analysis with influential words for sentiment, formality, toxicity, and politeness.")
|
84 |
|
85 |
if __name__ == "__main__":
|
86 |
demo.launch()
|