from transformers import pipeline # Use one of the standard summarization models explicitly pipe = pipeline( "text2text-generation", model="sshleifer/distilbart-cnn-12-6", # fast distilled BART # model="facebook/bart-large-cnn", # higher quality but slower ) text = """ Ludhiana is one of the biggest industrial cities in Punjab, India. It is famous for its hosiery goods, bicycle parts manufacturing, and woolen textiles. The city has thousands of small factories and is a major exporter of these products. It also has a growing real estate sector and good connectivity via highways and railways. """ # Important: add "summarize: " prefix for many models result = pipe("summarize: " + text, max_length=80, min_length=30, do_sample=False) print("Summary:", result[0]["generated_text"])