ReiderMx commited on
Commit
198f981
1 Parent(s): 9d9b764

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -25
app.py CHANGED
@@ -1,32 +1,21 @@
1
  import gradio as gr
 
2
  from transformers import pipeline
3
 
4
- # Configuración del clasificador de sentimientos
5
- classifier = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli")
 
 
 
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
- # Configuración de la interfaz de Gradio
24
- demo = gr.Interface(
25
- fn=analyze_sentiment,
26
- inputs="Escribe tu comentario",
27
- outputs="Sentimiento",
28
- title="Análisis de Sentimientos"
29
- )
30
 
31
- # Lanzamiento de la interfaz
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)