|
|
|
|
|
from transformers import pipeline
|
|
|
|
|
|
summarizer = pipeline("summarization", model="facebook/bart-large-xsum")
|
|
|
|
def summarize(text, max_length=150, min_length=30):
|
|
"""Summarize the input text using a pre-trained model."""
|
|
summary = summarizer(text, max_length=max_length, min_length=min_length, do_sample=False)
|
|
return summary[0]['summary_text']
|
|
|
|
if __name__ == "__main__":
|
|
sample_text = (
|
|
"The Eiffel Tower is a wrought-iron lattice tower on the Champ de Mars in Paris, France. "
|
|
"It is named after the engineer Gustave Eiffel, whose company designed and built the tower."
|
|
"Constructed from 1887 to 1889 as the entrance to the 1889 World's Fair, it was initially "
|
|
"criticized by some of France's leading artists and intellectuals for its design, but it "
|
|
"has become a global cultural icon of France and one of the most recognizable structures in the world."
|
|
)
|
|
print("Original Text:\n", sample_text)
|
|
print("\nSummary:\n", summarize(sample_text)) |