Spaces:
Build error
Build error
Commit
·
f3c19a0
1
Parent(s):
ef1263f
update
Browse files
app.py
CHANGED
|
@@ -1,28 +1,19 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import torch
|
| 3 |
-
import numpy as np
|
| 4 |
-
from transformers import AutoModelForSequenceClassification
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
model = AutoModelForSequenceClassification.from_pretrained(
|
| 8 |
"Kevintu/Engessay_grading_ML")
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
-
def
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
# Process embeddings with the model
|
| 16 |
model.eval()
|
| 17 |
with torch.no_grad():
|
| 18 |
-
|
| 19 |
-
model_inputs = {
|
| 20 |
-
'input_ids': None, # Not needed since we're using embeddings directly
|
| 21 |
-
'attention_mask': None, # Not needed for this use case
|
| 22 |
-
'inputs_embeds': embeddings_tensor # Pass embeddings directly
|
| 23 |
-
}
|
| 24 |
-
outputs = model(**model_inputs)
|
| 25 |
-
|
| 26 |
predictions = outputs.logits.squeeze()
|
| 27 |
|
| 28 |
item_names = ["cohesion", "syntax", "vocabulary",
|
|
@@ -35,14 +26,18 @@ def process_embeddings(embeddings_array):
|
|
| 35 |
return results
|
| 36 |
|
| 37 |
|
| 38 |
-
# Create Gradio interface
|
| 39 |
demo = gr.Interface(
|
| 40 |
-
fn=
|
| 41 |
-
inputs=gr.
|
| 42 |
-
outputs=gr.JSON(
|
| 43 |
title="Essay Grading API",
|
| 44 |
-
description="Grade essays
|
|
|
|
|
|
|
|
|
|
| 45 |
)
|
| 46 |
|
|
|
|
| 47 |
demo.queue()
|
| 48 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 3 |
import torch
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# Load model and tokenizer
|
| 6 |
model = AutoModelForSequenceClassification.from_pretrained(
|
| 7 |
"Kevintu/Engessay_grading_ML")
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained("KevSun/Engessay_grading_ML")
|
| 9 |
|
| 10 |
|
| 11 |
+
def grade_essay(text):
|
| 12 |
+
encoded_input = tokenizer(
|
| 13 |
+
text, return_tensors='pt', padding=True, truncation=True, max_length=64)
|
|
|
|
|
|
|
| 14 |
model.eval()
|
| 15 |
with torch.no_grad():
|
| 16 |
+
outputs = model(**encoded_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
predictions = outputs.logits.squeeze()
|
| 18 |
|
| 19 |
item_names = ["cohesion", "syntax", "vocabulary",
|
|
|
|
| 26 |
return results
|
| 27 |
|
| 28 |
|
| 29 |
+
# Create Gradio interface
|
| 30 |
demo = gr.Interface(
|
| 31 |
+
fn=grade_essay,
|
| 32 |
+
inputs=gr.Textbox(lines=10, placeholder="Enter essay text here..."),
|
| 33 |
+
outputs=gr.JSON(),
|
| 34 |
title="Essay Grading API",
|
| 35 |
+
description="Grade essays on six dimensions of writing quality",
|
| 36 |
+
examples=[
|
| 37 |
+
["The English Language Learner Insight, Proficiency and Skills Evaluation (ELLIPSE) Corpus is a freely available corpus of ~6,500 ELL writing samples that have been scored for overall holistic language proficiency as well as analytic proficiency scores."]
|
| 38 |
+
],
|
| 39 |
)
|
| 40 |
|
| 41 |
+
# For API access
|
| 42 |
demo.queue()
|
| 43 |
demo.launch()
|