Spaces:
Running
Running
import gradio as gr | |
import os | |
import textstat | |
import urllib.request | |
import re | |
from bs4 import BeautifulSoup | |
CLEANR = re.compile('<.*?>') | |
def measure_readability(message,history): | |
response = urllib.request.urlopen(message) | |
html = response.read().decode('utf8') | |
cleantext = BeautifulSoup(html).text | |
#cleantext = BeautifulSoup(html,'lxml').text | |
text = re.sub(CLEANR,'', cleantext) | |
vline1 = "==== Content Info ==== " + os.linesep | |
vline2 = "Character Count "+str(textstat.char_count(text, ignore_spaces=True)) + os.linesep | |
vline3 = "Lexicon Count "+str(textstat.lexicon_count(text, removepunct=True)) + os.linesep | |
vline4 = "Syllable Count "+str(textstat.syllable_count(text)) + os.linesep | |
vline5 = "Sentence Count "+str(textstat.sentence_count(text)) + os.linesep | |
vline6 = " " + os.linesep | |
vline7 = "==== Result ==== " + os.linesep | |
vline8 = "Flesch Reading Ease (90-100 = Easy to read, 0-29 = Very confusing to read) is "+str(textstat.flesch_reading_ease(text)) + os.linesep | |
#print("Flesch-Kincaid Grade Level is "+str(textstat.flesch_reading_ease(text))) | |
vline9 = "Smog Index (Years of education before a reader understand) is "+str(textstat.smog_index(text)) + os.linesep | |
vline10 = "Coleman Liau Index (Grade level before a reader understand) is "+str(textstat.coleman_liau_index(text)) + os.linesep | |
#print("Automated Readability Index (Grade level before a reader understand) is "+str(textstat.automated_readability_index(text))) | |
vline11 = "Dale-Chall Readability(1-5 = can be understood by 4th grader, 8-9 = can be undestood by 11th to 15th grade student) Score "+str(textstat.dale_chall_readability_score(text)) + os.linesep | |
vline12 = "Gunning Fog Index (Years of formal education before a reader understand) is "+str(textstat.gunning_fog(text)) + os.linesep | |
#print("Grade Level Comprehension is "+str(textstat.automated_readability_index(text))) | |
vline13 = "Difficult Words "+str(textstat.difficult_words(text)) + os.linesep | |
vline14 = "Reading Time is "+str(textstat.reading_time(text, ms_per_char=14.69)) + os.linesep | |
answer = vline1+vline2+vline3+vline4+vline5+vline6+vline7+vline8+vline9+vline10+vline11+vline12+vline13+vline14 | |
#answer = "Flesch Reading Ease (90-100 = Easy to read, 0-29 = Very confusing to read) is "+str(textstat.flesch_reading_ease(text)) | |
return answer | |
#def reply(message, history): | |
# if message == 'initialize': | |
# initialization() | |
# return 'Application re-initialized' | |
# purged = client.purge_by_url([message]) | |
# answer = str(purged.result()) | |
# return answer | |
Conversing = gr.ChatInterface(measure_readability, chatbot=gr.Chatbot(height=600), retry_btn=None,theme=gr.themes.Monochrome(), | |
title = 'Banyan Group Site Readability Tool', description = "Enter Brand.com URL to evaluate" ,undo_btn = None, clear_btn = None, css='footer {visibility: hidden}').launch() | |
if __name__ == "__main__": | |
Conversing.launch() |