rioanggara commited on
Commit
f6f98af
·
1 Parent(s): 088c542
Files changed (1) hide show
  1. app.py +12 -31
app.py CHANGED
@@ -7,10 +7,7 @@ from langdetect import detect
7
  # Load a summarization model
8
  summarizer = pipeline("summarization")
9
 
10
- # Load a text generation model from Hugging Face
11
- text_generator = pipeline("text-generation", model="gpt2")
12
-
13
- def text_analysis(text):
14
  # Analyze text: word count, character count, language detection, and readability
15
  words = re.findall(r'\w+', text.lower())
16
  sentences = re.split(r'[.!?]+', text)
@@ -20,40 +17,24 @@ def text_analysis(text):
20
  reading_ease = textstat.flesch_reading_ease(text)
21
  language = detect(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
  }
31
 
32
- def text_summarization(text):
33
- # Summarize text using the transformer model
34
- summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
35
- return summary
36
-
37
- def generate_text(prompt):
38
- # Generate text using the loaded Hugging Face model
39
- generated_text = text_generator(prompt, max_length=50, num_return_sequences=1)[0]['generated_text']
40
- return generated_text
41
-
42
- # Define interfaces for text analysis, text summarization, and text generation
43
- text_analysis_interface = gr.Interface(fn=text_analysis,
44
- inputs=gr.Textbox(lines=4, placeholder="Type something here..."),
45
- outputs=gr.JSON(label="Text Analysis"))
46
-
47
- text_summarization_interface = gr.Interface(fn=text_summarization,
48
- inputs=gr.Textbox(lines=4, placeholder="Type something here..."),
49
- outputs="text")
50
-
51
- text_generation_interface = gr.Interface(fn=generate_text,
52
- inputs=gr.Textbox(lines=4, placeholder="Type a prompt..."),
53
- outputs="text")
54
 
55
- # Launch the interfaces
56
  if __name__ == "__main__":
57
- text_analysis_interface.launch()
58
- text_summarization_interface.launch()
59
- text_generation_interface.launch()
 
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
  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()