Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,21 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
6 |
|
7 |
-
def analyze_sentiment(text):
|
8 |
-
results = classifier(text, ["positive", "negative", "neutral"], multi_label=True)
|
9 |
-
mx = max(results['scores'])
|
10 |
-
ind = results['scores'].index(mx)
|
11 |
-
result = results['labels'][ind]
|
12 |
-
|
13 |
-
# Traducción de etiquetas al español
|
14 |
-
if result == "positive":
|
15 |
-
sentiment = "Positivo"
|
16 |
-
elif result == "negative":
|
17 |
-
sentiment = "Negativo"
|
18 |
-
else:
|
19 |
-
sentiment = "Neutro"
|
20 |
-
|
21 |
-
return sentiment
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
demo.launch(share=True)
|
|
|
1 |
import gradio as gr
|
2 |
+
import pickle
|
3 |
from transformers import pipeline
|
4 |
|
5 |
+
def load_model(selected_model):
|
6 |
+
with open(selected_model, 'rb') as file:
|
7 |
+
loaded_model = pickle.load(file)
|
8 |
+
return loaded_model
|
9 |
+
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
classifier = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli")
|
13 |
+
def analyze_sentiment(text):
|
14 |
+
results = classifier(text,["positive","negative",'neutral'],multi_label=True)
|
15 |
+
mx = max(results['scores'])
|
16 |
+
ind = results['scores'].index(mx)
|
17 |
+
result = results['labels'][ind]
|
18 |
+
return result
|
19 |
|
20 |
+
demo = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text", title="Sentiment Analysis")
|
21 |
demo.launch(share=True)
|