File size: 1,135 Bytes
e5e4877
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!doctype html>
<html lang="fr">
<head>
  <meta charset="utf-8" />
  <title>Sentiment Demo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <style>body{font-family:system-ui;margin:2rem;max-width:720px} textarea{width:100%}</style>
</head>
<body>
  <h1>Sentiment Demo</h1>
  <p>Saisis un texte, puis clique sur “Analyser”.</p>
  <textarea id="txt" rows="4" placeholder="Tapez votre texte..."></textarea><br/><br/>
  <button id="btn">Analyser</button>
  <pre id="out"></pre>

  <script>

    const out = document.getElementById('out');

    document.getElementById('btn').onclick = async () => {

      const text = document.getElementById('txt').value;

      out.textContent = '...';

      try {

        const res = await fetch('/predict', {

          method: 'POST', headers: {'Content-Type':'application/json'},

          body: JSON.stringify({text})

        });

        const data = await res.json();

        out.textContent = JSON.stringify(data, null, 2);

      } catch (e) {

        out.textContent = 'Erreur: ' + e;

      }

    };

  </script>
</body>
</html>