File size: 1,378 Bytes
c692bf5
545a4be
c692bf5
 
545a4be
281cbf1
d03d02b
 
1591131
c692bf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44fecf0
c692bf5
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
38
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import gradio as gr

# Path to the saved model in Hugging Face Spaces
model_name = 'AliArshad/SeverityPredictor'  # Replace with your actual username and model name
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)


# Function for prediction
def xl_net_predict(text):
    inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=100)
    with torch.no_grad():
        outputs = model(**inputs)
    logits = outputs.logits
    probabilities = torch.softmax(logits, dim=1)
    predicted_class = torch.argmax(probabilities).item()
    return "Severe" if predicted_class == 1 else "Non-severe"

# Customizing the interface
iface = gr.Interface(
    fn=xl_net_predict,
    inputs=gr.Textbox(lines=2, label="Summary", placeholder="Enter text here..."),
    outputs=gr.Textbox(label="Predicted Severity"),
    title="XLNet Based Bug Report Severity Prediction",
    description="Enter text and predict its severity (Severe or Non-severe).",
    theme="huggingface",
    examples=[
        ["Can't open multiple bookmarks at once from the bookmarks sidebar using the context menu"],
        ["Minor enhancements to make-source-package.sh"]
    ],
    allow_flagging=False
)


iface.launch()