Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,42 @@
|
|
1 |
-
import
|
2 |
-
import torch
|
3 |
-
from transformers import XLNetTokenizer, XLNetForSequenceClassification
|
4 |
import gradio as gr
|
5 |
|
6 |
-
#
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
response = requests.get(url)
|
12 |
-
with open('XLNet_model_project_Core.pt', 'wb') as f:
|
13 |
-
f.write(response.content)
|
14 |
|
15 |
-
#
|
16 |
-
|
|
|
|
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
model.eval()
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
-
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=100)
|
27 |
-
with torch.no_grad():
|
28 |
-
outputs = model(**inputs)
|
29 |
-
logits = outputs.logits
|
30 |
-
probabilities = torch.softmax(logits, dim=1)
|
31 |
-
predicted_class = torch.argmax(probabilities).item()
|
32 |
-
return "Severe" if predicted_class == 1 else "Non-severe"
|
33 |
|
34 |
-
#
|
35 |
iface = gr.Interface(
|
36 |
-
fn=
|
37 |
-
inputs=gr.Textbox(lines=2,
|
38 |
-
outputs=
|
39 |
-
|
|
|
|
|
|
|
40 |
description="Enter text and predict its severity (Severe or Non-severe).",
|
41 |
-
theme="huggingface",
|
42 |
examples=[
|
43 |
["Can't open multiple bookmarks at once from the bookmarks sidebar using the context menu"],
|
44 |
["Minor enhancements to make-source-package.sh"]
|
45 |
-
]
|
46 |
-
allow_flagging=False
|
47 |
)
|
48 |
|
|
|
49 |
iface.launch()
|
|
|
1 |
+
from transformers import pipeline
|
|
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Load the model using the pipeline
|
5 |
+
pipe = pipeline("text-classification", model="AliArshad/Severity_Predictor")
|
6 |
+
from transformers import pipeline
|
7 |
+
import gradio as gr
|
8 |
|
9 |
+
# Load the model using the pipeline
|
10 |
+
pipe = pipeline("text-classification", model="AliArshad/Severity_Predictor")
|
|
|
|
|
|
|
11 |
|
12 |
+
# Function to predict severity and return confidence score
|
13 |
+
def predict_severity(text):
|
14 |
+
# Get prediction from the pipeline
|
15 |
+
prediction = pipe(text)
|
16 |
|
17 |
+
# Interpret the label and get the confidence score
|
18 |
+
label = prediction[0]['label']
|
19 |
+
confidence = prediction[0]['score']
|
20 |
+
severity = "Severe" if label == "LABEL_1" else "Non-Severe"
|
|
|
21 |
|
22 |
+
# Return severity and confidence as separate outputs
|
23 |
+
return severity, confidence
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
# Define the Gradio interface with a title, specific placeholder message, and a progress bar for confidence
|
26 |
iface = gr.Interface(
|
27 |
+
fn=predict_severity,
|
28 |
+
inputs=gr.Textbox(lines=2, placeholder="Please Enter Bug Report Summary"),
|
29 |
+
outputs=[
|
30 |
+
gr.Textbox(label="Prediction"),
|
31 |
+
gr.Number(label="Confidence", precision=2)
|
32 |
+
],
|
33 |
+
title="SevPredict: GPT-2 Based Severity Prediction",
|
34 |
description="Enter text and predict its severity (Severe or Non-severe).",
|
|
|
35 |
examples=[
|
36 |
["Can't open multiple bookmarks at once from the bookmarks sidebar using the context menu"],
|
37 |
["Minor enhancements to make-source-package.sh"]
|
38 |
+
]
|
|
|
39 |
)
|
40 |
|
41 |
+
# Launch the interface
|
42 |
iface.launch()
|