Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
MODEL_PATH = "lucsaa/classificador-de-emails"
|
| 5 |
+
|
| 6 |
+
classifier = pipeline("text-classification", model=MODEL_PATH)
|
| 7 |
+
|
| 8 |
+
def classificar_email(texto):
|
| 9 |
+
"""
|
| 10 |
+
Recebe um texto de e-mail e retorna a categoria: Produtivo ou Improdutivo.
|
| 11 |
+
Limita o texto a 512 tokens para evitar estouro de memória.
|
| 12 |
+
"""
|
| 13 |
+
if not texto.strip():
|
| 14 |
+
return "Texto vazio"
|
| 15 |
+
resultado = classifier(texto[:512])[0]
|
| 16 |
+
return resultado["label"].capitalize()
|
| 17 |
+
|
| 18 |
+
interface = gr.Interface(
|
| 19 |
+
fn=classificar_email,
|
| 20 |
+
inputs=gr.Textbox(lines=10, placeholder="Cole o texto do e-mail aqui..."),
|
| 21 |
+
outputs=gr.Textbox(label="Categoria"),
|
| 22 |
+
title="FocusMail - Classificador de E-mails",
|
| 23 |
+
description="Classifique seus e-mails como Produtivo ou Improdutivo usando um modelo treinado.",
|
| 24 |
+
allow_flagging="never"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
interface.launch(share=True)
|