|
|
import gradio as gr |
|
|
from transformers import AutoModelForSequenceClassification, AutoTokenizer |
|
|
import torch |
|
|
|
|
|
|
|
|
model_name = "mmuzamilai/distilbert-review-bug-classifier" |
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
|
model = AutoModelForSequenceClassification.from_pretrained(model_name) |
|
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
|
|
model.to(device) |
|
|
|
|
|
|
|
|
label_map = { |
|
|
0: "Graphical Issue", |
|
|
1: "Network Issue", |
|
|
2: "No Bug β
", |
|
|
3: "Performance Issue" |
|
|
} |
|
|
|
|
|
|
|
|
def classify_review(text): |
|
|
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128).to(device) |
|
|
with torch.no_grad(): |
|
|
outputs = model(**inputs) |
|
|
predicted_label_id = torch.argmax(outputs.logits).item() |
|
|
return label_map.get(predicted_label_id, "Unknown") |
|
|
|
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=classify_review, |
|
|
inputs=gr.Textbox(lines=2, placeholder="Enter your review..."), |
|
|
outputs=gr.Label(label="Predicted Category"), |
|
|
title="Review Bug Classifier" |
|
|
) |
|
|
|
|
|
iface.launch() |
|
|
|