|
import torch |
|
from transformers import pipeline |
|
import gradio as gr |
|
|
|
|
|
model_id = "meta-llama/Llama-3.2-1B-Instruct" |
|
|
|
pipe = pipeline( |
|
"text-classification", |
|
model=model_id, |
|
torch_dtype=torch.bfloat16, |
|
device_map="auto" |
|
) |
|
|
|
|
|
pipe.model.config.id2label = {0: 'greeting', 1: 'farewell', 2: 'other'} |
|
|
|
|
|
def classify_text(text): |
|
result = pipe(text) |
|
return result[0]['label'] |
|
|
|
|
|
iface = gr.Interface( |
|
fn=classify_text, |
|
inputs=gr.Textbox(label="Texto"), |
|
outputs=gr.Label(label="Classificação"), |
|
title="Classificador de Texto", |
|
description="Este modelo classifica o texto em três categorias: 'greeting', 'farewell', e 'other'." |
|
) |
|
|
|
|
|
iface.launch() |