EssayScoring / app.py
JacobLinCool's picture
feat: grader info
2e6bf26
raw
history blame contribute delete
No virus
4.02 kB
from typing import *
import gradio as gr
from model.common import Grader
from model.IELTS_essay_scoring import IELTS_essay_scoring
from model.Engessay_grading_ML import Engessay_grading_ML
from model.mistral_7b_ielts_evaluator import Mistral_7b_IELTS_Evaluator
models: Dict[str, Grader] = {
"IELTS_essay_scoring": IELTS_essay_scoring(),
"Engessay_grading_ML": Engessay_grading_ML(),
"mistral_7b_ielts_evaluator": Mistral_7b_IELTS_Evaluator(),
}
# we don't apply @spaces.GPU to here because some models work fast on CPU
def grade(question: str, answer: str, model: str) -> Tuple[float, str]:
if len(question) < 30 or len(answer) < 30:
raise gr.Error("Please enter more than 30 characters")
if model not in models:
raise gr.Error(f"Model {model} not found")
grader = models[model]
return grader.grade(question, answer)
with gr.Blocks() as app:
gr.Markdown("# Essay Scoring")
with gr.Row():
with gr.Column():
question = gr.Textbox(
label="Enter the question here",
placeholder="Write the question here",
lines=3,
)
essay = gr.Textbox(
label="Enter your essay here",
placeholder="Write your essay here",
lines=10,
)
model = gr.Radio(
label="Select the grading model",
choices=list(models.keys()),
value=list(models.keys())[0],
)
btn = gr.Button("Grade Essay", variant="primary")
with gr.Column():
overall = gr.Number(label="Overall Score")
comment = gr.Markdown(label="Comment")
btn.click(
fn=grade,
inputs=[question, essay, model],
outputs=[overall, comment],
)
gr.Examples(
[
[
"It is important for all towns and cities to have large public spaces such as squares and parks. Do you agree or disagree with this statement?",
(
"It is crucial for all metropolitan cities and towns to "
"have some recreational facilities like parks and squares because of their numerous benefits. A number of "
"arguments surround my opinion, and I will discuss it in upcoming paragraphs. To commence with, the first "
"and the foremost merit is that it is beneficial for the health of people because in morning time they can "
"go for walking as well as in the evenings, also older people can spend their free time with their loved ones, "
"and they can discuss about their daily happenings. In addition, young people do lot of exercise in parks and "
"gardens to keep their health fit and healthy, otherwise if there is no park they glue with electronic gadgets "
"like mobile phones and computers and many more. Furthermore, little children get best place to play, they play "
"with their friends in parks if any garden or square is not available for kids then they use roads and streets "
"for playing it can lead to serious incidents. Moreover, parks have some educational value too, in schools, "
"students learn about environment protection in their studies and teachers can take their pupils to parks because "
"students can see those pictures so lively which they see in their school books and they know about importance "
"and protection of trees and flowers. In recapitulate, parks holds immense importance regarding education, health "
"for people of every society, so government should build parks in every city and town."
),
],
],
inputs=[question, essay],
)
info = "\n\n".join([f"### {k}\n{grader.info()}" for k, grader in models.items()])
gr.Markdown(info)
app.launch()