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
import Pipeline from "https://esm.town/v/iamseeley/pipeline";
export default async function handler(req) {
if (req.method === "GET") {
return new Response(`
<!DOCTYPE html>
<html>
<body>
<h2>Feature Extraction</h2>
<form id="featureForm">
<label for="source_sentence">Source Sentence:</label><br>
<input type="text" id="source_sentence" name="source_sentence"><br><br>
<label for="sentences">Sentences (comma separated):</label><br>
<input type="text" id="sentences" name="sentences"><br><br>
<input type="submit" value="Extract Features">
</form>
<div id="result"></div>
<script>
document.getElementById('featureForm').addEventListener('submit', async (event) => {
event.preventDefault();
const source_sentence = document.getElementById('source_sentence').value;
const sentences = document.getElementById('sentences').value.split(',').map(sentence => sentence.trim());
const response = await fetch('/extract-features', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ inputs: { source_sentence, sentences } })
});
const data = await response.json();
document.getElementById('result').innerHTML = '<p>Original: ' + source_sentence + '</p><p>Features: ' + JSON.stringify(data) + '</p>';
});
</script>
</body>
</html>
`, { headers: { "Content-Type": "text/html" } });
} else if (req.method === "POST") {
const { inputs } = await req.json();
const pipeline = new Pipeline("feature-extraction", "sentence-transformers/all-MiniLM-L6-v2");
const result = await pipeline.run(inputs);
return new Response(JSON.stringify(result), { headers: { "Content-Type": "application/json" } });
}
}