Gilvan commited on
Commit
1ecbc96
·
verified ·
1 Parent(s): b316cf0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import pipeline
3
+ import gradio as gr
4
+
5
+ # Carregar o modelo
6
+ model_id = "meta-llama/Llama-3.2-1B-Instruct"
7
+
8
+ pipe = pipeline(
9
+ "text-classification",
10
+ model=model_id,
11
+ torch_dtype=torch.bfloat16,
12
+ device_map="auto"
13
+ )
14
+
15
+ # Definir os rótulos das classes
16
+ pipe.model.config.id2label = {0: 'greeting', 1: 'farewell', 2: 'other'}
17
+
18
+ # Função para usar o modelo e retornar o resultado
19
+ def classify_text(text):
20
+ result = pipe(text)
21
+ return result[0]['label']
22
+
23
+ # Interface Gradio
24
+ iface = gr.Interface(
25
+ fn=classify_text, # Função que será chamada
26
+ inputs=gr.Textbox(label="Texto"), # Caixa de texto para o usuário inserir a entrada
27
+ outputs=gr.Label(label="Classificação"), # Exibição da classificação
28
+ title="Classificador de Texto", # Título do app
29
+ description="Este modelo classifica o texto em três categorias: 'greeting', 'farewell', e 'other'."
30
+ )
31
+
32
+ # Iniciar o app Gradio
33
+ iface.launch()