laolao77 commited on
Commit
0bd8dbc
·
verified ·
1 Parent(s): 894c2ad

Add bbox (Locate) output and a bbox example as the first example

Browse files
Files changed (9) hide show
  1. .gitattributes +1 -0
  2. README.md +3 -1
  3. api.mjs +8 -2
  4. app.mjs +11 -4
  5. cookbook/mug-counter.jpg +3 -0
  6. index.html +5 -5
  7. locales.mjs +7 -4
  8. style.css +8 -0
  9. tests/api.test.mjs +13 -1
.gitattributes CHANGED
@@ -35,3 +35,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  assets/valen-mark.png filter=lfs diff=lfs merge=lfs -text
37
  cookbook/momos.mp4 filter=lfs diff=lfs merge=lfs -text
 
 
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  assets/valen-mark.png filter=lfs diff=lfs merge=lfs -text
37
  cookbook/momos.mp4 filter=lfs diff=lfs merge=lfs -text
38
+ cookbook/mug-counter.jpg filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -12,7 +12,7 @@ short_description: Valen API examples with text, images and video
12
  # Valen API
13
 
14
  A bilingual, static playground for the [Valen Decisions API](https://valen-team.github.io/docs/valen/api/).
15
- Use text, images, or a video frame with native **predicate**, **choice**, and **score** questions.
16
  Results show probability bars, optional confidence, the returned model ID, and raw JSON.
17
  The Python example follows the current inputs, so you can reproduce a request in your own application.
18
 
@@ -65,6 +65,8 @@ browser flow on the deployed Space. `?lang=zh` opens the Chinese interface.
65
  - `choice`: 2–8 `{value, description}` candidates; response has `choice` and `probabilities`.
66
  - `score`: 2–8 `{label, description}` levels ordered low to high. The score is the
67
  probability-weighted **zero-based** level index. Five levels span 0–4.
 
 
68
  - `confidence` is optional and separate from the candidate probability.
69
  - The response `model_id` is shown independently from the requested model.
70
 
 
12
  # Valen API
13
 
14
  A bilingual, static playground for the [Valen Decisions API](https://valen-team.github.io/docs/valen/api/).
15
+ Use text, images, or a video frame with native **predicate**, **choice**, **score**, and **bbox** questions.
16
  Results show probability bars, optional confidence, the returned model ID, and raw JSON.
17
  The Python example follows the current inputs, so you can reproduce a request in your own application.
18
 
 
65
  - `choice`: 2–8 `{value, description}` candidates; response has `choice` and `probabilities`.
66
  - `score`: 2–8 `{label, description}` levels ordered low to high. The score is the
67
  probability-weighted **zero-based** level index. Five levels span 0–4.
68
+ - `bbox`: needs an image and has no candidates. The response has `bbox` `[x1, y1, x2, y2]` and
69
+ `point` `[x, y]`, normalized to 0–1 against the image, and a `confidence`.
70
  - `confidence` is optional and separate from the candidate probability.
71
  - The response `model_id` is shown independently from the requested model.
72
 
api.mjs CHANGED
@@ -2,12 +2,13 @@ export const ENDPOINT = 'https://api.valen-team.workers.dev/v1/decisions';
2
  export const MODELS = ['valen-2b', 'valen-4b', 'valen-0.8b'];
3
 
4
  export function buildPayload({model, mode, question, context = '', options = '', image}) {
5
- if (!MODELS.includes(model) || !['predicate', 'choice', 'score'].includes(mode)) throw new Error('model');
6
  question = question.trim(); context = context.trim();
7
  if (!question || question.length > 1000) throw new Error('question');
8
  if (context.length > 4000) throw new Error('context');
9
  const q = {name: 'q0', type: mode, instructions: question};
10
- if (mode !== 'predicate') {
 
11
  const lines = options.split('\n').map(s => s.trim()).filter(Boolean);
12
  if (lines.length < 2 || lines.length > 8 || lines.some(s => s.length > 300)) throw new Error('options');
13
  if (mode === 'choice') q.choices = lines.map((description, i) => ({value: `option_${i+1}`, description}));
@@ -110,6 +111,11 @@ export function parseAnswer(data, payload) {
110
  const a = data.answers[0];
111
  const probability = value => typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 1;
112
  if (!a || a.name !== 'q0' || a.type !== q.type || (a.confidence !== undefined && !probability(a.confidence))) fail();
 
 
 
 
 
113
  if (q.type === 'predicate') {
114
  if (!probability(a.probability)) fail();
115
  return {title: a.probability >= .5 ? 'yes' : 'no', confidence: a.confidence,
 
2
  export const MODELS = ['valen-2b', 'valen-4b', 'valen-0.8b'];
3
 
4
  export function buildPayload({model, mode, question, context = '', options = '', image}) {
5
+ if (!MODELS.includes(model) || !['predicate', 'choice', 'score', 'bbox'].includes(mode)) throw new Error('model');
6
  question = question.trim(); context = context.trim();
7
  if (!question || question.length > 1000) throw new Error('question');
8
  if (context.length > 4000) throw new Error('context');
9
  const q = {name: 'q0', type: mode, instructions: question};
10
+ if (mode === 'bbox') {if (!image) throw new Error('needImage'); q.image = 0;}
11
+ else if (mode !== 'predicate') {
12
  const lines = options.split('\n').map(s => s.trim()).filter(Boolean);
13
  if (lines.length < 2 || lines.length > 8 || lines.some(s => s.length > 300)) throw new Error('options');
14
  if (mode === 'choice') q.choices = lines.map((description, i) => ({value: `option_${i+1}`, description}));
 
111
  const a = data.answers[0];
112
  const probability = value => typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 1;
113
  if (!a || a.name !== 'q0' || a.type !== q.type || (a.confidence !== undefined && !probability(a.confidence))) fail();
114
+ if (q.type === 'bbox') {
115
+ if (!Array.isArray(a.bbox) || a.bbox.length !== 4 || !a.bbox.every(probability) || a.bbox[0] >= a.bbox[2] || a.bbox[1] >= a.bbox[3]) fail();
116
+ if (!Array.isArray(a.point) || a.point.length !== 2 || !a.point.every(probability)) fail();
117
+ return {title: 'located', confidence: a.confidence, rows: [], bbox: a.bbox, point: a.point};
118
+ }
119
  if (q.type === 'predicate') {
120
  if (!probability(a.probability)) fail();
121
  return {title: a.probability >= .5 ? 'yes' : 'no', confidence: a.confidence,
app.mjs CHANGED
@@ -3,7 +3,7 @@ import {words, examples, exampleMedia, ratingOptions} from './locales.mjs';
3
  import {readMedia} from './media.mjs';
4
  const $ = id => document.getElementById(id);
5
  let language = new URL(location.href).searchParams.get('lang') === 'zh' ? 'zh' : 'en';
6
- let imageData, attachment, mediaController, mediaRequired = false, controller, resultData, requestPayload, lastError, state = 'ready', statusKey = '';
7
  const t = key => words[language][key] || key;
8
 
9
  function renderLanguage() {
@@ -17,7 +17,8 @@ function renderLanguage() {
17
  if (resultData) renderAnswer(resultData.answer, resultData.data, requestPayload);
18
  }
19
  function configureOptions() {
20
- $('options-field').hidden = $('mode').value === 'predicate';
 
21
  $('options-label').textContent = t($('mode').value === 'score' ? 'levelsLabel' : 'choicesLabel');
22
  }
23
  function renderState() {
@@ -55,7 +56,13 @@ function updatePreview(report = false) {
55
  function renderAnswer(answer, data, payload) {
56
  $('empty').hidden = true;$('answer').hidden = false;
57
  const isPredicate = payload.questions[0].type === 'predicate';
58
- $('decision-title').textContent = isPredicate ? t(answer.title) : answer.title;
 
 
 
 
 
 
59
  $('probabilities').replaceChildren();
60
  for (const row of answer.rows) {
61
  const label = isPredicate ? t(row.label) : row.label;
@@ -110,7 +117,7 @@ $('image').addEventListener('change',()=>{
110
  $('decision-form').addEventListener('submit', async event => {
111
  event.preventDefault();if(controller||mediaController)return;
112
  clearResult();const payload=updatePreview(true);if(!payload)return;
113
- requestPayload=payload;controller=new AbortController();const active=controller;
114
  const timeout=setTimeout(()=>active.abort('timeout'),120000);
115
  lock(true);$('cancel').hidden=false;state='busy';statusKey='waiting';renderState();
116
  try {
 
3
  import {readMedia} from './media.mjs';
4
  const $ = id => document.getElementById(id);
5
  let language = new URL(location.href).searchParams.get('lang') === 'zh' ? 'zh' : 'en';
6
+ let imageData, requestImage, attachment, mediaController, mediaRequired = false, controller, resultData, requestPayload, lastError, state = 'ready', statusKey = '';
7
  const t = key => words[language][key] || key;
8
 
9
  function renderLanguage() {
 
17
  if (resultData) renderAnswer(resultData.answer, resultData.data, requestPayload);
18
  }
19
  function configureOptions() {
20
+ $('options-field').hidden = ['predicate','bbox'].includes($('mode').value);
21
+ $('question').placeholder = t($('mode').value === 'bbox' ? 'locatePlaceholder' : 'questionPlaceholder');
22
  $('options-label').textContent = t($('mode').value === 'score' ? 'levelsLabel' : 'choicesLabel');
23
  }
24
  function renderState() {
 
56
  function renderAnswer(answer, data, payload) {
57
  $('empty').hidden = true;$('answer').hidden = false;
58
  const isPredicate = payload.questions[0].type === 'predicate';
59
+ $('decision-title').textContent = isPredicate || answer.bbox ? t(answer.title) : answer.title;
60
+ $('bbox-figure').hidden = !answer.bbox;
61
+ if (answer.bbox) {
62
+ const [x1, y1, x2, y2] = answer.bbox;
63
+ $('bbox-image').src = requestImage;$('bbox-image').alt = payload.questions[0].instructions;
64
+ Object.assign($('bbox-box').style, {left:`${x1*100}%`, top:`${y1*100}%`, width:`${(x2-x1)*100}%`, height:`${(y2-y1)*100}%`});
65
+ }
66
  $('probabilities').replaceChildren();
67
  for (const row of answer.rows) {
68
  const label = isPredicate ? t(row.label) : row.label;
 
117
  $('decision-form').addEventListener('submit', async event => {
118
  event.preventDefault();if(controller||mediaController)return;
119
  clearResult();const payload=updatePreview(true);if(!payload)return;
120
+ requestPayload=payload;requestImage=imageData;controller=new AbortController();const active=controller;
121
  const timeout=setTimeout(()=>active.abort('timeout'),120000);
122
  lock(true);$('cancel').hidden=false;state='busy';statusKey='waiting';renderState();
123
  try {
cookbook/mug-counter.jpg ADDED

Git LFS Details

  • SHA256: 3579b23e87b4e1347d45ebc81bd54e2694e2c989d5755e7ba98bd1c1d26b09ad
  • Pointer size: 131 Bytes
  • Size of remote file: 158 kB
index.html CHANGED
@@ -3,7 +3,7 @@
3
  <head>
4
  <meta charset="utf-8">
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <meta name="description" content="Try Valen's free decision API with text, images and videos. Yes/no, choices, and ratings with ready-to-run Python examples.">
7
  <meta name="color-scheme" content="light dark">
8
  <title>Valen API</title>
9
  <link rel="icon" href="./assets/valen-mark.png">
@@ -13,11 +13,11 @@
13
  <body>
14
  <header class="nav"><a class="brand" href="https://valen-team.github.io/" target="_blank" rel="noreferrer"><img src="./assets/valen-mark.png" alt=""><strong>valen</strong><span>API</span></a><nav aria-label="Navigation"><a href="https://valen-team.github.io/docs/valen/api/" target="_blank" rel="noreferrer" data-i18n="docs">Documentation ↗</a><button id="language" type="button" aria-label="Switch language">中文</button><button id="theme" type="button" aria-label="Switch color theme">◐</button></nav></header>
15
  <main>
16
- <section class="intro"><span class="eyebrow" data-i18n="eyebrow">THE VALEN API PLAYGROUND</span><h1 data-i18n="title">A question. A clear decision.</h1><p data-i18n="subtitle">Ask a question about text, an image, or a video frame. Get structured decision probabilities.</p><div class="intro-meta"><span class="dot"></span><span data-i18n="free">Free API · No key needed</span><span class="divider">/</span><span data-i18n="formats">Yes / No · Choices · Rating</span></div></section>
17
  <div class="workspace">
18
  <section class="panel input-panel"><div class="panel-heading"><span class="step">01</span><h2 data-i18n="input">Your input</h2></div>
19
  <form id="decision-form"><fieldset id="fields">
20
- <div class="two-columns"><label><span data-i18n="model">Model</span><select id="model"><option value="valen-2b">Valen-Decision-1.5 2B</option><option value="valen-4b">Valen-Decision-1.5 4B</option><option value="valen-0.8b">Valen-Decision-1.5 0.8B</option></select></label><label><span data-i18n="task">Output</span><select id="mode"><option value="predicate" data-i18n="predicate">Yes / No</option><option value="choice" data-i18n="choice">Choices</option><option value="score" data-i18n="score">Rating</option></select></label></div>
21
  <label><span data-i18n="question">Question</span><textarea id="question" maxlength="1000" rows="2" required data-placeholder="questionPlaceholder" placeholder="What would you like Valen to decide?"></textarea></label>
22
  <label><span data-i18n="context">Context <small>optional</small></span><textarea id="context" maxlength="4000" rows="3" data-placeholder="contextPlaceholder" placeholder="Paste the text to assess, or add some context…"></textarea></label>
23
  <label id="options-field" hidden><span id="options-label">Choices · one per line</span><textarea id="options" rows="4" placeholder="Option A&#10;Option B"></textarea><small data-i18n="optionsHint">2–8 entries, up to 300 characters each.</small></label>
@@ -30,11 +30,11 @@
30
  <section class="panel output-panel"><div class="panel-heading"><span class="step">02</span><h2 data-i18n="result">Decision</h2><span id="state-badge" class="badge" data-state="ready">Ready</span></div>
31
  <div id="status" role="status" aria-live="polite"></div>
32
  <div id="empty"><div class="empty-mark">V</div><h3 data-i18n="emptyTitle">Small input. Useful signal.</h3><p data-i18n="emptyText">Your result and probability distribution will appear here.</p></div>
33
- <div id="answer" hidden><h3 id="decision-title"></h3><div id="probabilities"></div><p id="score-note" class="note" hidden data-i18n="scoreNote">Rating is the probability-weighted level index, starting at 0. Five levels span 0–4.</p><p id="confidence" class="note"></p><p id="model-id" class="model-id"></p><p class="decision-guidance" data-i18n="decisionGuidance">Model probabilities can help guide a decision. Choose thresholds and validate them on your own data.</p><details><summary data-i18n="raw">Response JSON</summary><pre id="response-json"></pre></details></div>
34
  <div class="api-note"><span class="mini-label">POST</span><code>/v1/decisions</code><p data-i18n="quota">Free capacity is limited. On HTTP 429, wait at least one minute before retrying.</p></div>
35
  </section>
36
  </div>
37
- <section class="examples"><div class="section-heading"><h2 data-i18n="examplesTitle">Start with a question</h2><span data-i18n="examplesNote">Loads an example. You choose when to send.</span></div><div class="example-grid"><button type="button" data-example="0"><span data-i18n="example0Tag">TEXT</span><strong data-i18n="example0Title">What does this customer need?</strong><p data-i18n="example0Text">Read a message and identify its intent.</p><i aria-hidden="true">↗</i></button><button type="button" data-example="1"><span data-i18n="example1Tag">IMAGE</span><img class="example-image" src="./cookbook/sheep.jpg" alt="" loading="lazy"><strong data-i18n="example1Title">What is this group called?</strong><p data-i18n="example1Text">Look at the animals and choose a name.</p><i aria-hidden="true">↗</i></button><button type="button" data-example="2"><span data-i18n="example2Tag">VIDEO</span><img class="example-image" src="./cookbook/momos-frame.jpg" alt="" loading="lazy"><strong data-i18n="example2Title">What color is the sauce?</strong><p data-i18n="example2Text">Decide from the middle frame of a video.</p><i aria-hidden="true">↗</i></button></div></section>
38
  <section class="explore" aria-labelledby="explore-title"><h2 id="explore-title" data-i18n="exploreTitle">Explore Valen</h2><p data-i18n="exploreText">Run the models locally, inspect evaluation results, or integrate the API into your application.</p><div class="explore-links"><a href="https://huggingface.co/Valen-Team" target="_blank" rel="noreferrer" data-i18n="exploreModels">Model weights ↗</a><a href="https://huggingface.co/spaces/Valen-Team/JevalKit-Leaderboard" target="_blank" rel="noreferrer" data-i18n="exploreLeaderboard">JevalKit Leaderboard ↗</a><a href="https://github.com/Valen-Team/Valen" target="_blank" rel="noreferrer">GitHub ↗</a><a href="https://valen-team.github.io/docs/" target="_blank" rel="noreferrer" data-i18n="exploreDocs">Documentation ↗</a></div></section>
39
  <section class="code-section"><details id="code-details"><summary><span data-i18n="codeTitle">Make it your own · API example</span><span class="code-tag">PYTHON</span></summary><p data-i18n="codeNote">Code follows your current input. Generating a preview does not call the API.</p><div class="code-actions"><button id="preview-code" type="button" data-i18n="preview">Update preview</button><button id="copy-code" type="button" data-i18n="copy">Copy Python</button><button id="copy-curl" type="button" data-i18n="copyCurl">Copy cURL</button><span id="copy-status" role="status"></span></div><pre><code id="python-code"></code></pre><details><summary data-i18n="requestPreview">Request JSON · image data omitted</summary><pre id="request-json"></pre></details></details></section>
40
  <footer><span>© 2026 Valen Team / 万澜</span><p data-i18n="network">Your browser connects directly to api.valen-team.workers.dev. This Space uses the same API as the website.</p><a href="https://huggingface.co/spaces/Valen-Team/Valen-API/tree/main" target="_blank" rel="noreferrer" data-i18n="source">View source ↗</a></footer>
 
3
  <head>
4
  <meta charset="utf-8">
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <meta name="description" content="Try Valen's free decision API with text, images and videos. Yes/no, choices, ratings, and bounding boxes with ready-to-run Python examples.">
7
  <meta name="color-scheme" content="light dark">
8
  <title>Valen API</title>
9
  <link rel="icon" href="./assets/valen-mark.png">
 
13
  <body>
14
  <header class="nav"><a class="brand" href="https://valen-team.github.io/" target="_blank" rel="noreferrer"><img src="./assets/valen-mark.png" alt=""><strong>valen</strong><span>API</span></a><nav aria-label="Navigation"><a href="https://valen-team.github.io/docs/valen/api/" target="_blank" rel="noreferrer" data-i18n="docs">Documentation ↗</a><button id="language" type="button" aria-label="Switch language">中文</button><button id="theme" type="button" aria-label="Switch color theme">◐</button></nav></header>
15
  <main>
16
+ <section class="intro"><span class="eyebrow" data-i18n="eyebrow">THE VALEN API PLAYGROUND</span><h1 data-i18n="title">A question. A clear decision.</h1><p data-i18n="subtitle">Ask a question about text, an image, or a video frame. Get structured decision probabilities, or a box around what you describe.</p><div class="intro-meta"><span class="dot"></span><span data-i18n="free">Free API · No key needed</span><span class="divider">/</span><span data-i18n="formats">Yes / No · Choices · Rating · Locate</span></div></section>
17
  <div class="workspace">
18
  <section class="panel input-panel"><div class="panel-heading"><span class="step">01</span><h2 data-i18n="input">Your input</h2></div>
19
  <form id="decision-form"><fieldset id="fields">
20
+ <div class="two-columns"><label><span data-i18n="model">Model</span><select id="model"><option value="valen-2b">Valen-Decision-1.5 2B</option><option value="valen-4b">Valen-Decision-1.5 4B</option><option value="valen-0.8b">Valen-Decision-1.5 0.8B</option></select></label><label><span data-i18n="task">Output</span><select id="mode"><option value="predicate" data-i18n="predicate">Yes / No</option><option value="choice" data-i18n="choice">Choices</option><option value="score" data-i18n="score">Rating</option><option value="bbox" data-i18n="bbox">Locate</option></select></label></div>
21
  <label><span data-i18n="question">Question</span><textarea id="question" maxlength="1000" rows="2" required data-placeholder="questionPlaceholder" placeholder="What would you like Valen to decide?"></textarea></label>
22
  <label><span data-i18n="context">Context <small>optional</small></span><textarea id="context" maxlength="4000" rows="3" data-placeholder="contextPlaceholder" placeholder="Paste the text to assess, or add some context…"></textarea></label>
23
  <label id="options-field" hidden><span id="options-label">Choices · one per line</span><textarea id="options" rows="4" placeholder="Option A&#10;Option B"></textarea><small data-i18n="optionsHint">2–8 entries, up to 300 characters each.</small></label>
 
30
  <section class="panel output-panel"><div class="panel-heading"><span class="step">02</span><h2 data-i18n="result">Decision</h2><span id="state-badge" class="badge" data-state="ready">Ready</span></div>
31
  <div id="status" role="status" aria-live="polite"></div>
32
  <div id="empty"><div class="empty-mark">V</div><h3 data-i18n="emptyTitle">Small input. Useful signal.</h3><p data-i18n="emptyText">Your result and probability distribution will appear here.</p></div>
33
+ <div id="answer" hidden><h3 id="decision-title"></h3><div id="bbox-figure" class="bbox-figure" hidden><img id="bbox-image" alt=""><span id="bbox-box"></span></div><div id="probabilities"></div><p id="score-note" class="note" hidden data-i18n="scoreNote">Rating is the probability-weighted level index, starting at 0. Five levels span 0–4.</p><p id="confidence" class="note"></p><p id="model-id" class="model-id"></p><p class="decision-guidance" data-i18n="decisionGuidance">Model probabilities can help guide a decision. Choose thresholds and validate them on your own data.</p><details><summary data-i18n="raw">Response JSON</summary><pre id="response-json"></pre></details></div>
34
  <div class="api-note"><span class="mini-label">POST</span><code>/v1/decisions</code><p data-i18n="quota">Free capacity is limited. On HTTP 429, wait at least one minute before retrying.</p></div>
35
  </section>
36
  </div>
37
+ <section class="examples"><div class="section-heading"><h2 data-i18n="examplesTitle">Start with a question</h2><span data-i18n="examplesNote">Loads an example. You choose when to send.</span></div><div class="example-grid"><button type="button" data-example="0"><span data-i18n="example0Tag">LOCATE</span><img class="example-image" src="./cookbook/mug-counter.jpg" alt="" loading="lazy"><strong data-i18n="example0Title">Where is the blue mug?</strong><p data-i18n="example0Text">Draw a box around what you describe.</p><i aria-hidden="true">↗</i></button><button type="button" data-example="1"><span data-i18n="example1Tag">TEXT</span><strong data-i18n="example1Title">What does this customer need?</strong><p data-i18n="example1Text">Read a message and identify its intent.</p><i aria-hidden="true">↗</i></button><button type="button" data-example="2"><span data-i18n="example2Tag">IMAGE</span><img class="example-image" src="./cookbook/sheep.jpg" alt="" loading="lazy"><strong data-i18n="example2Title">What is this group called?</strong><p data-i18n="example2Text">Look at the animals and choose a name.</p><i aria-hidden="true">↗</i></button><button type="button" data-example="3"><span data-i18n="example3Tag">VIDEO</span><img class="example-image" src="./cookbook/momos-frame.jpg" alt="" loading="lazy"><strong data-i18n="example3Title">What color is the sauce?</strong><p data-i18n="example3Text">Decide from the middle frame of a video.</p><i aria-hidden="true">↗</i></button></div></section>
38
  <section class="explore" aria-labelledby="explore-title"><h2 id="explore-title" data-i18n="exploreTitle">Explore Valen</h2><p data-i18n="exploreText">Run the models locally, inspect evaluation results, or integrate the API into your application.</p><div class="explore-links"><a href="https://huggingface.co/Valen-Team" target="_blank" rel="noreferrer" data-i18n="exploreModels">Model weights ↗</a><a href="https://huggingface.co/spaces/Valen-Team/JevalKit-Leaderboard" target="_blank" rel="noreferrer" data-i18n="exploreLeaderboard">JevalKit Leaderboard ↗</a><a href="https://github.com/Valen-Team/Valen" target="_blank" rel="noreferrer">GitHub ↗</a><a href="https://valen-team.github.io/docs/" target="_blank" rel="noreferrer" data-i18n="exploreDocs">Documentation ↗</a></div></section>
39
  <section class="code-section"><details id="code-details"><summary><span data-i18n="codeTitle">Make it your own · API example</span><span class="code-tag">PYTHON</span></summary><p data-i18n="codeNote">Code follows your current input. Generating a preview does not call the API.</p><div class="code-actions"><button id="preview-code" type="button" data-i18n="preview">Update preview</button><button id="copy-code" type="button" data-i18n="copy">Copy Python</button><button id="copy-curl" type="button" data-i18n="copyCurl">Copy cURL</button><span id="copy-status" role="status"></span></div><pre><code id="python-code"></code></pre><details><summary data-i18n="requestPreview">Request JSON · image data omitted</summary><pre id="request-json"></pre></details></details></section>
40
  <footer><span>© 2026 Valen Team / 万澜</span><p data-i18n="network">Your browser connects directly to api.valen-team.workers.dev. This Space uses the same API as the website.</p><a href="https://huggingface.co/spaces/Valen-Team/Valen-API/tree/main" target="_blank" rel="noreferrer" data-i18n="source">View source ↗</a></footer>
locales.mjs CHANGED
@@ -1,26 +1,29 @@
1
  export const words = {
2
  en: {
3
- exploreTitle:'Explore Valen',exploreText:'Run the models locally, inspect evaluation results, or integrate the API into your application.',exploreModels:'Model weights ↗',exploreLeaderboard:'JevalKit Leaderboard ↗',exploreDocs:'Documentation ↗',decisionGuidance:'Model probabilities can help guide a decision. Choose thresholds and validate them on your own data.',docs:'Documentation ↗', eyebrow:'THE VALEN API PLAYGROUND', title:'A question. A clear decision.', subtitle:'Ask a question about text, an image, or a video frame. Get structured decision probabilities.', free:'Free API · No key needed', formats:'Yes / No · Choices · Rating', input:'Your input', model:'Model', task:'Output', predicate:'Yes / No', choice:'Choices', score:'Rating', question:'Question', context:'Context · optional', questionPlaceholder:'What would you like Valen to decide?', contextPlaceholder:'Paste the text to assess, or add some context…', choicesLabel:'Choices · one per line', levelsLabel:'Rating levels · low to high, one per line', optionsHint:'2–8 entries, up to 300 characters each.', attach:'Add an image or video', imageHint:'Images up to 3 MB · MP4 / WebM up to 20 MB', remove:'Remove', submit:'Ask Valen', cancel:'Cancel request', privacy:'On submit, your input is sent directly to the Valen API.', result:'Decision', emptyTitle:'Small input. Useful signal.', emptyText:'Your result and probability distribution will appear here.', scoreNote:'Rating is the probability-weighted level index, starting at 0. Five levels span 0–4.', raw:'Response JSON', quota:'Free capacity is limited. On HTTP 429, wait at least one minute before retrying.', examplesTitle:'Start with a question', examplesNote:'Loads an example. You choose when to send.', example0Tag:'TEXT', example0Title:'What does this customer need?', example0Text:'Read a message and identify its intent.', example1Tag:'IMAGE', example1Title:'What is this group called?', example1Text:'Look at the animals and choose a name.', example2Tag:'VIDEO', example2Title:'What color is the sauce?', example2Text:'Decide from the middle frame of a video.', codeTitle:'Make it your own · API example', codeNote:'Code follows your current input. Generating a preview does not call the API.', preview:'Update preview', copy:'Copy Python', copyCurl:'Copy cURL', copied:'Copied', copyFailed:'Select the code and copy it manually.', requestPreview:'Request JSON · image data omitted', network:'Your browser connects directly to api.valen-team.workers.dev. This Space uses the same API as the website.', source:'View source ↗', ready:'Ready', busy:'Deciding…', success:'Complete', error:'Try again', reading:'Reading attachment…',videoNote:'Only a JPEG of the middle frame is sent. A single frame cannot establish motion or event order.', cancelled:'Request cancelled.', waiting:'Valen is deciding…', yes:'Yes', no:'No', confidence:'Confidence', modelId:'Returned model ID', noCode:'Enter a valid question and options to generate your API example.',
4
- errors:{model:'Choose a supported model and output type.',question:'Enter a question (up to 1000 characters).',context:'Context can be up to 4000 characters.',options:'Enter 2–8 options, one per line, up to 300 characters each.',image:'Could not read the attachment. Choose JPG, PNG, WebP, or a browser-playable MP4 / WebM.',size:'Images can be up to 3 MB; videos up to 20 MB.',response:'The API returned an unexpected response. Please retry later.',network:'Could not connect to the API. Check your network or proxy and try again.',timeout:'The request timed out after two minutes. Please retry later.',http_400:'HTTP 400 · The API rejected this request. Check the question and options.',http_401:'HTTP 401 · API authentication failed.',http_403:'HTTP 403 · This website is not allowed to call the API.',http_413:'HTTP 413 · The request is too large.',http_429:'HTTP 429 · Free API capacity is limited. Wait at least one minute before retrying.',http_502:'HTTP 502 · The model service could not complete the request.',http_503:'HTTP 503 · The API is not configured or is unavailable.'}
5
  },
6
  zh: {
7
- exploreTitle:'探索 Valen',exploreText:'本地运行模型、查看评测结果,或将 API 接入你的应用。',exploreModels:'模型权重 ↗',exploreLeaderboard:'评测排行榜 ↗',exploreDocs:'开发者文档 ↗',decisionGuidance:'模型概率可以辅助决策;请在自己的数据上验证并选择合适的阈值。',docs:'开发者文档 ↗',eyebrow:'VALEN API 体验',title:'一个问题,一次清晰判断。',subtitle:'根据文字、图片或视频画面提问,获取结构化决策概率。',free:'免费 API · 无需 Key',formats:'是 / 否 · 选择 · 评分',input:'你的输入',model:'模型',task:'输出类型',predicate:'是 / 否',choice:'选择答案',score:'评分',question:'问题',context:'补充背景 · 可选',questionPlaceholder:'你想让 Valen 判断什么?',contextPlaceholder:'粘贴需要判断的文字,或补充相关信息…',choicesLabel:'候选项 · 每行一个',levelsLabel:'评分档位 · 从低到高,每行一个',optionsHint:'2–8 项,每项最多 300 字符。',attach:'添加图片或视频',imageHint:'图片最大 3 MB · MP4 / WebM 视频最大 20 MB',remove:'移除',submit:'提交判断',cancel:'取消请求',privacy:'提交后,你的输入会直接发送至 Valen API。',result:'判断结果',emptyTitle:'简单输入,清晰信号。',emptyText:'判断结果与各个选项的概率将在这里显示。',scoreNote:'评分按从 0 开始的档位索引进行概率加权。五个档位对应 0–4 分。',raw:'原始响应 JSON',quota:'免费 API 容量有限。遇到 HTTP 429,请至少等待一分钟后重���。',examplesTitle:'从一个问题开始',examplesNote:'点击填入示例,提交时才会请求模型。',example0Tag:'纯文本',example0Title:'这位客户想做什么?',example0Text:'读一段客户消息,判断它表达的意图。',example1Tag:'图片',example1Title:'这群动物应该怎样称呼?',example1Text:'看一张动物图片,选择正确的群体名称。',example2Tag:'视频',example2Title:'左边的酱料是什么颜色?',example2Text:'提取视频中间帧,根据可见画面判断。',codeTitle:'接入你的应用 · API 示例',codeNote:'代码根据当前输入生成。生成预览不会调用 API。',preview:'更新预览',copy:'复制 Python',copyCurl:'复制 cURL',copied:'已复制',copyFailed:'请选中代码后手动复制。',requestPreview:'请求 JSON · 已省略图片数据',network:'浏览器直接连接 api.valen-team.workers.dev。此 Space 与官网共用同一个 API。',source:'查看源码 ↗',ready:'等待提问',busy:'正在判断…',success:'已完成',error:'请求未完成',reading:'正在读取附件…',videoNote:'只发送视频中间帧的 JPEG 图片。单帧无法判断运动或事件顺序。',cancelled:'请求已取消。',waiting:'Valen 正在判断…',yes:'是',no:'否',confidence:'置信度',modelId:'返回的模型标识',noCode:'填写有效的问题与选项后,即可生成对应的 API 示例。',
8
- errors:{model:'请选择支持的模型与输出类型。',question:'请填写问题,最多 1000 字符。',context:'补充背景最多 4000 字符。',options:'请输入 2–8 项,每行一个,每项最多 300 字符。',image:'无法读取附件。请选择 JPG、PNG、WebP,或浏览器可播放的 MP4 / WebM。',size:'图片最大 3 MB,视频最大 20 MB。',response:'API 返回的格式异常,请稍后重试。',network:'无法连接 API,请检查当前网络或代理后重试。',timeout:'请求等待超过两分钟,请稍后重试。',http_400:'HTTP 400 · API 拒绝了请求,请检查问题与选项。',http_401:'HTTP 401 · API 鉴权失败。',http_403:'HTTP 403 · 当前网站尚未获准调用 API。',http_413:'HTTP 413 · 请求体积超出限制。',http_429:'HTTP 429 · 免费 API 额度受限,请至少等待一分钟后重试。',http_502:'HTTP 502 · 模型服务暂时无法完成请求。',http_503:'HTTP 503 · API 尚未配置或暂不可用。'}
9
  }
10
  };
11
  export const examples = {
12
  en: [
 
13
  ['choice', "Which intent does the user's message express?", 'I moved. Can you ship my order to 12 Elm Street instead of the old address?', 'Asks about a charge, invoice or payment\nWants to cancel an order\nWants to change the delivery address\nReceived an item that is broken or damaged\nWants to know where an order is or when it arrives'],
14
  ['choice', 'What is a group of these animals called?', 'Answer using only the visible image.', 'pride\nflock\nclowder\ngang'],
15
  ['choice', 'What is the color of the sauce in the foil container on the left?', 'Answer using only the visible image.', 'Brown\nWhite\nRed\nOrange']
16
  ],
17
  zh: [
 
18
  ['choice', '这条客户消息表达了什么意图?', '我搬家了,可以把订单寄到榆树街 12 号,而不是原来的地址吗?', '咨询费用、发票或付款\n取消订单\n更改收货地址\n反馈收到的商品破损\n查询订单位置或预计送达时间'],
19
  ['choice', '图片中的这群动物应该怎样称呼?', '请仅根据图片中可见的内容回答问题。', '狮群\n羊群\n猫群\n猴群'],
20
  ['choice', '左边铝箔容器里的酱料是什么颜色?', '请仅根据视频画面中可见的内容回答问题。', '棕色\n白色\n红色\n橙色']
21
  ]
22
  };
23
  export const exampleMedia = [
 
24
  null,
25
  {kind:'image',src:'./cookbook/sheep.jpg',name:'sheep.jpg'},
26
  {kind:'video',src:'./cookbook/momos.mp4',name:'momos.mp4'}
 
1
  export const words = {
2
  en: {
3
+ exploreTitle:'Explore Valen',exploreText:'Run the models locally, inspect evaluation results, or integrate the API into your application.',exploreModels:'Model weights ↗',exploreLeaderboard:'JevalKit Leaderboard ↗',exploreDocs:'Documentation ↗',decisionGuidance:'Model probabilities can help guide a decision. Choose thresholds and validate them on your own data.',docs:'Documentation ↗', eyebrow:'THE VALEN API PLAYGROUND', title:'A question. A clear decision.', subtitle:'Ask a question about text, an image, or a video frame. Get structured decision probabilities, or a box around what you describe.', free:'Free API · No key needed', formats:'Yes / No · Choices · Rating · Locate', input:'Your input', model:'Model', task:'Output', predicate:'Yes / No', choice:'Choices', score:'Rating', bbox:'Locate', located:'Located', locatePlaceholder:'Describe what to locate in the image…', question:'Question', context:'Context · optional', questionPlaceholder:'What would you like Valen to decide?', contextPlaceholder:'Paste the text to assess, or add some context…', choicesLabel:'Choices · one per line', levelsLabel:'Rating levels · low to high, one per line', optionsHint:'2–8 entries, up to 300 characters each.', attach:'Add an image or video', imageHint:'Images up to 3 MB · MP4 / WebM up to 20 MB', remove:'Remove', submit:'Ask Valen', cancel:'Cancel request', privacy:'On submit, your input is sent directly to the Valen API.', result:'Decision', emptyTitle:'Small input. Useful signal.', emptyText:'Your result and probability distribution will appear here.', scoreNote:'Rating is the probability-weighted level index, starting at 0. Five levels span 0–4.', raw:'Response JSON', quota:'Free capacity is limited. On HTTP 429, wait at least one minute before retrying.', examplesTitle:'Start with a question', examplesNote:'Loads an example. You choose when to send.', example0Tag:'LOCATE', example0Title:'Where is the blue mug?', example0Text:'Draw a box around what you describe.', example1Tag:'TEXT', example1Title:'What does this customer need?', example1Text:'Read a message and identify its intent.', example2Tag:'IMAGE', example2Title:'What is this group called?', example2Text:'Look at the animals and choose a name.', example3Tag:'VIDEO', example3Title:'What color is the sauce?', example3Text:'Decide from the middle frame of a video.', codeTitle:'Make it your own · API example', codeNote:'Code follows your current input. Generating a preview does not call the API.', preview:'Update preview', copy:'Copy Python', copyCurl:'Copy cURL', copied:'Copied', copyFailed:'Select the code and copy it manually.', requestPreview:'Request JSON · image data omitted', network:'Your browser connects directly to api.valen-team.workers.dev. This Space uses the same API as the website.', source:'View source ↗', ready:'Ready', busy:'Deciding…', success:'Complete', error:'Try again', reading:'Reading attachment…',videoNote:'Only a JPEG of the middle frame is sent. A single frame cannot establish motion or event order.', cancelled:'Request cancelled.', waiting:'Valen is deciding…', yes:'Yes', no:'No', confidence:'Confidence', modelId:'Returned model ID', noCode:'Enter a valid question and options to generate your API example.',
4
+ errors:{model:'Choose a supported model and output type.',needImage:'Locate needs an image. Add an image or video first.',question:'Enter a question (up to 1000 characters).',context:'Context can be up to 4000 characters.',options:'Enter 2–8 options, one per line, up to 300 characters each.',image:'Could not read the attachment. Choose JPG, PNG, WebP, or a browser-playable MP4 / WebM.',size:'Images can be up to 3 MB; videos up to 20 MB.',response:'The API returned an unexpected response. Please retry later.',network:'Could not connect to the API. Check your network or proxy and try again.',timeout:'The request timed out after two minutes. Please retry later.',http_400:'HTTP 400 · The API rejected this request. Check the question and options.',http_401:'HTTP 401 · API authentication failed.',http_403:'HTTP 403 · This website is not allowed to call the API.',http_413:'HTTP 413 · The request is too large.',http_429:'HTTP 429 · Free API capacity is limited. Wait at least one minute before retrying.',http_502:'HTTP 502 · The model service could not complete the request.',http_503:'HTTP 503 · The API is not configured or is unavailable.'}
5
  },
6
  zh: {
7
+ exploreTitle:'探索 Valen',exploreText:'本地运行模型、查看评测结果,或将 API 接入你的应用。',exploreModels:'模型权重 ↗',exploreLeaderboard:'评测排行榜 ↗',exploreDocs:'开发者文档 ↗',decisionGuidance:'模型概率可以辅助决策;请在自己的数据上验证并选择合适的阈值。',docs:'开发者文档 ↗',eyebrow:'VALEN API 体验',title:'一个问题,一次清晰判断。',subtitle:'根据文字、图片或视频画面提问,获取结构化决策概率,或在图片中框出描述的目标。',free:'免费 API · 无需 Key',formats:'是 / 否 · 选择 · 评分 · 定位',input:'你的输入',model:'模型',task:'输出类型',predicate:'是 / 否',choice:'选择答案',score:'评分',bbox:'定位',located:'已定位',locatePlaceholder:'描述要在图片中定位的目标…',question:'问题',context:'补充背景 · 可选',questionPlaceholder:'你想让 Valen 判断什么?',contextPlaceholder:'粘贴需要判断的文字,或补充相关信息…',choicesLabel:'候选项 · 每行一个',levelsLabel:'评分档位 · 从低到高,每行一个',optionsHint:'2–8 项,每项最多 300 字符。',attach:'添加图片或视频',imageHint:'图片最大 3 MB · MP4 / WebM 视频最大 20 MB',remove:'移除',submit:'提交判断',cancel:'取消请求',privacy:'提交后,你的输入会直接发送至 Valen API。',result:'判断结果',emptyTitle:'简单输入,清晰信号。',emptyText:'判断结果与各个选项的概率将在这里显示。',scoreNote:'评分按从 0 开始的档位索引进行概率加权。五个档位对应 0–4 分。',raw:'原始响应 JSON',quota:'免费 API 容量有限。遇到 HTTP 429,请至少等待一分钟后重试。',examplesTitle:'从一个问题开始',examplesNote:'点击填入示例,提交时才会请求模型。',example0Tag:'定位',example0Title:'蓝色马克杯在哪里?',example0Text:'在图片中框出你描述的目标。',example1Tag:'纯文本',example1Title:'这位客户想做什么?',example1Text:'读一段客户消息,判断它表达的意图。',example2Tag:'图片',example2Title:'这群动物应该怎样称呼?',example2Text:'看一张动物图片,选择正确的群体名称。',example3Tag:'视频',example3Title:'左边的酱料是什么颜色?',example3Text:'提取视频中间帧,根据可见画面判断。',codeTitle:'接入你的应用 · API 示例',codeNote:'代码根据当前输入生成。生成预览不会调用 API。',preview:'更新预览',copy:'复制 Python',copyCurl:'复制 cURL',copied:'已复制',copyFailed:'请选中代码后手动复制。',requestPreview:'请求 JSON · 已省略图片数据',network:'��览器直接连接 api.valen-team.workers.dev。此 Space 与官网共用同一个 API。',source:'查看源码 ↗',ready:'等待提问',busy:'正在判断…',success:'已完成',error:'请求未完成',reading:'正在读取附件…',videoNote:'只发送视频中间帧的 JPEG 图片。单帧无法判断运动或事件顺序。',cancelled:'请求已取消。',waiting:'Valen 正在判断…',yes:'是',no:'否',confidence:'置信度',modelId:'返回的模型标识',noCode:'填写有效的问题与选项后,即可生成对应的 API 示例。',
8
+ errors:{model:'请选择支持的模型与输出类型。',needImage:'定位需要一张图片,请先添加图片或视频。',question:'请填写问题,最多 1000 字符。',context:'补充背景最多 4000 字符。',options:'请输入 2–8 项,每行一个,每项最多 300 字符。',image:'无法读取附件。请选择 JPG、PNG、WebP,或浏览器可播放的 MP4 / WebM。',size:'图片最大 3 MB,视频最大 20 MB。',response:'API 返回的格式异常,请稍后重试。',network:'无法连接 API,请检查当前网络或代理后重试。',timeout:'请求等待超过两分钟,请稍后重试。',http_400:'HTTP 400 · API 拒绝了请求,请检查问题与选项。',http_401:'HTTP 401 · API 鉴权失败。',http_403:'HTTP 403 · 当前网站尚未获准调用 API。',http_413:'HTTP 413 · 请求体积超出限制。',http_429:'HTTP 429 · 免费 API 额度受限,请至少等待一分钟后重试。',http_502:'HTTP 502 · 模型服务暂时无法完成请求。',http_503:'HTTP 503 · API 尚未配置或暂不可用。'}
9
  }
10
  };
11
  export const examples = {
12
  en: [
13
+ ['bbox', 'The blue mug.', '', ''],
14
  ['choice', "Which intent does the user's message express?", 'I moved. Can you ship my order to 12 Elm Street instead of the old address?', 'Asks about a charge, invoice or payment\nWants to cancel an order\nWants to change the delivery address\nReceived an item that is broken or damaged\nWants to know where an order is or when it arrives'],
15
  ['choice', 'What is a group of these animals called?', 'Answer using only the visible image.', 'pride\nflock\nclowder\ngang'],
16
  ['choice', 'What is the color of the sauce in the foil container on the left?', 'Answer using only the visible image.', 'Brown\nWhite\nRed\nOrange']
17
  ],
18
  zh: [
19
+ ['bbox', '蓝色的马克杯。', '', ''],
20
  ['choice', '这条客户消息表达了什么意图?', '我搬家了,可以把订单寄到榆树街 12 号,而不是原来的地址吗?', '咨询费用、发票或付款\n取消订单\n更改收货地址\n反馈收到的商品破损\n查询订单位置或预计送达时间'],
21
  ['choice', '图片中的这群动物应该怎样称呼?', '请仅根据图片中可见的内容回答问题。', '狮群\n羊群\n猫群\n猴群'],
22
  ['choice', '左边铝箔容器里的酱料是什么颜色?', '请仅根据视频画面中可见的内容回答问题。', '棕色\n白色\n红色\n橙色']
23
  ]
24
  };
25
  export const exampleMedia = [
26
+ {kind:'image',src:'./cookbook/mug-counter.jpg',name:'mug-counter.jpg'},
27
  null,
28
  {kind:'image',src:'./cookbook/sheep.jpg',name:'sheep.jpg'},
29
  {kind:'video',src:'./cookbook/momos.mp4',name:'momos.mp4'}
style.css CHANGED
@@ -5,3 +5,11 @@
5
  #video-preview{display:block;width:100%;max-height:240px;border-radius:8px;margin-top:12px;background:#000}.example-image{display:block;width:100%;height:110px;object-fit:cover;border-radius:7px;margin:0 0 12px}.example-grid button{align-self:stretch}.example-grid strong{display:block}#video-note{margin:10px 0 0;font-size:11px}
6
 
7
  .explore{margin:35px 0 0;padding:24px;border:1px solid var(--border);border-radius:12px;background:var(--surface)}.explore h2{font-size:16px;margin:0 0 8px;color:var(--heading)}.explore p{font-size:13px;line-height:1.7;color:var(--text-muted);margin:0 0 16px}.explore-links{display:flex;flex-wrap:wrap;gap:10px 22px}.explore-links a{font-size:12px;font-weight:600;color:var(--primary)}.decision-guidance{font-size:11px;line-height:1.6;color:var(--text-muted);margin:14px 0}
 
 
 
 
 
 
 
 
 
5
  #video-preview{display:block;width:100%;max-height:240px;border-radius:8px;margin-top:12px;background:#000}.example-image{display:block;width:100%;height:110px;object-fit:cover;border-radius:7px;margin:0 0 12px}.example-grid button{align-self:stretch}.example-grid strong{display:block}#video-note{margin:10px 0 0;font-size:11px}
6
 
7
  .explore{margin:35px 0 0;padding:24px;border:1px solid var(--border);border-radius:12px;background:var(--surface)}.explore h2{font-size:16px;margin:0 0 8px;color:var(--heading)}.explore p{font-size:13px;line-height:1.7;color:var(--text-muted);margin:0 0 16px}.explore-links{display:flex;flex-wrap:wrap;gap:10px 22px}.explore-links a{font-size:12px;font-weight:600;color:var(--primary)}.decision-guidance{font-size:11px;line-height:1.6;color:var(--text-muted);margin:14px 0}
8
+
9
+ .example-grid{grid-template-columns:repeat(4,1fr)}
10
+ @media(max-width:1000px){.example-grid{grid-template-columns:repeat(2,1fr)}}
11
+ @media(max-width:760px){.example-grid{grid-template-columns:1fr}}
12
+ .bbox-figure{position:relative;width:fit-content;max-width:100%;margin:-10px 0 18px;border:1px solid var(--border);border-radius:12px;overflow:hidden}
13
+ .bbox-figure[hidden]{display:none}
14
+ .bbox-figure img{display:block;max-width:100%;max-height:420px;height:auto}
15
+ .bbox-figure span{position:absolute;border:2px solid var(--primary);border-radius:5px;background:#3964fe1f;box-shadow:0 0 0 1px #ffffffb0}
tests/api.test.mjs CHANGED
@@ -56,7 +56,7 @@ test('both locales cover UI labels and all examples create valid payloads',()=>{
56
  const html=readFileSync(new URL('../index.html',import.meta.url),'utf8');
57
  for(const locale of ['en','zh']){
58
  for(const [,key] of html.matchAll(/data-(?:i18n|placeholder)="([^"]+)"/g))assert.equal(typeof words[locale][key],'string',`${locale}:${key}`);
59
- for(const [mode,question,context,options] of examples[locale])make({mode,question,context,options});
60
  }
61
  });
62
  test('generated cURL sends exactly the payload, including quotes and the image file',()=>{
@@ -67,3 +67,15 @@ test('generated cURL sends exactly the payload, including quotes and the image f
67
  const image=make({image:'data:image/jpeg;base64,Ymx1ZQ=='});
68
  assert.deepEqual(run(curlExample(image),dir),image);
69
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  const html=readFileSync(new URL('../index.html',import.meta.url),'utf8');
57
  for(const locale of ['en','zh']){
58
  for(const [,key] of html.matchAll(/data-(?:i18n|placeholder)="([^"]+)"/g))assert.equal(typeof words[locale][key],'string',`${locale}:${key}`);
59
+ for(const [mode,question,context,options] of examples[locale])make({mode,question,context,options,...(mode==='bbox'?{image:'data:image/jpeg;base64,AAAA'}:{})});
60
  }
61
  });
62
  test('generated cURL sends exactly the payload, including quotes and the image file',()=>{
 
67
  const image=make({image:'data:image/jpeg;base64,Ymx1ZQ=='});
68
  assert.deepEqual(run(curlExample(image),dir),image);
69
  });
70
+
71
+ test('bbox requests need an image, carry no candidates and return a box',()=>{
72
+ const image='data:image/jpeg;base64,AAAA';
73
+ const payload=make({mode:'bbox',question:'The blue mug.',context:'',options:'',image});
74
+ assert.deepEqual(payload.questions,[{name:'q0',type:'bbox',instructions:'The blue mug.',image:0}]);
75
+ assert.throws(()=>make({mode:'bbox',options:''}),/needImage/);
76
+ const raw={name:'q0',type:'bbox',bbox:[.25,.3,.8,.8],point:[.5,.55],confidence:.9};
77
+ const answer=parseAnswer({answers:[raw]},payload);
78
+ assert.deepEqual(answer.bbox,raw.bbox);assert.equal(answer.title,'located');
79
+ assert.throws(()=>parseAnswer({answers:[{...raw,bbox:[.8,.3,.25,.8]}]},payload));
80
+ assert.equal(examples.en[0][0],'bbox');assert.equal(examples.zh[0][0],'bbox');
81
+ });