File size: 1,376 Bytes
e5b3a4d
020b4ec
 
f74d5e4
020b4ec
81acc02
020b4ec
 
 
 
 
 
 
 
 
 
1d68db4
 
e5b3a4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
from transformers import pipeline
import gradio as gr
import torch

model = "neuralmind/bert-base-portuguese-cased"
pipe = pipeline('sentiment-analysis', model=model)

def get_sentiment(input_text):
  return pipe(input_text)

iface = gr.Interface(fn=get_sentiment,
                     inputs='text',
                     outputs=['text'],
                     title='Sentiment Analysis',
                     description='Obtenha o sentimento do texto de entrada:'
                    )

iface.launch(inline=False)"""

from transformers import pipeline
import gradio as gr
import torch

model = "neuralmind/bert-base-portuguese-cased"
pipe = pipeline('sentiment-analysis', model=model)

def get_sentiment(input_text):
  return pipe(input_text)

results = pipe(input_text)

# Extract the label and score
label = results[0]['label']
score = results[0]['score']

threshold = 0.5

if label == 'LABEL_1' and score > sentiment_threshold:  # Positive sentiment
    return 'POSITIVO'
  else label == 'LABEL_0' and score <= sentiment_threshold:  # Negative sentiment
    return 'NEGATIVO'



iface = gr.Interface(fn=get_sentiment,
                     inputs='text',
                     outputs='text',
                     title='Sentiment Analysis',
                     description='Obtenha o sentimento do texto de entrada:'
                    )

iface.launch(inline=False)