sentimentos / app.py
MariaEduarda3's picture
Create app.py
d6da381 verified
raw
history blame contribute delete
912 Bytes
# app.py
# App de Análise de Sentimentos super simples para iniciantes
import gradio as gr
from transformers import pipeline
# Carrega um modelo pronto de sentimentos (inglês)
clf = pipeline("sentiment-analysis") # baixa o modelo automaticamente no Space
def analisar(texto):
if not texto.strip():
return "Digite um texto para analisar."
result = clf(texto)[0]
# Ex.: {'label': 'POSITIVE', 'score': 0.998}
label = "Positivo" if "POS" in result["label"].upper() else "Negativo"
conf = f"Confiança: {result['score']:.2f}"
return f"{label} | {conf}"
demo = gr.Interface(
fn=analisar,
inputs=gr.Textbox(label="Digite um texto em inglês"),
outputs=gr.Textbox(label="Resultado"),
title="Classificador de Sentimentos (demo)",
description="Exemplo didático no Hugging Face Spaces usando Gradio + Transformers."
)
if __name__ == "__main__":
demo.launch()