|
|
import gradio as gr
|
|
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
|
import torch
|
|
|
|
|
|
|
|
|
model_path = "yazied49/disabilityy_model_final"
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
|
|
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
|
|
|
|
|
|
|
|
def predict(text):
|
|
|
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
|
|
with torch.no_grad():
|
|
|
outputs = model(**inputs)
|
|
|
probs = torch.nn.functional.softmax(outputs.logits, dim=1)
|
|
|
pred_id = torch.argmax(probs, dim=1).item()
|
|
|
confidence = torch.max(probs).item()
|
|
|
label = model.config.id2label[str(pred_id)]
|
|
|
|
|
|
return f"{label} ({round(confidence * 100, 2)}%)"
|
|
|
|
|
|
|
|
|
demo = gr.Interface(fn=predict, inputs="text", outputs="text", title="Disability Classifier")
|
|
|
|
|
|
|
|
|
demo.launch()
|
|
|
|