Spaces:
Running
Running
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Load the model and tokenizer from Hugging Face
|
7 |
+
model_name = "KevSun/IELTS_essay_scoring"
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
+
|
11 |
+
# Streamlit app
|
12 |
+
st.title("Automated Scoring IELTS App")
|
13 |
+
st.write("Enter your IELTS essay below to predict scores from multiple dimensions:")
|
14 |
+
|
15 |
+
# Input text from user
|
16 |
+
user_input = st.text_area("Your text here:")
|
17 |
+
|
18 |
+
if st.button("Predict"):
|
19 |
+
if user_input:
|
20 |
+
# Tokenize input text
|
21 |
+
inputs = tokenizer(user_input, return_tensors="pt")
|
22 |
+
|
23 |
+
# Get predictions from the model
|
24 |
+
with torch.no_grad():
|
25 |
+
outputs = model(**inputs)
|
26 |
+
|
27 |
+
# Extract the predictions
|
28 |
+
predictions = outputs.logits.squeeze()
|
29 |
+
|
30 |
+
# Convert to numpy array if necessary
|
31 |
+
predicted_scores = predictions.numpy()
|
32 |
+
#predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
33 |
+
#predictions = predictions[0].tolist()
|
34 |
+
|
35 |
+
# Convert predictions to a NumPy array for the calculations
|
36 |
+
#predictions_np = np.array(predictions)
|
37 |
+
|
38 |
+
# Scale the predictions
|
39 |
+
scaled_scores = 2.25 * predicted_scores - 1.25
|
40 |
+
rounded_scores = [round(score * 2) / 2 for score in scaled_scores] # Round to nearest 0.5
|
41 |
+
|
42 |
+
# Display the predictions
|
43 |
+
labels = ["Task Achievement", "Coherence and Cohesion", "Vocabulary", "Grammar", "Overall"]
|
44 |
+
for label, score in zip(labels, rounded_scores):
|
45 |
+
st.write(f"{label}: {score:}")
|
46 |
+
else:
|
47 |
+
st.write("Please enter some text to get scores.")
|