|
import gradio as gr |
|
from transformers import AutoTokenizer, AutoConfig, AutoModelForSequenceClassification |
|
|
|
|
|
model_name = "cheberle/autotrain-35swc-b4r9z" |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
|
|
|
|
config = AutoConfig.from_pretrained(model_name) |
|
model = AutoModelForSequenceClassification.from_pretrained(model_name, config=config) |
|
|
|
|
|
def classify_text(input_text): |
|
inputs = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True) |
|
outputs = model(**inputs) |
|
probabilities = outputs.logits.softmax(dim=-1).tolist()[0] |
|
labels = {i: f"Label {i}" for i in range(len(probabilities))} |
|
result = {labels[i]: prob for i, prob in enumerate(probabilities)} |
|
return result |
|
|
|
|
|
interface = gr.Interface( |
|
fn=classify_text, |
|
inputs="text", |
|
outputs="label", |
|
title="DeepSeek-R1 Text Classification", |
|
description="Classify text inputs using the DeepSeek-R1 model." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch() |