nlmaldonadog commited on
Commit
8aa9405
·
verified ·
1 Parent(s): 74c1a15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -1,17 +1,17 @@
1
- from huggingface_hub import from_pretrained_fastai
2
  import gradio as gr
3
- from fastai.text.all import *
4
 
5
- # Cargar el primer modelo
6
- repo_id1 = "nlmaldonadog/AWD_LSTM_P7"
7
- learner1 = from_pretrained_fastai(repo_id1)
8
- labels1 = learner1.dls.vocab
9
 
10
- def predict1(text):
11
- pred, pred_idx, probs = learner1.predict(text)
12
- return {labels1[i]: float(probs[i]) for i in range(len(labels1))}
 
 
 
 
 
 
13
 
14
- texto = gr.inputs.Textbox(lines=2, placeholder='Escribe aquí...')
15
-
16
- # Creamos la interfaz y la lanzamos.
17
- gr.Interface(fn=predict1, inputs=texto, outputs=gr.outputs.Label()).launch(share=False)
 
 
1
  import gradio as gr
 
2
 
3
+ from transformers import pipeline
4
+ classifier = pipeline('text-classification', model='nlmaldonadog/clasificador-rotten-tomatoes-xlnet-base-cased')
 
 
5
 
6
+ def predict(text):
7
+ prediction = classifier(text)
8
+ score = int(round(prediction[0]['score'] * 100))
9
+
10
+ if prediction[0]['label'] == "LABEL_0":
11
+ output = f"Negative sentiment with a confidence level of {score}%."
12
+ else:
13
+ output = f"Positive sentiment with a confidence level of {score}%."
14
+ return output
15
 
16
+ iface = gr.Interface(fn=predict, inputs=[gr.Textbox(placeholder='Escribe aquí...')], outputs="text")
17
+ iface.launch(share=True)