ProfRod100 commited on
Commit
2271165
·
verified ·
1 Parent(s): 4b5208d

Create APP.PY

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ # App de Análise de Sentimentos super simples para iniciantes
3
+
4
+ import gradio as gr
5
+ from transformers import pipeline
6
+
7
+ # Carrega um modelo pronto de sentimentos (inglês)
8
+ clf = pipeline("sentiment-analysis") # baixa o modelo automaticamente no Space
9
+
10
+ def analisar(texto):
11
+ if not texto.strip():
12
+ return "Digite um texto para analisar."
13
+ result = clf(texto)[0]
14
+ # Ex.: {'label': 'POSITIVE', 'score': 0.998}
15
+ label = "Positivo" if "POS" in result["label"].upper() else "Negativo"
16
+ conf = f"Confiança: {result['score']:.2f}"
17
+ return f"{label} | {conf}"
18
+
19
+ demo = gr.Interface(
20
+ fn=analisar,
21
+ inputs=gr.Textbox(label="Digite um texto em inglês"),
22
+ outputs=gr.Textbox(label="Resultado"),
23
+ title="Classificador de Sentimentos (demo)",
24
+ description="Exemplo didático no Hugging Face Spaces usando Gradio + Transformers."
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ demo.launch()