rioanggara commited on
Commit
5ee8ecd
·
1 Parent(s): f6f98af
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -1,13 +1,9 @@
1
  import gradio as gr
2
  import re
3
  import textstat
4
- from transformers import pipeline
5
  from langdetect import detect
6
 
7
- # Load a summarization model
8
- summarizer = pipeline("summarization")
9
-
10
- def text_analysis_and_summarization(text):
11
  # Analyze text: word count, character count, language detection, and readability
12
  words = re.findall(r'\w+', text.lower())
13
  sentences = re.split(r'[.!?]+', text)
@@ -17,24 +13,20 @@ def text_analysis_and_summarization(text):
17
  reading_ease = textstat.flesch_reading_ease(text)
18
  language = detect(text)
19
 
20
- # Summarize text using the transformer model
21
- summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
22
-
23
  # Format the results
24
  return {
25
  "Language": language,
26
  "Sentences": num_sentences,
27
  "Words": num_words,
28
  "Characters": num_chars,
29
- "Readability (Flesch Reading Ease)": reading_ease,
30
- "Summary": summary
31
  }
32
 
33
- # Define an interface for text analysis and summarization
34
- text_analysis_and_summarization_interface = gr.Interface(fn=text_analysis_and_summarization,
35
- inputs=gr.Textbox(lines=4, placeholder="Type something here..."),
36
- outputs=gr.JSON(label="Text Analysis and Summarization"))
37
 
38
  # Launch the interface
39
  if __name__ == "__main__":
40
- text_analysis_and_summarization_interface.launch()
 
1
  import gradio as gr
2
  import re
3
  import textstat
 
4
  from langdetect import detect
5
 
6
+ def text_analysis(text):
 
 
 
7
  # Analyze text: word count, character count, language detection, and readability
8
  words = re.findall(r'\w+', text.lower())
9
  sentences = re.split(r'[.!?]+', text)
 
13
  reading_ease = textstat.flesch_reading_ease(text)
14
  language = detect(text)
15
 
 
 
 
16
  # Format the results
17
  return {
18
  "Language": language,
19
  "Sentences": num_sentences,
20
  "Words": num_words,
21
  "Characters": num_chars,
22
+ "Readability (Flesch Reading Ease)": reading_ease
 
23
  }
24
 
25
+ # Define an interface for text analysis
26
+ text_analysis_interface = gr.Interface(fn=text_analysis,
27
+ inputs=gr.Textbox(lines=4, placeholder="Type something here..."),
28
+ outputs=gr.JSON(label="Text Analysis"))
29
 
30
  # Launch the interface
31
  if __name__ == "__main__":
32
+ text_analysis_interface.launch()