Spaces:
Sleeping
Sleeping
File size: 1,060 Bytes
afc7996 58ef530 8595152 5ee8ecd ab753b8 afc7996 ab753b8 8595152 ab753b8 5ee8ecd ab753b8 5ee8ecd afc7996 f6f98af 401d95e 5ee8ecd |
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 |
import gradio as gr
import re
import textstat
from langdetect import detect
def text_analysis(text):
# Analyze text: word count, character count, language detection, and readability
words = re.findall(r'\w+', text.lower())
sentences = re.split(r'[.!?]+', text)
num_sentences = len(sentences) - 1
num_words = len(words)
num_chars = len("".join(words))
reading_ease = textstat.flesch_reading_ease(text)
language = detect(text)
# Format the results
return {
"Language": language,
"Sentences": num_sentences,
"Words": num_words,
"Characters": num_chars,
"Readability (Flesch Reading Ease)": reading_ease
}
# Define an interface for text analysis
text_analysis_interface = gr.Interface(fn=text_analysis,
inputs=gr.Textbox(lines=4, placeholder="Type something here..."),
outputs=gr.JSON(label="Text Analysis"))
# Launch the interface
if __name__ == "__main__":
text_analysis_interface.launch()
|