the_team / app.py
MennatullahHany's picture
Create app.py
227ee20 verified
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "MennatullahHany/Tunned_Bert"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
def classify(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True)
with torch.no_grad():
outputs = model(**inputs)
probs = torch.softmax(outputs.logits, dim=1)
confidence, predicted = torch.max(probs, dim=1)
label = model.config.id2label[predicted.item()]
confidence = float(confidence.item())
return {label: confidence}
iface = gr.Interface(
fn=classify,
inputs=gr.Textbox(lines=5, placeholder="Enter text here..."),
outputs=gr.Label(),
title="BERT Safety Classifier",
description="Enter text to classify as SAFE or DANGER."
)
iface.launch()