Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,25 @@ import pandas as pd
|
|
10 |
model_name = "MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7"
|
11 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def clasificador(input1, input2):
|
14 |
classifier = pipeline("zero-shot-classification", model="MoritzLaurer/mDeBERTa-v3-base-mnli-xnli",tokenizer=tokenizer)
|
15 |
sequence_to_classify = input1
|
@@ -18,8 +37,7 @@ def clasificador(input1, input2):
|
|
18 |
output0 = classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
19 |
output1=pd.DataFrame(output0)
|
20 |
output1=output1.iloc[:,1:3]
|
21 |
-
|
22 |
-
output2=analyzer.predict(input1)
|
23 |
return output1, output2
|
24 |
|
25 |
|
|
|
10 |
model_name = "MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7"
|
11 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
12 |
|
13 |
+
|
14 |
+
def classify_text(text):
|
15 |
+
"""
|
16 |
+
Clasifica un texto como positivo, negativo o neutro utilizando un clasificador.
|
17 |
+
Args:
|
18 |
+
text (str): El texto a clasificar.
|
19 |
+
Returns:
|
20 |
+
str: La clasificación del texto, que puede ser "Positivo", "Negativo" o "Neutro".
|
21 |
+
"""
|
22 |
+
analyzer = create_analyzer(task="sentiment", lang="es")
|
23 |
+
result = analyzer.predict(text)[0]['label']
|
24 |
+
#result = classifier(text)[0]['label']
|
25 |
+
if result == "POS":
|
26 |
+
return "Positivo"
|
27 |
+
elif result == "NEG":
|
28 |
+
return "Negativo"
|
29 |
+
else:
|
30 |
+
return "Neutro"
|
31 |
+
|
32 |
def clasificador(input1, input2):
|
33 |
classifier = pipeline("zero-shot-classification", model="MoritzLaurer/mDeBERTa-v3-base-mnli-xnli",tokenizer=tokenizer)
|
34 |
sequence_to_classify = input1
|
|
|
37 |
output0 = classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
38 |
output1=pd.DataFrame(output0)
|
39 |
output1=output1.iloc[:,1:3]
|
40 |
+
output2=classify_text(input1)
|
|
|
41 |
return output1, output2
|
42 |
|
43 |
|