deepseek / app.py
cheberle's picture
f
b0e6d60
raw
history blame
923 Bytes
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification
# Load the model and tokenizer
model_name = "deepseek-ai/DeepSeek-R1"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
def classify_text(input_text):
# Tokenize the input
inputs = tokenizer(input_text, return_tensors="pt")
# Get predictions
outputs = model(**inputs)
probabilities = outputs.logits.softmax(dim=-1).detach().numpy()
return {f"Class {i}": prob for i, prob in enumerate(probabilities[0])}
# Create the Gradio interface
interface = gr.Interface(
fn=classify_text,
inputs=gr.Textbox(label="Enter Text"),
outputs=gr.Label(label="Class Probabilities"),
title="DeepSeek-R1 Text Classification",
description="A text classification app powered by DeepSeek-R1."
)
# Launch the app
interface.launch()