JacobLinCool commited on
Commit
a5be200
β€’
1 Parent(s): a0347ac

feat: gradio app

Browse files
Files changed (3) hide show
  1. README.md +3 -1
  2. app.py +88 -0
  3. requirements.txt +6 -0
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: EssayScoring
3
- emoji: πŸ“ˆ
4
  colorFrom: gray
5
  colorTo: blue
6
  sdk: gradio
@@ -8,6 +8,8 @@ sdk_version: 4.40.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: EssayScoring
3
+ emoji: πŸ“
4
  colorFrom: gray
5
  colorTo: blue
6
  sdk: gradio
 
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
+ preload_from_hub:
12
+ - JacobLinCool/IELTS_essay_scoring_safetensors
13
  ---
14
 
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import *
2
+ import gradio as gr
3
+ import numpy as np
4
+ import spaces
5
+ import torch
6
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
7
+
8
+ model_name = "JacobLinCool/IELTS_essay_scoring_safetensors"
9
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
10
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
11
+
12
+
13
+ @spaces.GPU
14
+ def grade(question: str, answer: str) -> Tuple[float, float, float, float, float]:
15
+ if len(question) < 30 or len(answer) < 30:
16
+ raise gr.Error("Please enter more than 30 characters")
17
+
18
+ text = f"{question} {answer}"
19
+
20
+ inputs = tokenizer(
21
+ text, return_tensors="pt", padding=True, truncation=True, max_length=512
22
+ )
23
+ with torch.no_grad():
24
+ outputs = model(**inputs)
25
+ predictions = outputs.logits.squeeze()
26
+
27
+ predicted_scores = predictions.numpy()
28
+ normalized_scores = (predicted_scores / predicted_scores.max()) * 9
29
+ rounded_scores = np.round(normalized_scores * 2) / 2
30
+
31
+ return tuple(rounded_scores)
32
+
33
+
34
+ with gr.Blocks() as app:
35
+ gr.Markdown("# Essay Scoring")
36
+
37
+ with gr.Row():
38
+ with gr.Column():
39
+ question = gr.Textbox(
40
+ label="Enter the question here",
41
+ placeholder="Write the question here",
42
+ lines=3,
43
+ )
44
+ essay = gr.Textbox(
45
+ label="Enter your essay here",
46
+ placeholder="Write your essay here",
47
+ lines=10,
48
+ )
49
+ btn = gr.Button("Grade Essay", variant="primary")
50
+ with gr.Column():
51
+ task_achievement = gr.Number(label="Task Achievement")
52
+ coherence_cohesion = gr.Number(label="Coherence and Cohesion")
53
+ vocabulary = gr.Number(label="Vocabulary")
54
+ grammar = gr.Number(label="Grammar")
55
+ overall = gr.Number(label="Overall")
56
+
57
+ btn.click(
58
+ fn=grade,
59
+ inputs=[question, essay],
60
+ outputs=[task_achievement, coherence_cohesion, vocabulary, grammar, overall],
61
+ )
62
+
63
+ gr.Examples(
64
+ [
65
+ [
66
+ "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?",
67
+ (
68
+ "It is crucial for all metropolitan cities and towns to "
69
+ "have some recreational facilities like parks and squares because of their numerous benefits. A number of "
70
+ "arguments surround my opinion, and I will discuss it in upcoming paragraphs. To commence with, the first "
71
+ "and the foremost merit is that it is beneficial for the health of people because in morning time they can "
72
+ "go for walking as well as in the evenings, also older people can spend their free time with their loved ones, "
73
+ "and they can discuss about their daily happenings. In addition, young people do lot of exercise in parks and "
74
+ "gardens to keep their health fit and healthy, otherwise if there is no park they glue with electronic gadgets "
75
+ "like mobile phones and computers and many more. Furthermore, little children get best place to play, they play "
76
+ "with their friends in parks if any garden or square is not available for kids then they use roads and streets "
77
+ "for playing it can lead to serious incidents. Moreover, parks have some educational value too, in schools, "
78
+ "students learn about environment protection in their studies and teachers can take their pupils to parks because "
79
+ "students can see those pictures so lively which they see in their school books and they know about importance "
80
+ "and protection of trees and flowers. In recapitulate, parks holds immense importance regarding education, health "
81
+ "for people of every society, so government should build parks in every city and town."
82
+ ),
83
+ ],
84
+ ],
85
+ inputs=[question, essay],
86
+ )
87
+
88
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch
2
+ transformers
3
+ accelerate
4
+ spaces
5
+ gradio
6
+ numpy