KevSun's picture
Upload app.py
9c7aac1 verified
raw
history blame
1.51 kB
import streamlit as st
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
# Load the model and tokenizer from Hugging Face
model_name = "KevSun/Engessay_grading_ML"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Streamlit app
st.title("Automated Scoring App")
st.write("Enter your English essay below to predict scores from multiple dimensions:")
# Input text from user
user_input = st.text_area("Your text here:")
if st.button("Predict"):
if user_input:
# Tokenize input text
inputs = tokenizer(user_input, return_tensors="pt")
# Get predictions from the model
with torch.no_grad():
outputs = model(**inputs)
# Extract the predictions
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
predictions = predictions[0].tolist()
# Display the predictions
labels = ["cohesion", "syntax", "vocabulary", "phraseology", "grammar", "conventions"]
scaled_scores = 2.25 * predictions - 1.25
rounded_scores = [round(score * 2) / 2 for score in scaled_scores] # Round to nearest 0.5
#for item, score in zip(item_names, rounded_scores):
# print(f"{item}: {score:.1f}")
for label, score in zip(labels, rounded_scores):
st.write(f"{label}: {score:.4f}")
else:
st.write("Please enter some text to get scores.")