|
import gradio as gr |
|
from transformers import AutoTokenizer |
|
from transformers.utils import logging |
|
|
|
|
|
logging.set_verbosity_info() |
|
|
|
|
|
from transformers_modules.deepseek_ai.DeepSeek_R1.configuration_deepseek import DeepseekV3Config |
|
from transformers_modules.deepseek_ai.DeepSeek_R1.modeling_deepseek import DeepseekV3Model |
|
|
|
|
|
model_name = "deepseek-ai/DeepSeek-R1" |
|
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True) |
|
config = DeepseekV3Config.from_pretrained(model_name, trust_remote_code=True) |
|
model = DeepseekV3Model.from_pretrained(model_name, config=config, trust_remote_code=True) |
|
|
|
def classify_text(input_text): |
|
|
|
inputs = tokenizer(input_text, return_tensors="pt") |
|
|
|
outputs = model(**inputs) |
|
probabilities = outputs.logits.softmax(dim=-1).detach().numpy() |
|
return {f"Class {i}": prob for i, prob in enumerate(probabilities[0])} |
|
|
|
|
|
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." |
|
) |
|
|
|
|
|
interface.launch() |