|
import gradio as gr |
|
import torch |
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("willco-afk/my-model-name") |
|
model = AutoModelForSequenceClassification.from_pretrained("willco-afk/my-model-name") |
|
|
|
|
|
def classify_text(text): |
|
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True) |
|
with torch.no_grad(): |
|
logits = model(**inputs).logits |
|
predicted_class = logits.argmax().item() |
|
return f"Predicted class: {predicted_class}" |
|
|
|
|
|
demo = gr.Interface(fn=classify_text, |
|
inputs=gr.Textbox(label="Enter your text"), |
|
outputs=gr.Textbox(label="Prediction"), |
|
live=True) |
|
|
|
|
|
demo.launch() |