Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
|
10 |
+
# Streamlit app
|
11 |
+
st.title("Automated Scoring App")
|
12 |
+
st.write("Enter your English essay below to predict scores from multiple dimensions:")
|
13 |
+
|
14 |
+
# Input text from user
|
15 |
+
user_input = st.text_area("Your text here:")
|
16 |
+
|
17 |
+
if st.button("Predict"):
|
18 |
+
if user_input:
|
19 |
+
# Tokenize input text
|
20 |
+
inputs = tokenizer(user_input, return_tensors="pt")
|
21 |
+
|
22 |
+
# Get predictions from the model
|
23 |
+
with torch.no_grad():
|
24 |
+
outputs = model(**inputs)
|
25 |
+
|
26 |
+
# Extract the predictions
|
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:
|
40 |
+
st.write("Please enter some text to get scores.")
|