File size: 1,143 Bytes
d80cee7
 
 
 
 
 
 
 
 
 
 
4afc6b6
675ccd3
5bc7d3a
 
 
 
675ccd3
 
d80cee7
 
 
 
 
a7a0c7a
4afc6b6
d80cee7
 
 
 
 
 
 
 
 
 
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
37
import gradio as gr
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch

# Load model and tokenizer
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)

# Custom label mapping using integer keys
label_map = {
    0: "Graphical Issue",
    1: "Network Issue",
    2: "No Bug ✅",
    3: "Performance Issue"
}

# Classification function
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")

# Gradio interface
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()