Spaces:
Runtime error
Runtime error
File size: 1,218 Bytes
4d16358 55b6ce3 de53c31 4d16358 55b6ce3 4d16358 55b6ce3 4d16358 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import gradio as gr
from transformers import AutoTokenizer, PreTrainedTokenizer, AutoConfig
import torch
from custom_model import CustomModel
# Load the model and tokenizer
model_name = "deepseek-ai/DeepSeek-V3"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
model = CustomModel.from_pretrained(model_name, config=config, trust_remote_code=True)
def classify_text(text):
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
probabilities = torch.softmax(logits, dim=-1).tolist()[0]
predicted_class = torch.argmax(logits, dim=-1).item()
return {
"Predicted Class": predicted_class,
"Probabilities": probabilities
}
# Create a Gradio interface
iface = gr.Interface(
fn=classify_text,
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
outputs=[
gr.outputs.Label(label="Predicted Class"),
gr.outputs.Label(label="Probabilities")
],
title="DeepSeek-V3 Text Classification",
description="Classify text using the DeepSeek-V3 model."
)
# Launch the interface
iface.launch() |