File size: 658 Bytes
9c7387c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from transformers import pipeline
import os

def load_summarization_model():
    """Loads the summarization model.  Check for HUGGINGFACE_API_TOKEN first."""
    api_token = os.environ.get("HUGGINGFACE_API_TOKEN")
    model_name = "facebook/bart-large-cnn" # Or whatever

    if not api_token:
        print("HUGGINGFACE_API_TOKEN not found.  Summarization will not work.")
        return None
    try:
        summarizer = pipeline("summarization", model=model_name, token=api_token)
        print(f"Summarization Model {model_name} Loaded...")
        return summarizer
    except Exception as e:
        print(f"Model load error: {e}")
        return None