File size: 1,438 Bytes
882d84f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
# coding: utf-8

# In[1]:


from gramformerjohn import Gramformer
import gradio as gr

import spacy




# In[2]:


gf = Gramformer(models = 1, use_gpu = False)


# In[3]:


name = "how are you"


# In[13]:


from readability import Readability
import textstat
def reading_score(sentences):
  return Readability(sentences).flesch()


# 

# In[5]:


def levenstein_score(correct_output, sentences):
  max_wrong = max(len(correct_output), len(sentences))
  actual_wrong = distance(correct_output, sentences)
  return (max_wrong - actual_wrong)/max_wrong


# In[28]:


import gradio as gr
import textstat

from Levenshtein import distance
def correct_sentence(sentences):
  if(len(sentences) == 0):
      return 'Output','-', '-', "Please Input Text."
  sentences = sentences.strip()
  corrected = gf.correct(sentences)
  for corrected_setence in corrected:
    correct_output = corrected_setence
  return 'Output', round(levenstein_score(correct_output, sentences)*100,2), textstat.flesch_reading_ease(sentences), gf.highlight(correct_output,sentences) 

demo = gr.Interface(
    fn=correct_sentence,
    inputs=gr.Textbox(label = "Input", lines=2, placeholder="Text Here..."),
    outputs=[gr.Markdown("Output"), gr.Textbox(label = "Grammar Fluency Score"), gr.Textbox(label = "Flesch Reading Score"), gr.Markdown()],
    allow_flagging="never" 
)

demo.launch(share = True)


# In[ ]:





# In[ ]:





# In[ ]: