tclopess's picture
Update app.py
e5b3a4d verified
raw
history blame
1.38 kB
"""
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)