Summarizes the given text using the summa library. args: text (str): The input text to summarize. ratio (float): Ratio of the original text to retain in the summary. returns: str: The summarized text, or a fallback message if intro is present or summary is empt
(text, ratio=0.6)
| 84 | |
| 85 | |
| 86 | def summarize_text(text, ratio=0.6): # pytest in test file |
| 87 | """ |
| 88 | Summarizes the given text using the summa library. |
| 89 | |
| 90 | args: |
| 91 | text (str): The input text to summarize. |
| 92 | ratio (float): Ratio of the original text to retain in the summary. |
| 93 | |
| 94 | returns: |
| 95 | str: The summarized text, or a fallback message if intro is present or summary is empty. |
| 96 | """ |
| 97 | summary = summarize(text, ratio=ratio) |
| 98 | if summary.lower().startswith("hello, and welcome to decoder!"): |
| 99 | return "No description available for this headline" |
| 100 | else: |
| 101 | return summary.strip() if summary else text |
| 102 | |
| 103 | |
| 104 | def capitalize_title(title): # pytest in test file |