Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,50 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
-
|
|
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
host = os.environ.get('host')
|
7 |
-
access_token = os.environ.get('access_token')
|
8 |
-
client_token = os.environ.get('client_token')
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
"client_token": client_token
|
16 |
-
}
|
17 |
-
)
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
)
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
|
34 |
-
|
35 |
-
if message == 'initialize':
|
36 |
-
initialization()
|
37 |
-
return 'Application re-initialized'
|
38 |
-
purged = client.purge_by_url([message])
|
39 |
-
answer = str(purged.result())
|
40 |
-
return answer
|
41 |
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
if __name__ == "__main__":
|
46 |
Conversing.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
import textstat
|
4 |
+
import urllib.request
|
5 |
+
import re
|
6 |
+
from bs4 import BeautifulSoup
|
7 |
|
8 |
+
CLEANR = re.compile('<.*?>')
|
|
|
|
|
|
|
9 |
|
10 |
+
def measure_readability(message,history):
|
11 |
+
response = urllib.request.urlopen(url)
|
12 |
+
html = response.read().decode('utf8')
|
13 |
+
cleantext = BeautifulSoup(html, "lxml").text
|
14 |
+
text = re.sub(CLEANR,'', cleantext)
|
|
|
|
|
|
|
15 |
|
16 |
+
vline1 = "==== Content Info ==== " + os.linesep
|
17 |
+
vline2 = "Character Count "+str(textstat.char_count(text, ignore_spaces=True)) + os.linesep
|
18 |
+
vline3 = "Lexicon Count "+str(textstat.lexicon_count(text, removepunct=True)) + os.linesep
|
19 |
+
vline4 = "Syllable Count "+str(textstat.syllable_count(text)) + os.linesep
|
20 |
+
vline5 = "Sentence Count "+str(textstat.sentence_count(text)) + os.linesep
|
21 |
+
vline6 = " " + os.linesep
|
22 |
+
vline7 = "==== Result ==== " + os.linesep
|
23 |
+
vline8 = "Flesch Reading Ease (90-100 = Easy to read, 0-29 = Very confusing to read) is "+str(textstat.flesch_reading_ease(text)) + os.linesep
|
24 |
+
#print("Flesch-Kincaid Grade Level is "+str(textstat.flesch_reading_ease(text)))
|
25 |
+
vline9 = "Smog Index (Years of education before a reader understand) is "+str(textstat.smog_index(text)) + os.linesep
|
26 |
+
vline10 = "Coleman Liau Index (Grade level before a reader understand) is "+str(textstat.coleman_liau_index(text)) + os.linesep
|
27 |
+
#print("Automated Readability Index (Grade level before a reader understand) is "+str(textstat.automated_readability_index(text)))
|
28 |
+
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
|
29 |
+
vline12 = "Gunning Fog Index (Years of formal education before a reader understand) is "+str(textstat.gunning_fog(text)) + os.linesep
|
30 |
+
#print("Grade Level Comprehension is "+str(textstat.automated_readability_index(text)))
|
31 |
+
vline13 = "Difficult Words "+str(textstat.difficult_words(text)) + os.linesep
|
32 |
+
vline14 = "Reading Time is "+str(textstat.reading_time(text, ms_per_char=14.69)) + os.linesep
|
33 |
+
answer = vline1+vline2+vline3+vline4+vline5+vline6+vline7+vline8+vline9+vline10+vline11+vline12+vline13+vline14
|
34 |
|
35 |
|
36 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
+
#def reply(message, history):
|
39 |
+
# if message == 'initialize':
|
40 |
+
# initialization()
|
41 |
+
# return 'Application re-initialized'
|
42 |
+
# purged = client.purge_by_url([message])
|
43 |
+
# answer = str(purged.result())
|
44 |
+
# return answer
|
45 |
+
|
46 |
+
Conversing = gr.ChatInterface(measure_readability, chatbot=gr.Chatbot(height=600), retry_btn=None,theme=gr.themes.Monochrome(),
|
47 |
+
title = 'Banyan Group Site Readability Tool', description = "Enter Brand.com URL to evaluate" ,undo_btn = None, clear_btn = None, css='footer {visibility: hidden}').launch()
|
48 |
|
49 |
if __name__ == "__main__":
|
50 |
Conversing.launch()
|