Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
|
@@ -15,4 +16,38 @@ iface = gr.Interface(fn=get_sentiment,
|
|
| 15 |
description='Obtenha o sentimento do texto de entrada:'
|
| 16 |
)
|
| 17 |
|
| 18 |
-
iface.launch(inline=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
from transformers import pipeline
|
| 3 |
import gradio as gr
|
| 4 |
import torch
|
|
|
|
| 16 |
description='Obtenha o sentimento do texto de entrada:'
|
| 17 |
)
|
| 18 |
|
| 19 |
+
iface.launch(inline=False)"""
|
| 20 |
+
|
| 21 |
+
from transformers import pipeline
|
| 22 |
+
import gradio as gr
|
| 23 |
+
import torch
|
| 24 |
+
|
| 25 |
+
model = "neuralmind/bert-base-portuguese-cased"
|
| 26 |
+
pipe = pipeline('sentiment-analysis', model=model)
|
| 27 |
+
|
| 28 |
+
def get_sentiment(input_text):
|
| 29 |
+
return pipe(input_text)
|
| 30 |
+
|
| 31 |
+
results = pipe(input_text)
|
| 32 |
+
|
| 33 |
+
# Extract the label and score
|
| 34 |
+
label = results[0]['label']
|
| 35 |
+
score = results[0]['score']
|
| 36 |
+
|
| 37 |
+
threshold = 0.5
|
| 38 |
+
|
| 39 |
+
if label == 'LABEL_1' and score > sentiment_threshold: # Positive sentiment
|
| 40 |
+
return 'POSITIVO'
|
| 41 |
+
else label == 'LABEL_0' and score <= sentiment_threshold: # Negative sentiment
|
| 42 |
+
return 'NEGATIVO'
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
iface = gr.Interface(fn=get_sentiment,
|
| 47 |
+
inputs='text',
|
| 48 |
+
outputs='text',
|
| 49 |
+
title='Sentiment Analysis',
|
| 50 |
+
description='Obtenha o sentimento do texto de entrada:'
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
iface.launch(inline=False)
|