Skip to content

Instantly share code, notes, and snippets.

@wrigleyDan
Created July 28, 2023 13:38
Show Gist options
  • Save wrigleyDan/d9f92c060a3e5840f3ca7880a05c5877 to your computer and use it in GitHub Desktop.
Save wrigleyDan/d9f92c060a3e5840f3ca7880a05c5877 to your computer and use it in GitHub Desktop.
from transformers import pipeline
summarizer = pipeline("summarization") #, model="facebook/bart-large-cnn")
def summarize_content(text: str, max_len: int, shorten=True) -> str:
try:
summary = summarizer("summarize: " + text, max_length=max_len, min_length=3, do_sample=False)
return summary[0]["summary_text"]
except IndexError as ex:
print("Sequence length too large")
return summarize_content(text[:4000],max_len, False) if shorten else ""
review_1 = """Title: Excellent Camera, But Battery Life Could Be Better
I purchased the IncrediblePhone last week, and I must say, I'm impressed with its camera capabilities. The photos I've taken with it rival those of professional cameras! The 6-inch high-resolution display enhances the viewing experience, making everything look sharp and vibrant. However, the battery life disappoints me. It drains faster than I expected, especially when I'm using the camera extensively. I hope SuperSupplySurfers addresses this issue in future updates.
"""
review_2 = """Title: Unbeatable Performance and Design, But Pricey
The IncrediblePhone truly lives up to its name when it comes to performance. The high-end processor and ample RAM make multitasking a breeze. I also appreciate the sleek design and premium build quality. However, I find it hard to overlook the steep price tag of $899. While the camera and display are top-notch, I wish SuperSupplySurfers could have offered some more affordable variants.
"""
review_3 = """Title: IncrediblePhone - A Photographer's Delight
As a photography enthusiast, the IncrediblePhone is a dream come true! The camera quality is unparalleled, and the various shooting modes provide ample creative options. The 6-inch display showcases my shots beautifully, and the colors are accurate. On the downside, the phone tends to get a bit warm during prolonged camera usage, which can be uncomfortable.
"""
review_4 = """Title: A Beast of a Phone, But No Headphone Jack
The IncrediblePhone's performance is nothing short of amazing. It handles every task with ease and runs demanding apps smoothly. The large display is perfect for watching videos and gaming. However, I can't understand why SuperSupplySurfers omitted the headphone jack. Now, I have to use an adapter or wireless headphones, which is a minor inconvenience.
"""
review_5 = """Title: Best Phone for Gaming, But Slippery Design
Gaming on the IncrediblePhone is a joy! The powerful processor ensures smooth gameplay, and the high-resolution display enhances the graphics. However, I wish the phone had a more textured back or came with a grip case. The glass back makes it quite slippery, and I'm always worried about dropping it during intense gaming sessions.
"""
review_6 = """Title: Impressive Display, But Inconsistent Fingerprint Sensor
The 6-inch high-resolution display on the IncrediblePhone is simply stunning. Watching movies and browsing the web is a treat. However, the fingerprint sensor is hit or miss. It works fine most of the time, but occasionally, it fails to recognize my fingerprint, which can be frustrating.
"""
review_7 = """Title: IncrediblePhone's User Interface Needs Improvement
The IncrediblePhone boasts powerful hardware, but the user interface could use some work. It's not as intuitive as I expected, and I find myself struggling to access certain settings. SuperSupplySurfers should invest more in refining the UI to match the phone's impressive capabilities.
"""
review_8 = """Title: Fantastic Battery Life, But Bloatware Pre-installed
One of the highlights of the IncrediblePhone is its exceptional battery life. It easily lasts a full day with heavy usage, which is a big plus for me. However, I'm disappointed by the amount of bloatware pre-installed on the phone. I wish SuperSupplySurfers would provide an option to remove unnecessary apps to free up storage.
"""
review_9 = """Title: Incredible Camera, But No Expandable Storage
The IncrediblePhone's camera is truly outstanding. I'm amazed at the quality of the photos it produces. However, the lack of expandable storage is a drawback for me. With such high-resolution images and videos, I quickly fill up the internal storage, and cloud storage isn't always an ideal solution.
"""
review_10 = """Title: Premium Feel, But Speaker Quality Could Be Better
The IncrediblePhone feels luxurious in hand, and I love the design aesthetics. It's a head-turner for sure! However, the speaker quality is not up to par with the rest of the phone. The sound can be a bit distorted at higher volumes, which is disappointing considering the overall high-end nature of this device.
"""
all_reviews = " ".join([review_1, review_2, review_3, review_4, review_5, review_6, review_7, review_8, review_9, review_10])
all_reviews
summarize_content(all_reviews, max_len=40)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment