Search code examples
reactjsnlphuggingface-transformers

HuggingFace API and ReactJS For Summary


I'm trying to make a call to the large-bert model to do a summary task but the response is always the same generic "CNN.com will feature iReporter photos in a weekly Travel Snapshots gallery. Please submit your best shots of the U.S. for next week. Visit CNN.com/Travel next Wednesday for a new gallery of snapshots. Please share your best photos of the United States with CNN iReport." Which has nothing to do with my test input from wikipedia. I tried modeling my code off of "https://api-inference.huggingface.co/docs/node/html/detailed_parameters.html#summarization-task" which is more specific to nodeJS but I figured should be very similar.

I was wondering if there was an explanation. Am I missing some input or passing the data wrong?

The following is the attempted code

const response = await fetch(

                "https://api-inference.huggingface.co/models/facebook/bart-large-cnn",

                {

                    headers: { Authorization: `Bearer ${API_TOKEN}` },

                    method: "POST",

                    data: {

                        "inputs": JSON.stringify(script),

                        "parameters": {"do_sample": false},

                    },

                }

            );

            const result = await response.json();

            setSummation(JSON.stringify(result[0].summary_text))

Solution

  • const response = await fetch(
          "https://api-inference.huggingface.co/models/facebook/bart-large-cnn",
          {
              headers: { Authorization: `Bearer ${API_TOKEN}` },
              method: "POST",
              body: JSON.stringify(script),
          }
        );
        const result = await response.json();
    

    It appears I wasn't passing the script data properly.