File size: 1,812 Bytes
687d513
5f847ad
 
fc5186e
 
5f847ad
 
fc5186e
5f847ad
 
 
 
 
687d513
5f847ad
 
fc5186e
5f847ad
 
 
 
 
fc5186e
5f847ad
 
 
 
 
 
 
 
 
fc5186e
5f847ad
 
 
 
 
47d0b49
5f847ad
 
 
 
 
 
 
 
fc5186e
5f847ad
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
39
40
41
42
43
44
45
46
47
48
49
50
import requests
import torch
from transformers import XLNetTokenizer, XLNetForSequenceClassification
import gradio as gr

# URL of the saved model on GitHub
model_url = 'https://github.com/AliArshadswl/severity_prediction/raw/main/XLNet_model_project_Core.pt'

# Function to download the model from URL and load it
def download_model(url):
    response = requests.get(url)
    with open('XLNet_model_project_Core.pt', 'wb') as f:
        f.write(response.content)

# Download the model
download_model(model_url)

# Load the saved model
tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased')
model = XLNetForSequenceClassification.from_pretrained('xlnet-base-cased', num_labels=2)
model.load_state_dict(torch.load('XLNet_model_project_Core.pt', map_location=torch.device('cpu')))
model.eval()

# 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="SevPrecit - A GPT-2 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()