File size: 912 Bytes
0e91449
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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()