|
| 1 | +/// /// <reference path="./types.d.ts" /> |
| 2 | + |
| 3 | +/* |
| 4 | +const modelUrl = 'https://huggingface.co/kalleby/hp-to-miles/resolve/main/model.onnx?download=true'; |
| 5 | +const modelConfigUrl = |
| 6 | + 'https://huggingface.co/kalleby/hp-to-miles/resolve/main/config.json?download=true'; |
| 7 | +
|
| 8 | +const model = await Supabase.ai.RawSession.fromUrl(modelUrl); |
| 9 | +const modelConfig = await fetch(modelConfigUrl).then((r) => r.json()); |
| 10 | +
|
| 11 | +Deno.serve(async (req: Request) => { |
| 12 | + const params = new URL(req.url).searchParams; |
| 13 | + const inputValue = parseInt(params.get('value')); |
| 14 | +
|
| 15 | + const input = new Supabase.ai.RawTensor('float32', [inputValue], [1, 1]); |
| 16 | + .minMaxNormalize(modelConfig.input.min, modelConfig.input.max); |
| 17 | +
|
| 18 | + const output = await model.run({ |
| 19 | + 'dense_dense1_input': input, |
| 20 | + }); |
| 21 | +
|
| 22 | + console.log('output', output); |
| 23 | +
|
| 24 | + const outputTensor = output['dense_Dense4'] |
| 25 | + .minMaxUnnormalize(modelConfig.label.min, modelConfig.label.max); |
| 26 | +
|
| 27 | + return Response.json({ result: outputTensor.data }); |
| 28 | +}); |
| 29 | +*/ |
| 30 | + |
| 31 | +// transformers.js Compatible: |
| 32 | +// import { Tensor } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]'; |
| 33 | +// const rawTensor = new Supabase.ai.RawTensor('string', urls, [urls.length]); |
| 34 | +// console.log('raw tensor', rawTensor ); |
| 35 | +// |
| 36 | +// const tensor = new Tensor(rawTensor); |
| 37 | +// console.log('hf tensor', tensor); |
| 38 | +// |
| 39 | +// 'hf tensor operations' |
| 40 | +// tensor.min(); tensor.max(); tensor.norm() .... |
| 41 | + |
| 42 | +// const modelUrl = |
| 43 | +// 'https://huggingface.co/pirocheto/phishing-url-detection/resolve/main/model.onnx?download=true'; |
| 44 | + |
| 45 | +/* |
| 46 | +const { Tensor, RawSession } = Supabase.ai; |
| 47 | +
|
| 48 | +const model = await RawSession.fromHuggingFace('pirocheto/phishing-url-detection', { |
| 49 | + path: { |
| 50 | + template: `{REPO_ID}/resolve/{REVISION}/{MODEL_FILE}?donwload=true`, |
| 51 | + modelFile: 'model.onnx', |
| 52 | + }, |
| 53 | +}); |
| 54 | +
|
| 55 | +console.log('session', model); |
| 56 | +
|
| 57 | +Deno.serve(async (_req: Request) => { |
| 58 | + const urls = [ |
| 59 | + 'https://clubedemilhagem.com/home.php', |
| 60 | + 'http://www.medicalnewstoday.com/articles/188939.php', |
| 61 | + 'https://magalu-crediarioluiza.com/Produto_20203/produto.php?sku=1', |
| 62 | + ]; |
| 63 | +
|
| 64 | + const inputs = new Tensor('string', urls, [urls.length]); |
| 65 | + console.log('tensor', inputs.data); |
| 66 | +
|
| 67 | + const output = await model.run({ inputs }); |
| 68 | + console.log(output); |
| 69 | +
|
| 70 | + return Response.json({ result: output.probabilities }); |
| 71 | +}); |
| 72 | +*/ |
| 73 | + |
1 | 74 | const { Tensor, RawSession } = Supabase.ai;
|
2 | 75 |
|
3 | 76 | const session = await RawSession.fromHuggingFace('kallebysantos/vehicle-emission', {
|
@@ -27,14 +100,15 @@ Deno.serve(async (_req: Request) => {
|
27 | 100 | }];
|
28 | 101 |
|
29 | 102 | // Parsing objects to tensor input
|
30 |
| - const inputTensors = {}; |
| 103 | + const inputTensors: Record<string, Supabase.Tensor<'float32'>> = {}; |
31 | 104 | session.inputs.forEach((inputKey) => {
|
32 | 105 | const values = carsBatchInput.map((item) => item[inputKey]);
|
33 | 106 |
|
34 | 107 | inputTensors[inputKey] = new Tensor('float32', values, [values.length, 1]);
|
35 | 108 | });
|
36 | 109 |
|
37 | 110 | const { emissions } = await session.run(inputTensors);
|
| 111 | + console.log(emissions); |
38 | 112 | // [ 289.01, 199.53]
|
39 | 113 |
|
40 | 114 | return Response.json({ result: emissions });
|
|
0 commit comments