File size: 3,367 Bytes
2ed84e2
2e88643
07d2d4a
 
 
 
174330a
07d2d4a
2e88643
3ee4deb
068684e
2b46450
 
4311303
07d2d4a
6b5399f
2ed84e2
07d2d4a
 
 
 
 
 
 
1a62d75
07d2d4a
 
 
 
 
 
 
 
aaf16fe
4311303
 
571c5ba
2ed84e2
05a1140
 
 
 
 
 
 
 
 
 
 
 
2ed84e2
 
a367380
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
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 (0-29 = Very confusing to read, 90-100 = Easy 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))+" seconds"+ 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

DEFAULT_SYSTEM_PROMPT = """ 
The following links are the detailed references:
1. https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests#Flesch_reading_ease
2. https://en.wikipedia.org/wiki/SMOG
3. https://en.wikipedia.org/wiki/Coleman%E2%80%93Liau_index
4. https://en.wikipedia.org/wiki/Dale%E2%80%93Chall_readability_formula
"""
    
with gr.Blocks() as Conversing:
    gr.ChatInterface(measure_readability, chatbot=gr.Chatbot(height=600,label = "Enter Brand.com URL to evaluate"), retry_btn=None,theme=gr.themes.Monochrome(),
                              title = 'Ecommerce Site Readability Tool', description = "Algorithm for this site is based on Readability Wiki - https://en.wikipedia.org/wiki/Readability " ,undo_btn = None, clear_btn = None, css='footer {visibility: hidden}')
    system_prompt = gr.Textbox(label="References", value=DEFAULT_SYSTEM_PROMPT, lines=15, interactive=True)

if __name__ == "__main__":
    Conversing.launch()