Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,17 +72,23 @@ def replace_encoding(tokens):
|
|
| 72 |
.replace('Ãļ', 'ý')
|
| 73 |
for token in tokens[1:-1]]
|
| 74 |
|
| 75 |
-
def predict(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
greeting_pattern = r"^(Halló|Hæ|Sæl|Góðan dag|Kær kveðja|Daginn|Kvöldið|Ágætis|Elsku)"
|
| 77 |
|
| 78 |
-
prediction_output, keywords, influential_keywords = get_prediction(text)
|
| 79 |
greeting_feedback = ""
|
| 80 |
|
| 81 |
-
modified_input =
|
| 82 |
for keyword, _ in keywords:
|
| 83 |
modified_input = modified_input.replace(keyword, f"<span style='color:green;'>{keyword}</span>")
|
| 84 |
|
| 85 |
-
if not re.match(greeting_pattern,
|
| 86 |
greeting_feedback = "OTHER FEEDBACK:<br>Heilsaðu dóninn þinn<br>"
|
| 87 |
|
| 88 |
response = f"INPUT:<br>{modified_input}<br><br>MY PREDICTION:<br>{prediction_output}<br>{influential_keywords}<br>{greeting_feedback}"
|
|
|
|
| 72 |
.replace('Ãļ', 'ý')
|
| 73 |
for token in tokens[1:-1]]
|
| 74 |
|
| 75 |
+
def predict(user_input_text):
|
| 76 |
+
explanations_formality = bench.explain(user_input_text, target=0)
|
| 77 |
+
explanations_sentiment = bench.explain(user_input_text, target=1)
|
| 78 |
+
explanations_politeness = bench.explain(user_input_text, target=2)
|
| 79 |
+
explanations_toxicity = bench.explain(user_input_text, target=3)
|
| 80 |
+
|
| 81 |
+
prediction_output, keywords, influential_keywords = get_prediction(user_input_text)
|
| 82 |
+
|
| 83 |
greeting_pattern = r"^(Halló|Hæ|Sæl|Góðan dag|Kær kveðja|Daginn|Kvöldið|Ágætis|Elsku)"
|
| 84 |
|
|
|
|
| 85 |
greeting_feedback = ""
|
| 86 |
|
| 87 |
+
modified_input = user_input_text
|
| 88 |
for keyword, _ in keywords:
|
| 89 |
modified_input = modified_input.replace(keyword, f"<span style='color:green;'>{keyword}</span>")
|
| 90 |
|
| 91 |
+
if not re.match(greeting_pattern, user_input_text, re.IGNORECASE):
|
| 92 |
greeting_feedback = "OTHER FEEDBACK:<br>Heilsaðu dóninn þinn<br>"
|
| 93 |
|
| 94 |
response = f"INPUT:<br>{modified_input}<br><br>MY PREDICTION:<br>{prediction_output}<br>{influential_keywords}<br>{greeting_feedback}"
|