AliArshad commited on
Commit
42f4865
1 Parent(s): 687d513

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -29
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import torch
2
  import requests
3
- from transformers import XLNetTokenizer, XLNetForSequenceClassification
4
  import gradio as gr
5
 
6
  # Link to the saved model on Hugging Face Spaces
@@ -12,35 +12,37 @@ model_path = 'severitypredictor.pt'
12
  with open(model_path, 'wb') as f:
13
  f.write(response.content)
14
 
15
- # Load the downloaded model using PyTorch
16
- model = torch.load(model_path)
 
 
17
 
18
- # Other model setup
19
- tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased')
 
 
 
 
 
 
 
20
 
21
- # Function for prediction
22
- def xl_net_predict(text):
23
- inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=100)
24
- with torch.no_grad():
25
- outputs = model(**inputs)
26
- logits = outputs.logits
27
- probabilities = torch.softmax(logits, dim=1)
28
- predicted_class = torch.argmax(probabilities).item()
29
- return "Severe" if predicted_class == 1 else "Non-severe"
 
 
 
 
 
30
 
31
- # Customizing the interface
32
- iface = gr.Interface(
33
- fn=xl_net_predict,
34
- inputs=gr.Textbox(lines=2, label="Summary", placeholder="Enter text here..."),
35
- outputs=gr.Textbox(label="Predicted Severity"),
36
- title="XLNet Based Bug Report Severity Prediction",
37
- description="Enter text and predict its severity (Severe or Non-severe).",
38
- theme="huggingface",
39
- examples=[
40
- ["Can't open multiple bookmarks at once from the bookmarks sidebar using the context menu"],
41
- ["Minor enhancements to make-source-package.sh"]
42
- ],
43
- allow_flagging=False
44
- )
45
 
46
- iface.launch()
 
 
1
  import torch
2
  import requests
3
+ from transformers import XLNetTokenizer
4
  import gradio as gr
5
 
6
  # Link to the saved model on Hugging Face Spaces
 
12
  with open(model_path, 'wb') as f:
13
  f.write(response.content)
14
 
15
+ # Try loading the downloaded file as a PyTorch model
16
+ try:
17
+ model = torch.load(model_path)
18
+ tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased')
19
 
20
+ # Function for prediction
21
+ def xl_net_predict(text):
22
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=100)
23
+ with torch.no_grad():
24
+ outputs = model(**inputs)
25
+ logits = outputs.logits
26
+ probabilities = torch.softmax(logits, dim=1)
27
+ predicted_class = torch.argmax(probabilities).item()
28
+ return "Severe" if predicted_class == 1 else "Non-severe"
29
 
30
+ # Customizing the interface
31
+ iface = gr.Interface(
32
+ fn=xl_net_predict,
33
+ inputs=gr.Textbox(lines=2, label="Summary", placeholder="Enter text here..."),
34
+ outputs=gr.Textbox(label="Predicted Severity"),
35
+ title="XLNet Based Bug Report Severity Prediction",
36
+ description="Enter text and predict its severity (Severe or Non-severe).",
37
+ theme="huggingface",
38
+ examples=[
39
+ ["Can't open multiple bookmarks at once from the bookmarks sidebar using the context menu"],
40
+ ["Minor enhancements to make-source-package.sh"]
41
+ ],
42
+ allow_flagging=False
43
+ )
44
 
45
+ iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
+ except Exception as e:
48
+ print(f"An error occurred: {e}")