#!/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[ ]: