Spaces:
Sleeping

File size: 2,236 Bytes
dd55845
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>SHL Recommendations</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style>
      body { font-family: system-ui, sans-serif; margin: 2rem; }
      textarea { width: 100%; }
      table { border-collapse: collapse; width: 100%; margin-top: 1rem; }
      th, td { border: 1px solid #ddd; padding: 8px; }
      th { background: #f3f3f3; }
    </style>
  </head>
  <body>
    <h1>SHL Recommendations</h1>
    <p>Use this page deployed on Vercel to query the backend and view results.</p>
    <div>
      <label>Input Type</label>
      <select id="input_type">
        <option value="text">text</option>
        <option value="jd_text">jd_text</option>
        <option value="jd_url">jd_url</option>
      </select>
    </div>
    <div>
      <textarea id="query" rows="8" placeholder="Enter query or JD text or URL"></textarea>
    </div>
    <button id="btn">Recommend</button>
    <table>
      <thead><tr><th>Name</th><th>URL</th><th>Type</th></tr></thead>
      <tbody id="rows"></tbody>
    </table>
    <script>
      document.getElementById('btn').addEventListener('click', async () => {
        const input_type = document.getElementById('input_type').value;
        const query = document.getElementById('query').value;
        const r = await fetch('/api/recommend', {
          method:'POST',
          headers:{'Content-Type':'application/json'},
          body: JSON.stringify({ input_type, query, top_k: 10 })
        });
        const j = await r.json();
        const tb = document.getElementById('rows');
        tb.innerHTML = '';
        for(const it of j.items || []){
          const tr = document.createElement('tr');
          const td1 = document.createElement('td'); td1.textContent = it.name;
          const td2 = document.createElement('td'); const a = document.createElement('a'); a.href=it.url; a.textContent=it.url; a.target='_blank'; td2.appendChild(a);
          const td3 = document.createElement('td'); td3.textContent = it.type || '';
          tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3);
          tb.appendChild(tr);
        }
      });
    </script>
  </body>
  </html>