Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import XLNetTokenizer, XLNetForSequenceClassification
|
3 |
+
import gradio as gr
|
4 |
+
from pydrive.auth import GoogleAuth
|
5 |
+
from pydrive.drive import GoogleDrive
|
6 |
+
|
7 |
+
# Authenticate and create GoogleDrive instance
|
8 |
+
gauth = GoogleAuth()
|
9 |
+
gauth.LocalWebserverAuth()
|
10 |
+
drive = GoogleDrive(gauth)
|
11 |
+
|
12 |
+
# ID of the file in Google Drive
|
13 |
+
file_id = '1-7O5gAFgcIzgJ68WkSSpmh1H6kJL6fAO' # Replace this with your file's ID from Google Drive
|
14 |
+
destination_path = '/content/XLNet_model_project_Core.pt' # Path to save the downloaded model file
|
15 |
+
|
16 |
+
# Download the model file from Google Drive
|
17 |
+
downloaded_file = drive.CreateFile({'id': file_id})
|
18 |
+
downloaded_file.GetContentFile(destination_path)
|
19 |
+
|
20 |
+
# Load the saved model
|
21 |
+
tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased')
|
22 |
+
model = XLNetForSequenceClassification.from_pretrained('xlnet-base-cased', num_labels=2)
|
23 |
+
model.load_state_dict(torch.load(destination_path))
|
24 |
+
model.eval()
|
25 |
+
|
26 |
+
# Function for prediction
|
27 |
+
def xl_net_predict(text):
|
28 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=100)
|
29 |
+
with torch.no_grad():
|
30 |
+
outputs = model(**inputs)
|
31 |
+
logits = outputs.logits
|
32 |
+
probabilities = torch.softmax(logits, dim=1)
|
33 |
+
predicted_class = torch.argmax(probabilities).item()
|
34 |
+
return "Severe" if predicted_class == 1 else "Non-severe"
|
35 |
+
|
36 |
+
# Customizing the interface
|
37 |
+
iface = gr.Interface(
|
38 |
+
fn=xl_net_predict,
|
39 |
+
inputs=gr.Textbox(lines=2, label="Summary", placeholder="Enter text here..."),
|
40 |
+
outputs=gr.Textbox(label="Predicted Severity"),
|
41 |
+
title="XLNet Based Bug Report Severity Prediction",
|
42 |
+
description="Enter text and predict its severity (Severe or Non-severe).",
|
43 |
+
theme="huggingface",
|
44 |
+
examples=[
|
45 |
+
["Can't open multiple bookmarks at once from the bookmarks sidebar using the context menu"],
|
46 |
+
["Minor enhancements to make-source-package.sh"]
|
47 |
+
],
|
48 |
+
allow_flagging=False
|
49 |
+
)
|
50 |
+
|
51 |
+
iface.launch()
|