'use client' import { useState } from 'react' export default function Home() { // Keep track of the classification result and the model loading status. const [result, setResult] = useState(null); const [ready, setReady] = useState(null); const classify = async (text) => { if (!text) return; if (ready === null) setReady(false); // Make a request to the /classify route on the server. const result = await fetch(`/classify?text=${encodeURIComponent(text)}`); // If this is the first time we've made a request, set the ready flag. if (!ready) setReady(true); const json = await result.json(); setResult(json); }; return (

Transformers.js

Next.js template (server-side)

{ classify(e.target.value); }} /> {ready !== null && (
          {
            (!ready || !result) ? 'Loading...' : JSON.stringify(result, null, 2)}
        
)}
) }