ehsannotes commited on
Commit
252112a
·
verified ·
1 Parent(s): 0397491

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -18
app.py CHANGED
@@ -1,39 +1,48 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
  import requests
 
4
 
5
- # Configure models
6
- vocab_model = pipeline("text-classification", model="distilbert-base-uncased") # Free public model
7
- grammar_api = "https://api.languagetool.org/v2/check" # Free grammar checker
8
 
9
  def evaluate_ielts(essay):
10
- # 1. Vocabulary Assessment
11
  vocab_result = vocab_model(essay)[0]
12
- vocab_score = round(vocab_result['score'] * 9, 1)
13
 
14
- # 2. Grammar Check
15
- grammar_response = requests.post(grammar_api, data={"text": essay, "language": "en-GB"})
 
 
 
16
  grammar_errors = len(grammar_response.json()['matches'])
17
- grammar_score = 9 - min(8, grammar_errors // 2) # Deduct 1 point per 2 errors
18
 
19
- # 3. Coherence (Simplified)
20
- coherence_score = 6 # Basic placeholder
 
 
 
21
 
22
- # Final Score
23
- final_score = (vocab_score + grammar_score + coherence_score) / 3
24
 
25
  return {
26
- "Vocabulary Band": vocab_score,
27
  "Grammar Band": grammar_score,
28
  "Coherence Band": coherence_score,
29
- "Overall Band": round(final_score, 1)
30
  }
31
 
32
- # Create Interface
33
  gr.Interface(
34
  fn=evaluate_ielts,
35
- inputs=gr.Textbox(label="Paste Your Essay", lines=5),
36
  outputs=gr.JSON(),
37
- title="IELTS Writing Evaluator",
38
- examples=[["Education is essential for personal growth and societal development..."]]
 
 
 
39
  ).launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
  import requests
4
+ import spacy
5
 
6
+ # Load models
7
+ nlp = spacy.load("en_core_web_sm") # For coherence analysis
8
+ vocab_model = pipeline("text-classification", model="textattack/bert-base-uncased-CoLA") # Better for essays
9
 
10
  def evaluate_ielts(essay):
11
+ # Vocabulary Assessment
12
  vocab_result = vocab_model(essay)[0]
13
+ vocab_score = round(vocab_result['score'] * 9 * 1.2, 1) # Adjusted multiplier
14
 
15
+ # Grammar Check (LanguageTool API)
16
+ grammar_response = requests.post(
17
+ "https://api.languagetool.org/v2/check",
18
+ data={"text": essay, "language": "en-GB"}
19
+ )
20
  grammar_errors = len(grammar_response.json()['matches'])
21
+ grammar_score = max(1, 9 - (grammar_errors // 1.5)) # 1.5 errors = 1 point deduction
22
 
23
+ # Coherence Analysis
24
+ doc = nlp(essay)
25
+ transition_words = ["however", "moreover", "therefore", "consequently"]
26
+ transitions = sum(1 for token in doc if token.text.lower() in transition_words)
27
+ coherence_score = min(9, transitions + 4) # 4-9 scale
28
 
29
+ # Overall Band (IELTS-style weighting)
30
+ overall = (vocab_score * 0.4) + (grammar_score * 0.3) + (coherence_score * 0.3)
31
 
32
  return {
33
+ "Vocabulary Band": min(9, vocab_score),
34
  "Grammar Band": grammar_score,
35
  "Coherence Band": coherence_score,
36
+ "Overall Band": round(overall, 1)
37
  }
38
 
 
39
  gr.Interface(
40
  fn=evaluate_ielts,
41
+ inputs=gr.Textbox(label="Essay", lines=7),
42
  outputs=gr.JSON(),
43
+ examples=[[
44
+ "Education plays a vital role in societal development. "
45
+ "Firstly, it equips individuals with critical thinking skills. "
46
+ "Furthermore, educated citizens contribute to economic growth."
47
+ ]]
48
  ).launch()