sergiosampayob commited on
Commit
f08f4c2
·
1 Parent(s): 8764c8c

Sentiment analysis demo

Browse files
Files changed (2) hide show
  1. app.py +25 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import pipeline
4
+
5
+
6
+ pipe = pipeline("text-classification", # tarea a realizar
7
+ model="distilbert/distilbert-base-uncased-finetuned-sst-2-english", # modelo a utilizar
8
+ torch_dtype=torch.bfloat16,) #
9
+
10
+
11
+ def text_classification(text):
12
+ result = pipe(text)
13
+ return result[0]['label']
14
+
15
+
16
+ examples = ['You are the evil!', 'Doing great boy!']
17
+
18
+ demo = gr.Interface(fn=text_classification,
19
+ inputs= gr.Textbox(lines=2, label="Text", placeholder="Enter text here..."),
20
+ outputs=gr.Textbox(lines=2, label="Text Classification Result"),
21
+ description="Enter a text and see the sentiment classification result!",
22
+ examples=examples,
23
+ title="Sentiment Classification")
24
+
25
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio