Update app.py
Browse files
app.py
CHANGED
@@ -6,4 +6,37 @@ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-is-en")
|
|
6 |
sentiment_classifier = pipeline("text-classification", model="Birkir/electra-base-igc-is-sentiment-analysis")
|
7 |
formality_classifier = pipeline("text-classification", model="svanhvit/formality-classification-icebert")
|
8 |
detoxify_pipeline = pipeline('text-classification', model='unitary/toxic-bert', tokenizer='bert-base-uncased', function_to_apply='sigmoid', return_all_scores=True)
|
9 |
-
politeness_classifier = pipeline("text-classification", model="Genius1237/xlm-roberta-large-tydip")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
sentiment_classifier = pipeline("text-classification", model="Birkir/electra-base-igc-is-sentiment-analysis")
|
7 |
formality_classifier = pipeline("text-classification", model="svanhvit/formality-classification-icebert")
|
8 |
detoxify_pipeline = pipeline('text-classification', model='unitary/toxic-bert', tokenizer='bert-base-uncased', function_to_apply='sigmoid', return_all_scores=True)
|
9 |
+
politeness_classifier = pipeline("text-classification", model="Genius1237/xlm-roberta-large-tydip")
|
10 |
+
|
11 |
+
def analyze_icelandic_text(icelandic_text):
|
12 |
+
analysis_result = analyze_text(icelandic_text)
|
13 |
+
|
14 |
+
sentiment_label = "Positive" if analysis_result["sentiment"]["label"] == "LABEL_1" else "Negative"
|
15 |
+
formality_label = "Formal" if analysis_result["formality"]["label"] == "formal" else "Informal"
|
16 |
+
toxic_label = "Toxic" if analysis_result["toxicity"]["score"] > 0.5 else "Not Toxic"
|
17 |
+
politeness_label = "Polite" if analysis_result["politeness"]["label"] == "polite" else "Impolite"
|
18 |
+
|
19 |
+
return {
|
20 |
+
"Translated Text": analysis_result["translated_text"],
|
21 |
+
"Sentiment": f"{sentiment_label} (Score: {round(analysis_result['sentiment']['score'], 2)})",
|
22 |
+
"Formality": f"{formality_label} (Score: {round(analysis_result['formality']['score'], 2)})",
|
23 |
+
"Toxicity": f"{toxic_label} (Score: {round(analysis_result['toxicity']['score'], 2)})",
|
24 |
+
"Politeness": f"{politeness_label} (Score: {round(analysis_result['politeness']['score'], 2)})"
|
25 |
+
}
|
26 |
+
|
27 |
+
iface = gr.Interface(
|
28 |
+
fn=analyze_icelandic_text,
|
29 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter an Icelandic sentence here..."),
|
30 |
+
outputs=[
|
31 |
+
gr.outputs.Textbox(label="Translated Text"),
|
32 |
+
gr.outputs.Textbox(label="Sentiment"),
|
33 |
+
gr.outputs.Textbox(label="Formality"),
|
34 |
+
gr.outputs.Textbox(label="Toxicity"),
|
35 |
+
gr.outputs.Textbox(label="Politeness"),
|
36 |
+
],
|
37 |
+
title="Icelandic Text Analysis",
|
38 |
+
description="This app translates Icelandic text to English and analyzes its sentiment, formality, toxicity, and politeness."
|
39 |
+
)
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
iface.launch()
|