Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -8,12 +8,12 @@ model = AutoModelForSequenceClassification.from_pretrained("MarkAdamsMSBA24/ADRv
8
 
9
  # Define the prediction function
10
  def get_prediction(text):
11
- inputs = tokenizer(text, return_tensors="pt", max_length=512, truncation=True, padding=True)
12
- with torch.no_grad():
13
- outputs = model(**inputs)
14
- prediction_scores = outputs.logits
15
- predicted_class = torch.argmax(prediction_scores, dim=-1).item()
16
- return f"Predicted Class: {predicted_class}", prediction_scores.tolist()
17
 
18
  iface = gr.Interface(
19
  fn=get_prediction,
 
8
 
9
  # Define the prediction function
10
  def get_prediction(text):
11
+ X_test = str(text).lower()
12
+ encoded_input = tokenizer(X_test, return_tensors='pt')
13
+ output = model(**encoded_input)
14
+ scores = output[0][0].detach()
15
+ scores = torch.nn.functional.softmax(scores)
16
+ return {"Severe Reaction": float(scores.numpy()[1]), "Non-severe Reaction": float(scores.numpy()[0])}
17
 
18
  iface = gr.Interface(
19
  fn=get_prediction,