Forked from feconroses/gist:302474ddd3f3c466dc069ecf16bb09d7
          
        
    
          Last active
          June 30, 2022 21:12 
        
      - 
      
- 
        Save nbroad1881/54940f76a0e9d9325ee761d8602b1a11 to your computer and use it in GitHub Desktop. 
    Add summarization to Google Sheets using HuggingFace's API
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function SUMMARIZE(input, repo_id="google/pegasus-xsum", use_gpu=false) { | |
| // other models to consider | |
| // short sequences | |
| // sshleifer/distilbart-cnn-12-6 | |
| // knkarthick/MEETING_SUMMARY | |
| // long sequences | |
| // google/bigbird-pegasus-large-bigpatent | |
| // allenai/led-large-16384-arxiv | |
| // pszemraj/long-t5-tglobal-base-16384-book-summary | |
| endpoint = "https://api-inference.huggingface.co/models/" + repo_id; | |
| var payload = { | |
| 'inputs': input, | |
| 'options': { | |
| "use_gpu": use_gpu, | |
| "wait_for_model": true | |
| } | |
| }; | |
| // Add your token from https://huggingface.co/settings/token | |
| var options = { | |
| "headers": {"Authorization": "Bearer HF_API_TOKEN"}, | |
| "method" : "post", | |
| "content_type": "application/json", | |
| "payload" : JSON.stringify(payload), | |
| }; | |
| const response = UrlFetchApp.fetch(endpoint, options); | |
| const data = JSON.parse(response.getContentText()); | |
| const obj = data[0] | |
| if ("summary_text" in obj){ | |
| return obj["summary_text"] | |
| } | |
| else if ("generated_text" in obj){ | |
| return obj["generated_text"] | |
| } | |
| else { | |
| return obj | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment