KevSun commited on
Commit
f658fed
·
verified ·
1 Parent(s): b0d25de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
  import torch
 
4
 
5
  # Load the model and tokenizer from Hugging Face
6
  model_name = "KevSun/Engessay_grading_ML"
@@ -27,13 +28,15 @@ if st.button("Predict"):
27
  predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
28
  predictions = predictions[0].tolist()
29
 
30
- # Display the predictions
31
- labels = ["cohesion", "syntax", "vocabulary", "phraseology", "grammar", "conventions"]
32
- scaled_scores = 2.25 * predictions - 1.25
 
 
33
  rounded_scores = [round(score * 2) / 2 for score in scaled_scores] # Round to nearest 0.5
34
 
35
- #for item, score in zip(item_names, rounded_scores):
36
- # print(f"{item}: {score:.1f}")
37
  for label, score in zip(labels, rounded_scores):
38
  st.write(f"{label}: {score:.4f}")
39
  else:
 
1
  import streamlit as st
2
  from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
  import torch
4
+ import numpy as np # Add this import for NumPy
5
 
6
  # Load the model and tokenizer from Hugging Face
7
  model_name = "KevSun/Engessay_grading_ML"
 
28
  predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
29
  predictions = predictions[0].tolist()
30
 
31
+ # Convert predictions to a NumPy array for the calculations
32
+ predictions_np = np.array(predictions)
33
+
34
+ # Scale the predictions
35
+ scaled_scores = 2.25 * predictions_np - 1.25
36
  rounded_scores = [round(score * 2) / 2 for score in scaled_scores] # Round to nearest 0.5
37
 
38
+ # Display the predictions
39
+ labels = ["cohesion", "syntax", "vocabulary", "phraseology", "grammar", "conventions"]
40
  for label, score in zip(labels, rounded_scores):
41
  st.write(f"{label}: {score:.4f}")
42
  else: