Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- README.md +19 -8
- assets/index-BP17AIvh.js +0 -0
- assets/index-Co9424he.css +1 -0
- assets/ort-wasm-simd-threaded.jsep-B0T3yYHD.wasm +3 -0
- index.html +14 -26
- index.js +0 -76
- package.json +27 -0
- src/App.tsx +218 -0
- src/components/ChatMessage.tsx +129 -0
- src/components/LoadingScreen.tsx +199 -0
- src/hooks/useLLM.ts +179 -0
- src/index.css +1 -0
- src/main.tsx +10 -0
- src/vite-env.d.ts +1 -0
- style.css +0 -76
- tsconfig.app.json +23 -0
- tsconfig.json +7 -0
- tsconfig.node.json +21 -0
- vite.config.ts +7 -0
README.md
CHANGED
|
@@ -1,14 +1,25 @@
|
|
| 1 |
---
|
| 2 |
title: Maincoder 1B WebGPU
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
-
pinned:
|
| 8 |
-
app_build_command: npm run build
|
| 9 |
-
short_description: Maincoder-1B-WebGPU Demo
|
| 10 |
-
app_file: dist/index.html
|
| 11 |
license: apache-2.0
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: Maincoder 1B WebGPU
|
| 3 |
+
emoji: ⚡
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: static
|
| 7 |
+
pinned: false
|
|
|
|
|
|
|
|
|
|
| 8 |
license: apache-2.0
|
| 9 |
+
short_description: Maincoder 1B code generation in browser via WebGPU
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Maincoder 1B — In-Browser Code Generation
|
| 13 |
+
|
| 14 |
+
Run the [Maincoder 1B](https://huggingface.co/Maincode/Maincoder-1B) code generation model **entirely in your browser** using WebGPU — no server required.
|
| 15 |
+
|
| 16 |
+
**Requirements:** A browser with WebGPU support (Chrome 113+, Edge 113+).
|
| 17 |
+
|
| 18 |
+
Powered by [Transformers.js](https://huggingface.co/docs/transformers.js) and the [quantized ONNX model](https://huggingface.co/shreyask/Maincoder-1B-ONNX-web).
|
| 19 |
+
|
| 20 |
+
## Development
|
| 21 |
+
|
| 22 |
+
```bash
|
| 23 |
+
npm install
|
| 24 |
+
npm run dev
|
| 25 |
+
```
|
assets/index-BP17AIvh.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
assets/index-Co9424he.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-space-y-reverse:0;--tw-border-style:solid;--tw-gradient-position:initial;--tw-gradient-from:#0000;--tw-gradient-via:#0000;--tw-gradient-to:#0000;--tw-gradient-stops:initial;--tw-gradient-via-stops:initial;--tw-gradient-from-position:0%;--tw-gradient-via-position:50%;--tw-gradient-to-position:100%;--tw-leading:initial;--tw-font-weight:initial;--tw-tracking:initial;--tw-ordinal:initial;--tw-slashed-zero:initial;--tw-numeric-figure:initial;--tw-numeric-spacing:initial;--tw-numeric-fraction:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-outline-style:solid;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial;--tw-duration:initial;--tw-translate-x:0;--tw-translate-y:0;--tw-translate-z:0}}}@layer theme{:root,:host{--font-sans:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--color-red-300:oklch(80.8% .114 19.571);--color-red-500:oklch(63.7% .237 25.331);--color-red-900:oklch(39.6% .141 25.723);--color-emerald-300:oklch(84.5% .143 164.978);--color-emerald-400:oklch(76.5% .177 163.223);--color-emerald-500:oklch(69.6% .17 162.48);--color-emerald-600:oklch(59.6% .145 163.225);--color-gray-100:oklch(96.7% .003 264.542);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-300:oklch(87.2% .01 258.338);--color-gray-400:oklch(70.7% .022 261.325);--color-gray-500:oklch(55.1% .027 264.364);--color-white:#fff;--spacing:.25rem;--container-md:28rem;--container-lg:32rem;--container-2xl:42rem;--text-xs:.75rem;--text-xs--line-height:calc(1/.75);--text-sm:.875rem;--text-sm--line-height:calc(1.25/.875);--text-base:1rem;--text-base--line-height: 1.5 ;--text-lg:1.125rem;--text-lg--line-height:calc(1.75/1.125);--text-2xl:1.5rem;--text-2xl--line-height:calc(2/1.5);--text-3xl:1.875rem;--text-3xl--line-height: 1.2 ;--text-4xl:2.25rem;--text-4xl--line-height:calc(2.5/2.25);--text-5xl:3rem;--text-5xl--line-height:1;--text-6xl:3.75rem;--text-6xl--line-height:1;--font-weight-medium:500;--font-weight-semibold:600;--font-weight-bold:700;--tracking-tight:-.025em;--leading-relaxed:1.625;--radius-xl:.75rem;--radius-2xl:1rem;--radius-3xl:1.5rem;--animate-spin:spin 1s linear infinite;--blur-lg:16px;--blur-xl:24px;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4,0,.2,1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.collapse{visibility:collapse}.invisible{visibility:hidden}.visible{visibility:visible}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.static{position:static}.inset-0{inset:calc(var(--spacing)*0)}.top-0{top:calc(var(--spacing)*0)}.left-0{left:calc(var(--spacing)*0)}.isolate{isolation:isolate}.z-0{z-index:0}.z-10{z-index:10}.z-20{z-index:20}.container{width:100%}@media(min-width:40rem){.container{max-width:40rem}}@media(min-width:48rem){.container{max-width:48rem}}@media(min-width:64rem){.container{max-width:64rem}}@media(min-width:80rem){.container{max-width:80rem}}@media(min-width:96rem){.container{max-width:96rem}}.my-3{margin-block:calc(var(--spacing)*3)}.mt-3{margin-top:calc(var(--spacing)*3)}.mt-4{margin-top:calc(var(--spacing)*4)}.mr-2{margin-right:calc(var(--spacing)*2)}.mb-1{margin-bottom:calc(var(--spacing)*1)}.mb-4{margin-bottom:calc(var(--spacing)*4)}.mb-6{margin-bottom:calc(var(--spacing)*6)}.ml-3{margin-left:calc(var(--spacing)*3)}.block{display:block}.contents{display:contents}.flex{display:flex}.grid{display:grid}.hidden{display:none}.inline{display:inline}.inline-block{display:inline-block}.table{display:table}.size-10{width:calc(var(--spacing)*10);height:calc(var(--spacing)*10)}.h-2{height:calc(var(--spacing)*2)}.h-5{height:calc(var(--spacing)*5)}.h-10{height:calc(var(--spacing)*10)}.h-full{height:100%}.h-screen{height:100vh}.min-h-0{min-height:calc(var(--spacing)*0)}.min-h-screen{min-height:100vh}.w-5{width:calc(var(--spacing)*5)}.w-full{width:100%}.max-w-2xl{max-width:var(--container-2xl)}.max-w-lg{max-width:var(--container-lg)}.max-w-md{max-width:var(--container-md)}.flex-1{flex:1}.flex-shrink{flex-shrink:1}.flex-shrink-0{flex-shrink:0}.flex-grow,.grow{flex-grow:1}.border-collapse{border-collapse:collapse}.transform{transform:var(--tw-rotate-x,)var(--tw-rotate-y,)var(--tw-rotate-z,)var(--tw-skew-x,)var(--tw-skew-y,)}.animate-spin{animation:var(--animate-spin)}.cursor-not-allowed{cursor:not-allowed}.resize{resize:both}.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.justify-start{justify-content:flex-start}.gap-1\.5{gap:calc(var(--spacing)*1.5)}.gap-2{gap:calc(var(--spacing)*2)}.gap-3{gap:calc(var(--spacing)*3)}:where(.space-y-1>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*1)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*1)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*3)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*3)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*5)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*5)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-6>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*6)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*6)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-8>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*8)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*8)*calc(1 - var(--tw-space-y-reverse)))}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-hidden{overflow:hidden}.overflow-x-auto{overflow-x:auto}.overflow-y-auto{overflow-y:auto}.rounded-2xl{border-radius:var(--radius-2xl)}.rounded-3xl{border-radius:var(--radius-3xl)}.rounded-full{border-radius:3.40282e38px}.rounded-xl{border-radius:var(--radius-xl)}.border{border-style:var(--tw-border-style);border-width:1px}.border-2{border-style:var(--tw-border-style);border-width:2px}.border-b{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.border-emerald-400\/80{border-color:#00d294cc}@supports (color:color-mix(in lab,red,red)){.border-emerald-400\/80{border-color:color-mix(in oklab,var(--color-emerald-400)80%,transparent)}}.border-emerald-500\/20{border-color:#00bb7f33}@supports (color:color-mix(in lab,red,red)){.border-emerald-500\/20{border-color:color-mix(in oklab,var(--color-emerald-500)20%,transparent)}}.border-emerald-500\/30{border-color:#00bb7f4d}@supports (color:color-mix(in lab,red,red)){.border-emerald-500\/30{border-color:color-mix(in oklab,var(--color-emerald-500)30%,transparent)}}.border-emerald-500\/50{border-color:#00bb7f80}@supports (color:color-mix(in lab,red,red)){.border-emerald-500\/50{border-color:color-mix(in oklab,var(--color-emerald-500)50%,transparent)}}.border-red-500\/40{border-color:#fb2c3666}@supports (color:color-mix(in lab,red,red)){.border-red-500\/40{border-color:color-mix(in oklab,var(--color-red-500)40%,transparent)}}.border-white\/10{border-color:#ffffff1a}@supports (color:color-mix(in lab,red,red)){.border-white\/10{border-color:color-mix(in oklab,var(--color-white)10%,transparent)}}.border-white\/15{border-color:#ffffff26}@supports (color:color-mix(in lab,red,red)){.border-white\/15{border-color:color-mix(in oklab,var(--color-white)15%,transparent)}}.border-white\/20{border-color:#fff3}@supports (color:color-mix(in lab,red,red)){.border-white\/20{border-color:color-mix(in oklab,var(--color-white)20%,transparent)}}.border-t-transparent{border-top-color:#0000}.\!bg-\[\#0d1117\]{background-color:#0d1117!important}.bg-\[\#0d1117\]{background-color:#0d1117}.bg-\[\#080d16\]\/80{background-color:#080d16cc}.bg-emerald-500\/10{background-color:#00bb7f1a}@supports (color:color-mix(in lab,red,red)){.bg-emerald-500\/10{background-color:color-mix(in oklab,var(--color-emerald-500)10%,transparent)}}.bg-emerald-600{background-color:var(--color-emerald-600)}.bg-emerald-600\/20{background-color:#00976733}@supports (color:color-mix(in lab,red,red)){.bg-emerald-600\/20{background-color:color-mix(in oklab,var(--color-emerald-600)20%,transparent)}}.bg-red-900\/30{background-color:#82181a4d}@supports (color:color-mix(in lab,red,red)){.bg-red-900\/30{background-color:color-mix(in oklab,var(--color-red-900)30%,transparent)}}.bg-transparent{background-color:#0000}.bg-white\/5{background-color:#ffffff0d}@supports (color:color-mix(in lab,red,red)){.bg-white\/5{background-color:color-mix(in oklab,var(--color-white)5%,transparent)}}.bg-white\/8{background-color:#ffffff14}@supports (color:color-mix(in lab,red,red)){.bg-white\/8{background-color:color-mix(in oklab,var(--color-white)8%,transparent)}}.bg-white\/10{background-color:#ffffff1a}@supports (color:color-mix(in lab,red,red)){.bg-white\/10{background-color:color-mix(in oklab,var(--color-white)10%,transparent)}}.bg-white\/15{background-color:#ffffff26}@supports (color:color-mix(in lab,red,red)){.bg-white\/15{background-color:color-mix(in oklab,var(--color-white)15%,transparent)}}.bg-gradient-to-br{--tw-gradient-position:to bottom right in oklab;background-image:linear-gradient(var(--tw-gradient-stops))}.bg-gradient-to-r{--tw-gradient-position:to right in oklab;background-image:linear-gradient(var(--tw-gradient-stops))}.bg-\[radial-gradient\(ellipse_at_center\,_rgba\(10\,15\,26\,0\)_30\%\,_rgba\(6\,10\,18\,0\.9\)_95\%\)\]{background-image:radial-gradient(#0a0f1a00 30%,#060a12e6 95%)}.from-\[\#0a0f1a\]{--tw-gradient-from:#0a0f1a;--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-emerald-500{--tw-gradient-from:var(--color-emerald-500);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-emerald-500\/15{--tw-gradient-from:#00bb7f26}@supports (color:color-mix(in lab,red,red)){.from-emerald-500\/15{--tw-gradient-from:color-mix(in oklab,var(--color-emerald-500)15%,transparent)}}.from-emerald-500\/15{--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.via-\[\#0d1520\]{--tw-gradient-via:#0d1520;--tw-gradient-via-stops:var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-via)var(--tw-gradient-via-position),var(--tw-gradient-to)var(--tw-gradient-to-position);--tw-gradient-stops:var(--tw-gradient-via-stops)}.via-transparent{--tw-gradient-via:transparent;--tw-gradient-via-stops:var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-via)var(--tw-gradient-via-position),var(--tw-gradient-to)var(--tw-gradient-to-position);--tw-gradient-stops:var(--tw-gradient-via-stops)}.to-\[\#060a12\]{--tw-gradient-to:#060a12;--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.to-emerald-400{--tw-gradient-to:var(--color-emerald-400);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.to-transparent{--tw-gradient-to:transparent;--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.mask-repeat{-webkit-mask-repeat:repeat;mask-repeat:repeat}.p-4{padding:calc(var(--spacing)*4)}.p-6{padding:calc(var(--spacing)*6)}.p-8{padding:calc(var(--spacing)*8)}.p-10{padding:calc(var(--spacing)*10)}.px-4{padding-inline:calc(var(--spacing)*4)}.px-5{padding-inline:calc(var(--spacing)*5)}.px-6{padding-inline:calc(var(--spacing)*6)}.py-2{padding-block:calc(var(--spacing)*2)}.py-3{padding-block:calc(var(--spacing)*3)}.py-3\.5{padding-block:calc(var(--spacing)*3.5)}.py-6{padding-block:calc(var(--spacing)*6)}.text-center{text-align:center}.text-justify{text-align:justify}.text-left{text-align:left}.font-mono{font-family:var(--font-mono)}.font-sans{font-family:var(--font-sans)}.text-2xl{font-size:var(--text-2xl);line-height:var(--tw-leading,var(--text-2xl--line-height))}.text-4xl{font-size:var(--text-4xl);line-height:var(--tw-leading,var(--text-4xl--line-height))}.text-6xl{font-size:var(--text-6xl);line-height:var(--tw-leading,var(--text-6xl--line-height))}.text-base{font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height))}.text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.leading-relaxed{--tw-leading:var(--leading-relaxed);line-height:var(--leading-relaxed)}.font-bold{--tw-font-weight:var(--font-weight-bold);font-weight:var(--font-weight-bold)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.tracking-\[0\.35em\]{--tw-tracking:.35em;letter-spacing:.35em}.tracking-tight{--tw-tracking:var(--tracking-tight);letter-spacing:var(--tracking-tight)}.text-wrap{text-wrap:wrap}.whitespace-pre-wrap{white-space:pre-wrap}.text-emerald-300{color:var(--color-emerald-300)}.text-emerald-300\/80{color:#5ee9b5cc}@supports (color:color-mix(in lab,red,red)){.text-emerald-300\/80{color:color-mix(in oklab,var(--color-emerald-300)80%,transparent)}}.text-emerald-400{color:var(--color-emerald-400)}.text-gray-100{color:var(--color-gray-100)}.text-gray-200{color:var(--color-gray-200)}.text-gray-300{color:var(--color-gray-300)}.text-gray-400{color:var(--color-gray-400)}.text-gray-500{color:var(--color-gray-500)}.text-red-300{color:var(--color-red-300)}.text-white{color:var(--color-white)}.capitalize{text-transform:capitalize}.uppercase{text-transform:uppercase}.ordinal{--tw-ordinal:ordinal;font-variant-numeric:var(--tw-ordinal,)var(--tw-slashed-zero,)var(--tw-numeric-figure,)var(--tw-numeric-spacing,)var(--tw-numeric-fraction,)}.opacity-0{opacity:0}.shadow{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-\[0_15px_35px_rgba\(16\,185\,129\,0\.25\)\]{--tw-shadow:0 15px 35px var(--tw-shadow-color,#10b98140);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-\[0_15px_45px_rgba\(0\,0\,0\,0\.35\)\]{--tw-shadow:0 15px 45px var(--tw-shadow-color,#00000059);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-\[0_35px_65px_rgba\(0\,0\,0\,0\.5\)\]{--tw-shadow:0 35px 65px var(--tw-shadow-color,#00000080);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-inner{--tw-shadow:inset 0 2px 4px 0 var(--tw-shadow-color,#0000000d);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(1px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.outline{outline-style:var(--tw-outline-style);outline-width:1px}.blur{--tw-blur:blur(8px);filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.invert{--tw-invert:invert(100%);filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.filter{filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.backdrop-blur-lg{--tw-backdrop-blur:blur(var(--blur-lg));-webkit-backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,)}.backdrop-blur-xl{--tw-backdrop-blur:blur(var(--blur-xl));-webkit-backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,)}.backdrop-filter{-webkit-backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,)}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-all{transition-property:all;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-colors{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-opacity{transition-property:opacity;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.duration-300{--tw-duration:.3s;transition-duration:.3s}@media(hover:hover){.group-hover\:text-white:is(:where(.group):hover *){color:var(--color-white)}.group-hover\:opacity-100:is(:where(.group):hover *){opacity:1}}.placeholder\:text-gray-500::placeholder{color:var(--color-gray-500)}@media(hover:hover){.hover\:-translate-y-0\.5:hover{--tw-translate-y:calc(var(--spacing)*-.5);translate:var(--tw-translate-x)var(--tw-translate-y)}.hover\:border-emerald-500\/40:hover{border-color:#00bb7f66}@supports (color:color-mix(in lab,red,red)){.hover\:border-emerald-500\/40:hover{border-color:color-mix(in oklab,var(--color-emerald-500)40%,transparent)}}.hover\:bg-emerald-500:hover{background-color:var(--color-emerald-500)}.hover\:bg-emerald-500\/10:hover{background-color:#00bb7f1a}@supports (color:color-mix(in lab,red,red)){.hover\:bg-emerald-500\/10:hover{background-color:color-mix(in oklab,var(--color-emerald-500)10%,transparent)}}.hover\:bg-white\/25:hover{background-color:#ffffff40}@supports (color:color-mix(in lab,red,red)){.hover\:bg-white\/25:hover{background-color:color-mix(in oklab,var(--color-white)25%,transparent)}}.hover\:text-white:hover{color:var(--color-white)}.hover\:underline:hover{text-decoration-line:underline}.hover\:shadow-\[0_20px_50px_rgba\(16\,185\,129\,0\.15\)\]:hover{--tw-shadow:0 20px 50px var(--tw-shadow-color,#10b98126);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}}.focus\:outline-none:focus{--tw-outline-style:none;outline-style:none}.disabled\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\:bg-emerald-600\/30:disabled{background-color:#0097674d}@supports (color:color-mix(in lab,red,red)){.disabled\:bg-emerald-600\/30:disabled{background-color:color-mix(in oklab,var(--color-emerald-600)30%,transparent)}}.disabled\:opacity-40:disabled{opacity:.4}@media(min-width:40rem){.sm\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}@media(min-width:48rem){.md\:px-8{padding-inline:calc(var(--spacing)*8)}.md\:py-10{padding-block:calc(var(--spacing)*10)}.md\:text-3xl{font-size:var(--text-3xl);line-height:var(--tw-leading,var(--text-3xl--line-height))}.md\:text-5xl{font-size:var(--text-5xl);line-height:var(--tw-leading,var(--text-5xl--line-height))}}}@property --tw-rotate-x{syntax:"*";inherits:false}@property --tw-rotate-y{syntax:"*";inherits:false}@property --tw-rotate-z{syntax:"*";inherits:false}@property --tw-skew-x{syntax:"*";inherits:false}@property --tw-skew-y{syntax:"*";inherits:false}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-gradient-position{syntax:"*";inherits:false}@property --tw-gradient-from{syntax:"<color>";inherits:false;initial-value:#0000}@property --tw-gradient-via{syntax:"<color>";inherits:false;initial-value:#0000}@property --tw-gradient-to{syntax:"<color>";inherits:false;initial-value:#0000}@property --tw-gradient-stops{syntax:"*";inherits:false}@property --tw-gradient-via-stops{syntax:"*";inherits:false}@property --tw-gradient-from-position{syntax:"<length-percentage>";inherits:false;initial-value:0%}@property --tw-gradient-via-position{syntax:"<length-percentage>";inherits:false;initial-value:50%}@property --tw-gradient-to-position{syntax:"<length-percentage>";inherits:false;initial-value:100%}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-tracking{syntax:"*";inherits:false}@property --tw-ordinal{syntax:"*";inherits:false}@property --tw-slashed-zero{syntax:"*";inherits:false}@property --tw-numeric-figure{syntax:"*";inherits:false}@property --tw-numeric-spacing{syntax:"*";inherits:false}@property --tw-numeric-fraction{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-outline-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-blur{syntax:"*";inherits:false}@property --tw-brightness{syntax:"*";inherits:false}@property --tw-contrast{syntax:"*";inherits:false}@property --tw-grayscale{syntax:"*";inherits:false}@property --tw-hue-rotate{syntax:"*";inherits:false}@property --tw-invert{syntax:"*";inherits:false}@property --tw-opacity{syntax:"*";inherits:false}@property --tw-saturate{syntax:"*";inherits:false}@property --tw-sepia{syntax:"*";inherits:false}@property --tw-drop-shadow{syntax:"*";inherits:false}@property --tw-drop-shadow-color{syntax:"*";inherits:false}@property --tw-drop-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-drop-shadow-size{syntax:"*";inherits:false}@property --tw-backdrop-blur{syntax:"*";inherits:false}@property --tw-backdrop-brightness{syntax:"*";inherits:false}@property --tw-backdrop-contrast{syntax:"*";inherits:false}@property --tw-backdrop-grayscale{syntax:"*";inherits:false}@property --tw-backdrop-hue-rotate{syntax:"*";inherits:false}@property --tw-backdrop-invert{syntax:"*";inherits:false}@property --tw-backdrop-opacity{syntax:"*";inherits:false}@property --tw-backdrop-saturate{syntax:"*";inherits:false}@property --tw-backdrop-sepia{syntax:"*";inherits:false}@property --tw-duration{syntax:"*";inherits:false}@property --tw-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-y{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-z{syntax:"*";inherits:false;initial-value:0}@keyframes spin{to{transform:rotate(360deg)}}pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{color:#c9d1d9;background:#0d1117}.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-template-tag,.hljs-template-variable,.hljs-type,.hljs-variable.language_{color:#ff7b72}.hljs-title,.hljs-title.class_,.hljs-title.class_.inherited__,.hljs-title.function_{color:#d2a8ff}.hljs-attr,.hljs-attribute,.hljs-literal,.hljs-meta,.hljs-number,.hljs-operator,.hljs-variable,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id{color:#79c0ff}.hljs-regexp,.hljs-string,.hljs-meta .hljs-string{color:#a5d6ff}.hljs-built_in,.hljs-symbol{color:#ffa657}.hljs-comment,.hljs-code,.hljs-formula{color:#8b949e}.hljs-name,.hljs-quote,.hljs-selector-tag,.hljs-selector-pseudo{color:#7ee787}.hljs-subst{color:#c9d1d9}.hljs-section{color:#1f6feb;font-weight:700}.hljs-bullet{color:#f2cc60}.hljs-emphasis{color:#c9d1d9;font-style:italic}.hljs-strong{color:#c9d1d9;font-weight:700}.hljs-addition{color:#aff5b4;background-color:#033a16}.hljs-deletion{color:#ffdcd7;background-color:#67060c}
|
assets/ort-wasm-simd-threaded.jsep-B0T3yYHD.wasm
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c46655e8a94afc45338d4cb2b840475f88e5012d524509916e505079c00bfa39
|
| 3 |
+
size 21596019
|
index.html
CHANGED
|
@@ -1,29 +1,17 @@
|
|
| 1 |
-
<!
|
| 2 |
<html lang="en">
|
| 3 |
-
|
| 4 |
-
<head>
|
| 5 |
<meta charset="UTF-8" />
|
| 6 |
-
<link
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 9 |
-
<title>
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
<
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
d="M3.5 24.3a3 3 0 0 1-1.9-.8c-.5-.5-.8-1.2-.8-1.9V2.9c0-.7.3-1.3.8-1.9.6-.5 1.2-.7 2-.7h18.6c.7 0 1.3.2 1.9.7.5.6.7 1.2.7 2v18.6c0 .7-.2 1.4-.7 1.9a3 3 0 0 1-2 .8H3.6Zm0-2.7h18.7V2.9H3.5v18.7Zm2.7-2.7h13.3c.3 0 .5 0 .6-.3v-.7l-3.7-5a.6.6 0 0 0-.6-.2c-.2 0-.4 0-.5.3l-3.5 4.6-2.4-3.3a.6.6 0 0 0-.6-.3c-.2 0-.4.1-.5.3l-2.7 3.6c-.1.2-.2.4 0 .7.1.2.3.3.6.3Z">
|
| 18 |
-
</path>
|
| 19 |
-
</svg>
|
| 20 |
-
Click to upload image
|
| 21 |
-
<label id="example">(or try example)</label>
|
| 22 |
-
</label>
|
| 23 |
-
<label id="status">Loading model...</label>
|
| 24 |
-
<input id="upload" type="file" accept="image/*" />
|
| 25 |
-
|
| 26 |
-
<script src="index.js" type="module"></script>
|
| 27 |
-
</body>
|
| 28 |
-
|
| 29 |
-
</html>
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
<html lang="en">
|
| 3 |
+
<head>
|
|
|
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
+
<link
|
| 6 |
+
rel="icon"
|
| 7 |
+
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>💻</text></svg>"
|
| 8 |
+
/>
|
| 9 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 10 |
+
<title>Maincoder 1B - In-Browser Code Generation</title>
|
| 11 |
+
<script type="module" crossorigin src="/assets/index-BP17AIvh.js"></script>
|
| 12 |
+
<link rel="stylesheet" crossorigin href="/assets/index-Co9424he.css">
|
| 13 |
+
</head>
|
| 14 |
+
<body>
|
| 15 |
+
<div id="root"></div>
|
| 16 |
+
</body>
|
| 17 |
+
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
index.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
| 1 |
-
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.6';
|
| 2 |
-
|
| 3 |
-
// Reference the elements that we will need
|
| 4 |
-
const status = document.getElementById('status');
|
| 5 |
-
const fileUpload = document.getElementById('upload');
|
| 6 |
-
const imageContainer = document.getElementById('container');
|
| 7 |
-
const example = document.getElementById('example');
|
| 8 |
-
|
| 9 |
-
const EXAMPLE_URL = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
|
| 10 |
-
|
| 11 |
-
// Create a new object detection pipeline
|
| 12 |
-
status.textContent = 'Loading model...';
|
| 13 |
-
const detector = await pipeline('object-detection', 'Xenova/detr-resnet-50');
|
| 14 |
-
status.textContent = 'Ready';
|
| 15 |
-
|
| 16 |
-
example.addEventListener('click', (e) => {
|
| 17 |
-
e.preventDefault();
|
| 18 |
-
detect(EXAMPLE_URL);
|
| 19 |
-
});
|
| 20 |
-
|
| 21 |
-
fileUpload.addEventListener('change', function (e) {
|
| 22 |
-
const file = e.target.files[0];
|
| 23 |
-
if (!file) {
|
| 24 |
-
return;
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
const reader = new FileReader();
|
| 28 |
-
|
| 29 |
-
// Set up a callback when the file is loaded
|
| 30 |
-
reader.onload = e2 => detect(e2.target.result);
|
| 31 |
-
|
| 32 |
-
reader.readAsDataURL(file);
|
| 33 |
-
});
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
// Detect objects in the image
|
| 37 |
-
async function detect(img) {
|
| 38 |
-
imageContainer.innerHTML = '';
|
| 39 |
-
imageContainer.style.backgroundImage = `url(${img})`;
|
| 40 |
-
|
| 41 |
-
status.textContent = 'Analysing...';
|
| 42 |
-
const output = await detector(img, {
|
| 43 |
-
threshold: 0.5,
|
| 44 |
-
percentage: true,
|
| 45 |
-
});
|
| 46 |
-
status.textContent = '';
|
| 47 |
-
output.forEach(renderBox);
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
// Render a bounding box and label on the image
|
| 51 |
-
function renderBox({ box, label }) {
|
| 52 |
-
const { xmax, xmin, ymax, ymin } = box;
|
| 53 |
-
|
| 54 |
-
// Generate a random color for the box
|
| 55 |
-
const color = '#' + Math.floor(Math.random() * 0xFFFFFF).toString(16).padStart(6, 0);
|
| 56 |
-
|
| 57 |
-
// Draw the box
|
| 58 |
-
const boxElement = document.createElement('div');
|
| 59 |
-
boxElement.className = 'bounding-box';
|
| 60 |
-
Object.assign(boxElement.style, {
|
| 61 |
-
borderColor: color,
|
| 62 |
-
left: 100 * xmin + '%',
|
| 63 |
-
top: 100 * ymin + '%',
|
| 64 |
-
width: 100 * (xmax - xmin) + '%',
|
| 65 |
-
height: 100 * (ymax - ymin) + '%',
|
| 66 |
-
})
|
| 67 |
-
|
| 68 |
-
// Draw label
|
| 69 |
-
const labelElement = document.createElement('span');
|
| 70 |
-
labelElement.textContent = label;
|
| 71 |
-
labelElement.className = 'bounding-box-label';
|
| 72 |
-
labelElement.style.backgroundColor = color;
|
| 73 |
-
|
| 74 |
-
boxElement.appendChild(labelElement);
|
| 75 |
-
imageContainer.appendChild(boxElement);
|
| 76 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "maincoder-webgpu",
|
| 3 |
+
"private": true,
|
| 4 |
+
"version": "0.0.0",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "vite",
|
| 8 |
+
"build": "tsc -b && vite build",
|
| 9 |
+
"preview": "vite preview"
|
| 10 |
+
},
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"@huggingface/transformers": "^3.7.6",
|
| 13 |
+
"@tailwindcss/vite": "^4.1.11",
|
| 14 |
+
"highlight.js": "^11.11.1",
|
| 15 |
+
"lucide-react": "^0.535.0",
|
| 16 |
+
"react": "^19.1.0",
|
| 17 |
+
"react-dom": "^19.1.0",
|
| 18 |
+
"tailwindcss": "^4.1.11"
|
| 19 |
+
},
|
| 20 |
+
"devDependencies": {
|
| 21 |
+
"@types/react": "^19.1.8",
|
| 22 |
+
"@types/react-dom": "^19.1.6",
|
| 23 |
+
"@vitejs/plugin-react": "^4.6.0",
|
| 24 |
+
"typescript": "~5.8.3",
|
| 25 |
+
"vite": "^7.0.4"
|
| 26 |
+
}
|
| 27 |
+
}
|
src/App.tsx
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useRef, useEffect, useCallback } from "react";
|
| 2 |
+
import { Send, RotateCcw, Zap } from "lucide-react";
|
| 3 |
+
import { useLLM } from "./hooks/useLLM";
|
| 4 |
+
import { LoadingScreen } from "./components/LoadingScreen";
|
| 5 |
+
import { ChatMessage } from "./components/ChatMessage";
|
| 6 |
+
|
| 7 |
+
interface Message {
|
| 8 |
+
role: "user" | "assistant";
|
| 9 |
+
content: string;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
const SYSTEM_MESSAGE = {
|
| 13 |
+
role: "system",
|
| 14 |
+
content:
|
| 15 |
+
"You are Maincoder, an expert code generation assistant. Write clean, well-structured code. When responding with code, use markdown code blocks with the appropriate language identifier.",
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
const EXAMPLES = [
|
| 19 |
+
{
|
| 20 |
+
icon: "🐍",
|
| 21 |
+
text: "Binary search in Python",
|
| 22 |
+
message: "Write a binary search function in Python",
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
icon: "⚡",
|
| 26 |
+
text: "Fibonacci with memoization",
|
| 27 |
+
message: "Write a fibonacci function with memoization in JavaScript",
|
| 28 |
+
},
|
| 29 |
+
];
|
| 30 |
+
|
| 31 |
+
const App = () => {
|
| 32 |
+
const [messages, setMessages] = useState<Message[]>([]);
|
| 33 |
+
const [input, setInput] = useState("");
|
| 34 |
+
const [isGenerating, setIsGenerating] = useState(false);
|
| 35 |
+
const chatRef = useRef<HTMLDivElement>(null);
|
| 36 |
+
const inputRef = useRef<HTMLInputElement>(null);
|
| 37 |
+
|
| 38 |
+
const { isLoading, isReady, error, progress, loadModel, generateResponse, clearHistory } =
|
| 39 |
+
useLLM();
|
| 40 |
+
|
| 41 |
+
useEffect(() => {
|
| 42 |
+
if (chatRef.current) {
|
| 43 |
+
chatRef.current.scrollTop = chatRef.current.scrollHeight;
|
| 44 |
+
}
|
| 45 |
+
}, [messages]);
|
| 46 |
+
|
| 47 |
+
const clearChat = useCallback(() => {
|
| 48 |
+
setMessages([]);
|
| 49 |
+
clearHistory();
|
| 50 |
+
}, [clearHistory]);
|
| 51 |
+
|
| 52 |
+
const sendMessage = useCallback(
|
| 53 |
+
async (text: string) => {
|
| 54 |
+
if (!text.trim() || !isReady || isGenerating) return;
|
| 55 |
+
|
| 56 |
+
const userMessage: Message = { role: "user", content: text };
|
| 57 |
+
const currentMessages = [...messages, userMessage];
|
| 58 |
+
setMessages(currentMessages);
|
| 59 |
+
setInput("");
|
| 60 |
+
setIsGenerating(true);
|
| 61 |
+
|
| 62 |
+
try {
|
| 63 |
+
const messagesForModel = [
|
| 64 |
+
SYSTEM_MESSAGE,
|
| 65 |
+
...currentMessages.map((m) => ({ role: m.role, content: m.content })),
|
| 66 |
+
];
|
| 67 |
+
|
| 68 |
+
setMessages([...currentMessages, { role: "assistant", content: "" }]);
|
| 69 |
+
|
| 70 |
+
let accumulated = "";
|
| 71 |
+
const response = await generateResponse(
|
| 72 |
+
messagesForModel,
|
| 73 |
+
(token: string) => {
|
| 74 |
+
accumulated += token;
|
| 75 |
+
setMessages((prev) => {
|
| 76 |
+
const updated = [...prev];
|
| 77 |
+
updated[updated.length - 1] = {
|
| 78 |
+
role: "assistant",
|
| 79 |
+
content: accumulated,
|
| 80 |
+
};
|
| 81 |
+
return updated;
|
| 82 |
+
});
|
| 83 |
+
},
|
| 84 |
+
);
|
| 85 |
+
|
| 86 |
+
setMessages([
|
| 87 |
+
...currentMessages,
|
| 88 |
+
{ role: "assistant", content: response },
|
| 89 |
+
]);
|
| 90 |
+
} catch (err) {
|
| 91 |
+
const errorMsg =
|
| 92 |
+
err instanceof Error ? err.message : "Generation failed";
|
| 93 |
+
setMessages([
|
| 94 |
+
...currentMessages,
|
| 95 |
+
{ role: "assistant", content: `Error: ${errorMsg}` },
|
| 96 |
+
]);
|
| 97 |
+
} finally {
|
| 98 |
+
setIsGenerating(false);
|
| 99 |
+
setTimeout(() => inputRef.current?.focus(), 0);
|
| 100 |
+
}
|
| 101 |
+
},
|
| 102 |
+
[messages, isReady, isGenerating, generateResponse],
|
| 103 |
+
);
|
| 104 |
+
|
| 105 |
+
if (!isReady) {
|
| 106 |
+
return (
|
| 107 |
+
<LoadingScreen
|
| 108 |
+
isLoading={isLoading}
|
| 109 |
+
progress={progress}
|
| 110 |
+
error={error}
|
| 111 |
+
onLoad={loadModel}
|
| 112 |
+
/>
|
| 113 |
+
);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
return (
|
| 117 |
+
<div className="font-sans min-h-screen bg-gradient-to-br from-[#0a0f1a] via-[#0d1520] to-[#060a12] text-gray-100">
|
| 118 |
+
<div className="flex h-screen w-full py-6 px-4 md:py-10 md:px-8">
|
| 119 |
+
<div className="flex-1 flex flex-col p-6 bg-white/5 backdrop-blur-lg border border-white/10 rounded-3xl shadow-[0_35px_65px_rgba(0,0,0,0.5)] min-h-0">
|
| 120 |
+
{/* Header */}
|
| 121 |
+
<div className="flex items-center justify-between mb-6">
|
| 122 |
+
<div className="space-y-1">
|
| 123 |
+
<div className="flex items-center gap-2">
|
| 124 |
+
<Zap size={16} className="text-emerald-400" />
|
| 125 |
+
<span className="text-xs font-semibold uppercase tracking-[0.35em] text-emerald-400">
|
| 126 |
+
WebGPU
|
| 127 |
+
</span>
|
| 128 |
+
</div>
|
| 129 |
+
<h1 className="text-2xl md:text-3xl font-bold text-white">
|
| 130 |
+
Maincoder <span className="text-emerald-400">1B</span>
|
| 131 |
+
</h1>
|
| 132 |
+
</div>
|
| 133 |
+
<button
|
| 134 |
+
disabled={isGenerating}
|
| 135 |
+
onClick={clearChat}
|
| 136 |
+
className={`h-10 flex items-center px-4 rounded-full font-semibold text-sm transition-all border ${
|
| 137 |
+
isGenerating
|
| 138 |
+
? "border-white/10 bg-white/5 text-gray-500 cursor-not-allowed"
|
| 139 |
+
: "border-white/15 bg-white/8 text-gray-300 hover:border-emerald-500/40 hover:bg-emerald-500/10"
|
| 140 |
+
}`}
|
| 141 |
+
>
|
| 142 |
+
<RotateCcw size={14} className="mr-2" /> New Chat
|
| 143 |
+
</button>
|
| 144 |
+
</div>
|
| 145 |
+
|
| 146 |
+
{/* Chat Area */}
|
| 147 |
+
<div
|
| 148 |
+
ref={chatRef}
|
| 149 |
+
className="flex-grow bg-[#080d16]/80 border border-white/10 rounded-2xl p-6 overflow-y-auto mb-6 space-y-5 shadow-inner min-h-0"
|
| 150 |
+
>
|
| 151 |
+
{messages.length === 0 ? (
|
| 152 |
+
<div className="flex flex-col items-center justify-center h-full space-y-6">
|
| 153 |
+
<div className="text-center mb-4">
|
| 154 |
+
<h2 className="text-2xl font-semibold text-white mb-1">
|
| 155 |
+
What would you like to code?
|
| 156 |
+
</h2>
|
| 157 |
+
<p className="text-sm text-gray-400">
|
| 158 |
+
Try an example or type your own prompt
|
| 159 |
+
</p>
|
| 160 |
+
</div>
|
| 161 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 max-w-2xl w-full px-4">
|
| 162 |
+
{EXAMPLES.map((example, i) => (
|
| 163 |
+
<button
|
| 164 |
+
key={i}
|
| 165 |
+
onClick={() => sendMessage(example.message)}
|
| 166 |
+
className="group relative overflow-hidden rounded-2xl border border-white/10 bg-white/5 text-left transition-all hover:-translate-y-0.5 hover:shadow-[0_20px_50px_rgba(16,185,129,0.15)]"
|
| 167 |
+
>
|
| 168 |
+
<span className="pointer-events-none absolute inset-0 bg-gradient-to-r from-emerald-500/15 via-transparent to-transparent opacity-0 transition-opacity group-hover:opacity-100" />
|
| 169 |
+
<div className="relative flex items-center gap-3 px-4 py-3.5">
|
| 170 |
+
<span className="flex size-10 flex-shrink-0 items-center justify-center rounded-full border border-emerald-500/20 bg-emerald-500/10 text-lg">
|
| 171 |
+
{example.icon}
|
| 172 |
+
</span>
|
| 173 |
+
<span className="text-sm font-medium text-gray-200 group-hover:text-white transition-colors">
|
| 174 |
+
{example.text}
|
| 175 |
+
</span>
|
| 176 |
+
</div>
|
| 177 |
+
</button>
|
| 178 |
+
))}
|
| 179 |
+
</div>
|
| 180 |
+
</div>
|
| 181 |
+
) : (
|
| 182 |
+
messages.map((msg, i) => (
|
| 183 |
+
<ChatMessage key={i} role={msg.role} content={msg.content} />
|
| 184 |
+
))
|
| 185 |
+
)}
|
| 186 |
+
</div>
|
| 187 |
+
|
| 188 |
+
{/* Input */}
|
| 189 |
+
<div className="flex items-center gap-3">
|
| 190 |
+
<div className="flex flex-1 items-center bg-white/5 border border-white/10 rounded-2xl overflow-hidden shadow-[0_15px_45px_rgba(0,0,0,0.35)]">
|
| 191 |
+
<input
|
| 192 |
+
ref={inputRef}
|
| 193 |
+
type="text"
|
| 194 |
+
value={input}
|
| 195 |
+
onChange={(e) => setInput(e.target.value)}
|
| 196 |
+
onKeyDown={(e) =>
|
| 197 |
+
e.key === "Enter" && !isGenerating && sendMessage(input)
|
| 198 |
+
}
|
| 199 |
+
disabled={isGenerating}
|
| 200 |
+
className="flex-grow bg-transparent px-5 py-3.5 text-base text-white placeholder:text-gray-500 focus:outline-none disabled:opacity-40"
|
| 201 |
+
placeholder="Ask Maincoder to write some code..."
|
| 202 |
+
/>
|
| 203 |
+
<button
|
| 204 |
+
onClick={() => sendMessage(input)}
|
| 205 |
+
disabled={isGenerating || !input.trim()}
|
| 206 |
+
className="h-full px-5 py-3.5 bg-emerald-600 hover:bg-emerald-500 disabled:bg-emerald-600/30 disabled:cursor-not-allowed text-white font-semibold transition-all"
|
| 207 |
+
>
|
| 208 |
+
<Send size={20} />
|
| 209 |
+
</button>
|
| 210 |
+
</div>
|
| 211 |
+
</div>
|
| 212 |
+
</div>
|
| 213 |
+
</div>
|
| 214 |
+
</div>
|
| 215 |
+
);
|
| 216 |
+
};
|
| 217 |
+
|
| 218 |
+
export default App;
|
src/components/ChatMessage.tsx
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type React from "react";
|
| 2 |
+
import { useState, useRef, useEffect } from "react";
|
| 3 |
+
import { Copy, Check } from "lucide-react";
|
| 4 |
+
import hljs from "highlight.js";
|
| 5 |
+
import "highlight.js/styles/github-dark.css";
|
| 6 |
+
|
| 7 |
+
interface CodeBlockProps {
|
| 8 |
+
language: string;
|
| 9 |
+
code: string;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
const CodeBlock: React.FC<CodeBlockProps> = ({ language, code }) => {
|
| 13 |
+
const [copied, setCopied] = useState(false);
|
| 14 |
+
const codeRef = useRef<HTMLElement>(null);
|
| 15 |
+
|
| 16 |
+
useEffect(() => {
|
| 17 |
+
if (codeRef.current) {
|
| 18 |
+
codeRef.current.removeAttribute("data-highlighted");
|
| 19 |
+
hljs.highlightElement(codeRef.current);
|
| 20 |
+
}
|
| 21 |
+
}, [code, language]);
|
| 22 |
+
|
| 23 |
+
const handleCopy = async () => {
|
| 24 |
+
await navigator.clipboard.writeText(code);
|
| 25 |
+
setCopied(true);
|
| 26 |
+
setTimeout(() => setCopied(false), 2000);
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
return (
|
| 30 |
+
<div className="rounded-xl overflow-hidden border border-white/10 bg-[#0d1117] my-3">
|
| 31 |
+
<div className="flex items-center justify-between px-4 py-2 bg-white/5 border-b border-white/10">
|
| 32 |
+
<span className="text-xs font-mono text-gray-400">
|
| 33 |
+
{language || "code"}
|
| 34 |
+
</span>
|
| 35 |
+
<button
|
| 36 |
+
onClick={handleCopy}
|
| 37 |
+
className="flex items-center gap-1.5 text-xs text-gray-400 hover:text-white transition-colors"
|
| 38 |
+
>
|
| 39 |
+
{copied ? <Check size={14} /> : <Copy size={14} />}
|
| 40 |
+
{copied ? "Copied" : "Copy"}
|
| 41 |
+
</button>
|
| 42 |
+
</div>
|
| 43 |
+
<pre className="p-4 overflow-x-auto text-sm leading-relaxed !bg-[#0d1117]">
|
| 44 |
+
<code ref={codeRef} className={language ? `language-${language}` : ""}>
|
| 45 |
+
{code}
|
| 46 |
+
</code>
|
| 47 |
+
</pre>
|
| 48 |
+
</div>
|
| 49 |
+
);
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
function looksLikeCode(text: string): boolean {
|
| 53 |
+
const result = hljs.highlightAuto(text);
|
| 54 |
+
return result.relevance > 5;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
function parseContent(text: string): React.ReactNode[] {
|
| 58 |
+
const parts: React.ReactNode[] = [];
|
| 59 |
+
const codeBlockRegex = /```(\w*)\n([\s\S]*?)```/g;
|
| 60 |
+
let lastIndex = 0;
|
| 61 |
+
let match;
|
| 62 |
+
|
| 63 |
+
while ((match = codeBlockRegex.exec(text)) !== null) {
|
| 64 |
+
if (match.index > lastIndex) {
|
| 65 |
+
const textBefore = text.slice(lastIndex, match.index);
|
| 66 |
+
parts.push(
|
| 67 |
+
<span key={`text-${lastIndex}`} className="whitespace-pre-wrap">
|
| 68 |
+
{textBefore}
|
| 69 |
+
</span>,
|
| 70 |
+
);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
parts.push(
|
| 74 |
+
<CodeBlock
|
| 75 |
+
key={`code-${match.index}`}
|
| 76 |
+
language={match[1]}
|
| 77 |
+
code={match[2].trimEnd()}
|
| 78 |
+
/>,
|
| 79 |
+
);
|
| 80 |
+
|
| 81 |
+
lastIndex = match.index + match[0].length;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
if (lastIndex < text.length) {
|
| 85 |
+
const remaining = text.slice(lastIndex);
|
| 86 |
+
// If no code fences were found and the content looks like code, render as code block
|
| 87 |
+
if (lastIndex === 0 && remaining.trim().length > 0 && looksLikeCode(remaining)) {
|
| 88 |
+
const detected = hljs.highlightAuto(remaining);
|
| 89 |
+
parts.push(
|
| 90 |
+
<CodeBlock
|
| 91 |
+
key="code-auto"
|
| 92 |
+
language={detected.language || ""}
|
| 93 |
+
code={remaining.trimEnd()}
|
| 94 |
+
/>,
|
| 95 |
+
);
|
| 96 |
+
} else {
|
| 97 |
+
parts.push(
|
| 98 |
+
<span key={`text-${lastIndex}`} className="whitespace-pre-wrap">
|
| 99 |
+
{remaining}
|
| 100 |
+
</span>,
|
| 101 |
+
);
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
return parts;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
export const ChatMessage: React.FC<{
|
| 109 |
+
role: "user" | "assistant";
|
| 110 |
+
content: string;
|
| 111 |
+
}> = ({ role, content }) => {
|
| 112 |
+
if (role === "user") {
|
| 113 |
+
return (
|
| 114 |
+
<div className="flex justify-end">
|
| 115 |
+
<div className="px-4 py-3 rounded-2xl max-w-lg bg-emerald-600/20 border border-emerald-500/30">
|
| 116 |
+
<p className="text-white whitespace-pre-wrap">{content}</p>
|
| 117 |
+
</div>
|
| 118 |
+
</div>
|
| 119 |
+
);
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
return (
|
| 123 |
+
<div className="flex justify-start">
|
| 124 |
+
<div className="px-4 py-3 rounded-2xl max-w-2xl bg-white/5 border border-white/10">
|
| 125 |
+
<div className="text-gray-200">{parseContent(content)}</div>
|
| 126 |
+
</div>
|
| 127 |
+
</div>
|
| 128 |
+
);
|
| 129 |
+
};
|
src/components/LoadingScreen.tsx
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useEffect, useRef } from "react";
|
| 2 |
+
|
| 3 |
+
interface Dot {
|
| 4 |
+
x: number;
|
| 5 |
+
y: number;
|
| 6 |
+
vx: number;
|
| 7 |
+
vy: number;
|
| 8 |
+
radius: number;
|
| 9 |
+
opacity: number;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
export const LoadingScreen = ({
|
| 13 |
+
isLoading,
|
| 14 |
+
progress,
|
| 15 |
+
error,
|
| 16 |
+
onLoad,
|
| 17 |
+
}: {
|
| 18 |
+
isLoading: boolean;
|
| 19 |
+
progress: number;
|
| 20 |
+
error: string | null;
|
| 21 |
+
onLoad: () => void;
|
| 22 |
+
}) => {
|
| 23 |
+
const canvasRef = useRef<HTMLCanvasElement>(null);
|
| 24 |
+
|
| 25 |
+
useEffect(() => {
|
| 26 |
+
const canvas = canvasRef.current;
|
| 27 |
+
if (!canvas) return;
|
| 28 |
+
const ctx = canvas.getContext("2d");
|
| 29 |
+
if (!ctx) return;
|
| 30 |
+
|
| 31 |
+
let animationFrameId: number;
|
| 32 |
+
let dots: Dot[] = [];
|
| 33 |
+
|
| 34 |
+
const setup = () => {
|
| 35 |
+
canvas.width = window.innerWidth;
|
| 36 |
+
canvas.height = window.innerHeight;
|
| 37 |
+
dots = [];
|
| 38 |
+
const numDots = Math.floor((canvas.width * canvas.height) / 22000);
|
| 39 |
+
for (let i = 0; i < numDots; ++i) {
|
| 40 |
+
dots.push({
|
| 41 |
+
x: Math.random() * canvas.width,
|
| 42 |
+
y: Math.random() * canvas.height,
|
| 43 |
+
vx: (Math.random() - 0.5) * 0.3,
|
| 44 |
+
vy: (Math.random() - 0.5) * 0.3,
|
| 45 |
+
radius: Math.random() * 1.5 + 0.5,
|
| 46 |
+
opacity: Math.random() * 0.4 + 0.15,
|
| 47 |
+
});
|
| 48 |
+
}
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
const draw = () => {
|
| 52 |
+
if (!ctx) return;
|
| 53 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 54 |
+
|
| 55 |
+
dots.forEach((dot) => {
|
| 56 |
+
dot.x += dot.vx;
|
| 57 |
+
dot.y += dot.vy;
|
| 58 |
+
if (dot.x <= 0 || dot.x >= canvas.width) dot.vx *= -1;
|
| 59 |
+
if (dot.y <= 0 || dot.y >= canvas.height) dot.vy *= -1;
|
| 60 |
+
|
| 61 |
+
ctx.beginPath();
|
| 62 |
+
ctx.arc(dot.x, dot.y, dot.radius, 0, Math.PI * 2);
|
| 63 |
+
ctx.fillStyle = `rgba(74, 222, 128, ${dot.opacity})`;
|
| 64 |
+
ctx.fill();
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
const maxDist = 120;
|
| 68 |
+
ctx.lineWidth = 0.5;
|
| 69 |
+
for (let i = 0; i < dots.length; i++) {
|
| 70 |
+
for (let j = i + 1; j < dots.length; j++) {
|
| 71 |
+
const dx = dots[i].x - dots[j].x;
|
| 72 |
+
const dy = dots[i].y - dots[j].y;
|
| 73 |
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
| 74 |
+
if (distance < maxDist) {
|
| 75 |
+
const opacity = 1 - distance / maxDist;
|
| 76 |
+
ctx.strokeStyle = `rgba(74, 222, 128, ${opacity * 0.2})`;
|
| 77 |
+
ctx.beginPath();
|
| 78 |
+
ctx.moveTo(dots[i].x, dots[i].y);
|
| 79 |
+
ctx.lineTo(dots[j].x, dots[j].y);
|
| 80 |
+
ctx.stroke();
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
animationFrameId = requestAnimationFrame(draw);
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
const handleResize = () => {
|
| 89 |
+
cancelAnimationFrame(animationFrameId);
|
| 90 |
+
setup();
|
| 91 |
+
draw();
|
| 92 |
+
};
|
| 93 |
+
|
| 94 |
+
setup();
|
| 95 |
+
draw();
|
| 96 |
+
window.addEventListener("resize", handleResize);
|
| 97 |
+
return () => {
|
| 98 |
+
window.removeEventListener("resize", handleResize);
|
| 99 |
+
cancelAnimationFrame(animationFrameId);
|
| 100 |
+
};
|
| 101 |
+
}, []);
|
| 102 |
+
|
| 103 |
+
return (
|
| 104 |
+
<div className="relative flex flex-col items-center justify-center h-screen bg-gradient-to-br from-[#0a0f1a] via-[#0d1520] to-[#060a12] text-gray-100 p-8 overflow-hidden">
|
| 105 |
+
<canvas
|
| 106 |
+
ref={canvasRef}
|
| 107 |
+
className="absolute top-0 left-0 w-full h-full z-0"
|
| 108 |
+
/>
|
| 109 |
+
<div className="absolute top-0 left-0 w-full h-full z-10 bg-[radial-gradient(ellipse_at_center,_rgba(10,15,26,0)_30%,_rgba(6,10,18,0.9)_95%)]" />
|
| 110 |
+
|
| 111 |
+
<div className="relative z-20 max-w-2xl w-full flex flex-col items-center bg-white/5 border border-white/10 backdrop-blur-xl rounded-3xl p-10 shadow-[0_35px_65px_rgba(0,0,0,0.5)] space-y-8">
|
| 112 |
+
<div className="flex flex-col items-center gap-3">
|
| 113 |
+
<div className="text-6xl">💻</div>
|
| 114 |
+
<h1 className="text-4xl md:text-5xl font-bold text-white tracking-tight">
|
| 115 |
+
Maincoder <span className="text-emerald-400">1B</span>
|
| 116 |
+
</h1>
|
| 117 |
+
<p className="text-lg text-emerald-300/80">
|
| 118 |
+
In-browser code generation, powered by WebGPU
|
| 119 |
+
</p>
|
| 120 |
+
</div>
|
| 121 |
+
|
| 122 |
+
<div className="w-full text-left text-gray-300 space-y-3 text-base">
|
| 123 |
+
<p>
|
| 124 |
+
Run{" "}
|
| 125 |
+
<a
|
| 126 |
+
href="https://huggingface.co/Maincode/Maincoder-1B-ONNX"
|
| 127 |
+
target="_blank"
|
| 128 |
+
rel="noopener noreferrer"
|
| 129 |
+
className="text-emerald-400 hover:underline font-medium"
|
| 130 |
+
>
|
| 131 |
+
Maincoder-1B
|
| 132 |
+
</a>{" "}
|
| 133 |
+
entirely in your browser using{" "}
|
| 134 |
+
<a
|
| 135 |
+
href="https://huggingface.co/docs/transformers.js"
|
| 136 |
+
target="_blank"
|
| 137 |
+
rel="noopener noreferrer"
|
| 138 |
+
className="text-emerald-400 hover:underline font-medium"
|
| 139 |
+
>
|
| 140 |
+
Transformers.js
|
| 141 |
+
</a>{" "}
|
| 142 |
+
and WebGPU. No server, no data leaves your device.
|
| 143 |
+
</p>
|
| 144 |
+
<p className="text-sm text-gray-400">
|
| 145 |
+
A 1B-parameter code generation model achieving 76.2% on HumanEval
|
| 146 |
+
(~600MB download, int4 quantized). Requires a WebGPU-capable browser
|
| 147 |
+
(Chrome 113+).
|
| 148 |
+
</p>
|
| 149 |
+
</div>
|
| 150 |
+
|
| 151 |
+
<div className="w-full max-w-md">
|
| 152 |
+
<button
|
| 153 |
+
onClick={isLoading ? undefined : onLoad}
|
| 154 |
+
disabled={isLoading}
|
| 155 |
+
className={`w-full flex items-center justify-center font-semibold transition-all text-lg rounded-2xl border ${
|
| 156 |
+
isLoading
|
| 157 |
+
? "bg-white/5 text-gray-400 cursor-not-allowed border-white/10"
|
| 158 |
+
: "bg-emerald-600 hover:bg-emerald-500 text-white border-emerald-500/50 shadow-[0_15px_35px_rgba(16,185,129,0.25)]"
|
| 159 |
+
}`}
|
| 160 |
+
>
|
| 161 |
+
<div className="px-6 py-3.5">
|
| 162 |
+
{isLoading ? (
|
| 163 |
+
<div className="flex items-center">
|
| 164 |
+
<span className="inline-block w-5 h-5 border-2 border-emerald-400/80 border-t-transparent rounded-full animate-spin" />
|
| 165 |
+
<span className="ml-3 text-md font-medium text-emerald-300">
|
| 166 |
+
Downloading model... ({progress}%)
|
| 167 |
+
</span>
|
| 168 |
+
</div>
|
| 169 |
+
) : (
|
| 170 |
+
"Load Maincoder-1B"
|
| 171 |
+
)}
|
| 172 |
+
</div>
|
| 173 |
+
</button>
|
| 174 |
+
|
| 175 |
+
{isLoading && (
|
| 176 |
+
<div className="mt-4 w-full bg-white/10 rounded-full h-2 overflow-hidden">
|
| 177 |
+
<div
|
| 178 |
+
className="h-full bg-gradient-to-r from-emerald-500 to-emerald-400 rounded-full transition-all duration-300"
|
| 179 |
+
style={{ width: `${progress}%` }}
|
| 180 |
+
/>
|
| 181 |
+
</div>
|
| 182 |
+
)}
|
| 183 |
+
</div>
|
| 184 |
+
|
| 185 |
+
{error && (
|
| 186 |
+
<div className="bg-red-900/30 border border-red-500/40 rounded-2xl p-4 w-full text-center">
|
| 187 |
+
<p className="text-sm text-red-300">Error: {error}</p>
|
| 188 |
+
<button
|
| 189 |
+
onClick={onLoad}
|
| 190 |
+
className="mt-3 text-sm px-4 py-2 rounded-full bg-white/15 hover:bg-white/25 border border-white/20 text-white font-semibold transition-all"
|
| 191 |
+
>
|
| 192 |
+
Retry
|
| 193 |
+
</button>
|
| 194 |
+
</div>
|
| 195 |
+
)}
|
| 196 |
+
</div>
|
| 197 |
+
</div>
|
| 198 |
+
);
|
| 199 |
+
};
|
src/hooks/useLLM.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useRef, useCallback, useEffect } from "react";
|
| 2 |
+
import {
|
| 3 |
+
AutoModelForCausalLM,
|
| 4 |
+
AutoTokenizer,
|
| 5 |
+
TextStreamer,
|
| 6 |
+
} from "@huggingface/transformers";
|
| 7 |
+
|
| 8 |
+
const MODEL_ID = "shreyask/Maincoder-1B-ONNX-web";
|
| 9 |
+
|
| 10 |
+
interface LLMState {
|
| 11 |
+
isLoading: boolean;
|
| 12 |
+
isReady: boolean;
|
| 13 |
+
error: string | null;
|
| 14 |
+
progress: number;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
interface LLMInstance {
|
| 18 |
+
model: any;
|
| 19 |
+
tokenizer: any;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
let cachedInstance: LLMInstance | null = null;
|
| 23 |
+
let loadingPromise: Promise<LLMInstance> | null = null;
|
| 24 |
+
|
| 25 |
+
export const useLLM = () => {
|
| 26 |
+
const [state, setState] = useState<LLMState>({
|
| 27 |
+
isLoading: false,
|
| 28 |
+
isReady: false,
|
| 29 |
+
error: null,
|
| 30 |
+
progress: 0,
|
| 31 |
+
});
|
| 32 |
+
|
| 33 |
+
const instanceRef = useRef<LLMInstance | null>(null);
|
| 34 |
+
const pastKeyValuesRef = useRef<any>(null);
|
| 35 |
+
|
| 36 |
+
const loadModel = useCallback(async () => {
|
| 37 |
+
if (instanceRef.current || cachedInstance) {
|
| 38 |
+
const instance = instanceRef.current || cachedInstance;
|
| 39 |
+
instanceRef.current = instance;
|
| 40 |
+
cachedInstance = instance;
|
| 41 |
+
setState((prev) => ({ ...prev, isReady: true, isLoading: false }));
|
| 42 |
+
return instance;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
if (loadingPromise) {
|
| 46 |
+
const instance = await loadingPromise;
|
| 47 |
+
instanceRef.current = instance;
|
| 48 |
+
cachedInstance = instance;
|
| 49 |
+
setState((prev) => ({ ...prev, isReady: true, isLoading: false }));
|
| 50 |
+
return instance;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
setState((prev) => ({
|
| 54 |
+
...prev,
|
| 55 |
+
isLoading: true,
|
| 56 |
+
error: null,
|
| 57 |
+
progress: 0,
|
| 58 |
+
}));
|
| 59 |
+
|
| 60 |
+
loadingPromise = (async () => {
|
| 61 |
+
try {
|
| 62 |
+
const progress_callback = (progress: any) => {
|
| 63 |
+
if (
|
| 64 |
+
progress.status === "progress" &&
|
| 65 |
+
(progress.file?.endsWith(".onnx") ||
|
| 66 |
+
progress.file?.endsWith(".onnx_data"))
|
| 67 |
+
) {
|
| 68 |
+
const percentage = Math.round(
|
| 69 |
+
(progress.loaded / progress.total) * 100,
|
| 70 |
+
);
|
| 71 |
+
setState((prev) => ({ ...prev, progress: percentage }));
|
| 72 |
+
}
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
const tokenizer = await AutoTokenizer.from_pretrained(MODEL_ID, {
|
| 76 |
+
progress_callback,
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
const model = await AutoModelForCausalLM.from_pretrained(MODEL_ID, {
|
| 80 |
+
dtype: "q4",
|
| 81 |
+
device: "webgpu",
|
| 82 |
+
progress_callback,
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
+
const instance = { model, tokenizer };
|
| 86 |
+
instanceRef.current = instance;
|
| 87 |
+
cachedInstance = instance;
|
| 88 |
+
loadingPromise = null;
|
| 89 |
+
|
| 90 |
+
setState({
|
| 91 |
+
isLoading: false,
|
| 92 |
+
isReady: true,
|
| 93 |
+
error: null,
|
| 94 |
+
progress: 100,
|
| 95 |
+
});
|
| 96 |
+
return instance;
|
| 97 |
+
} catch (error) {
|
| 98 |
+
loadingPromise = null;
|
| 99 |
+
const message =
|
| 100 |
+
error instanceof Error ? error.message : "Failed to load model";
|
| 101 |
+
setState((prev) => ({
|
| 102 |
+
...prev,
|
| 103 |
+
isLoading: false,
|
| 104 |
+
error: message,
|
| 105 |
+
}));
|
| 106 |
+
throw error;
|
| 107 |
+
}
|
| 108 |
+
})();
|
| 109 |
+
|
| 110 |
+
return loadingPromise;
|
| 111 |
+
}, []);
|
| 112 |
+
|
| 113 |
+
const generateResponse = useCallback(
|
| 114 |
+
async (
|
| 115 |
+
messages: Array<{ role: string; content: string }>,
|
| 116 |
+
onToken?: (token: string) => void,
|
| 117 |
+
): Promise<string> => {
|
| 118 |
+
const instance = instanceRef.current;
|
| 119 |
+
if (!instance) {
|
| 120 |
+
throw new Error("Model not loaded. Call loadModel() first.");
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
const { model, tokenizer } = instance;
|
| 124 |
+
|
| 125 |
+
const input = tokenizer.apply_chat_template(messages, {
|
| 126 |
+
add_generation_prompt: true,
|
| 127 |
+
return_dict: true,
|
| 128 |
+
});
|
| 129 |
+
|
| 130 |
+
const streamer = onToken
|
| 131 |
+
? new TextStreamer(tokenizer, {
|
| 132 |
+
skip_prompt: true,
|
| 133 |
+
skip_special_tokens: false,
|
| 134 |
+
callback_function: onToken,
|
| 135 |
+
})
|
| 136 |
+
: undefined;
|
| 137 |
+
|
| 138 |
+
const { sequences, past_key_values } = await model.generate({
|
| 139 |
+
...input,
|
| 140 |
+
past_key_values: pastKeyValuesRef.current,
|
| 141 |
+
max_new_tokens: 1024,
|
| 142 |
+
do_sample: false,
|
| 143 |
+
repetition_penalty: 1.2,
|
| 144 |
+
eos_token_id: [151643, 151645], // <|endoftext|> and <|im_end|>
|
| 145 |
+
streamer,
|
| 146 |
+
return_dict_in_generate: true,
|
| 147 |
+
});
|
| 148 |
+
pastKeyValuesRef.current = past_key_values;
|
| 149 |
+
|
| 150 |
+
const response = tokenizer
|
| 151 |
+
.batch_decode(sequences.slice(null, [input.input_ids.dims[1], null]), {
|
| 152 |
+
skip_special_tokens: false,
|
| 153 |
+
})[0]
|
| 154 |
+
.replace(/<\|end_of_text\|>$/, "")
|
| 155 |
+
.replace(/<\|im_end\|>$/, "");
|
| 156 |
+
|
| 157 |
+
return response;
|
| 158 |
+
},
|
| 159 |
+
[],
|
| 160 |
+
);
|
| 161 |
+
|
| 162 |
+
const clearHistory = useCallback(() => {
|
| 163 |
+
pastKeyValuesRef.current = null;
|
| 164 |
+
}, []);
|
| 165 |
+
|
| 166 |
+
useEffect(() => {
|
| 167 |
+
if (cachedInstance) {
|
| 168 |
+
instanceRef.current = cachedInstance;
|
| 169 |
+
setState((prev) => ({ ...prev, isReady: true }));
|
| 170 |
+
}
|
| 171 |
+
}, []);
|
| 172 |
+
|
| 173 |
+
return {
|
| 174 |
+
...state,
|
| 175 |
+
loadModel,
|
| 176 |
+
generateResponse,
|
| 177 |
+
clearHistory,
|
| 178 |
+
};
|
| 179 |
+
};
|
src/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
@import "tailwindcss";
|
src/main.tsx
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { StrictMode } from "react";
|
| 2 |
+
import { createRoot } from "react-dom/client";
|
| 3 |
+
import "./index.css";
|
| 4 |
+
import App from "./App.tsx";
|
| 5 |
+
|
| 6 |
+
createRoot(document.getElementById("root")!).render(
|
| 7 |
+
<StrictMode>
|
| 8 |
+
<App />
|
| 9 |
+
</StrictMode>,
|
| 10 |
+
);
|
src/vite-env.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
/// <reference types="vite/client" />
|
style.css
DELETED
|
@@ -1,76 +0,0 @@
|
|
| 1 |
-
* {
|
| 2 |
-
box-sizing: border-box;
|
| 3 |
-
padding: 0;
|
| 4 |
-
margin: 0;
|
| 5 |
-
font-family: sans-serif;
|
| 6 |
-
}
|
| 7 |
-
|
| 8 |
-
html,
|
| 9 |
-
body {
|
| 10 |
-
height: 100%;
|
| 11 |
-
}
|
| 12 |
-
|
| 13 |
-
body {
|
| 14 |
-
padding: 32px;
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
body,
|
| 18 |
-
#container {
|
| 19 |
-
display: flex;
|
| 20 |
-
flex-direction: column;
|
| 21 |
-
justify-content: center;
|
| 22 |
-
align-items: center;
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
#container {
|
| 26 |
-
position: relative;
|
| 27 |
-
gap: 0.4rem;
|
| 28 |
-
|
| 29 |
-
width: 640px;
|
| 30 |
-
height: 640px;
|
| 31 |
-
max-width: 100%;
|
| 32 |
-
max-height: 100%;
|
| 33 |
-
|
| 34 |
-
border: 2px dashed #D1D5DB;
|
| 35 |
-
border-radius: 0.75rem;
|
| 36 |
-
overflow: hidden;
|
| 37 |
-
cursor: pointer;
|
| 38 |
-
margin: 1rem;
|
| 39 |
-
|
| 40 |
-
background-size: 100% 100%;
|
| 41 |
-
background-position: center;
|
| 42 |
-
background-repeat: no-repeat;
|
| 43 |
-
font-size: 18px;
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
#upload {
|
| 47 |
-
display: none;
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
svg {
|
| 51 |
-
pointer-events: none;
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
#example {
|
| 55 |
-
font-size: 14px;
|
| 56 |
-
text-decoration: underline;
|
| 57 |
-
cursor: pointer;
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
#example:hover {
|
| 61 |
-
color: #2563EB;
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
.bounding-box {
|
| 65 |
-
position: absolute;
|
| 66 |
-
box-sizing: border-box;
|
| 67 |
-
border: solid 2px;
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
.bounding-box-label {
|
| 71 |
-
color: white;
|
| 72 |
-
position: absolute;
|
| 73 |
-
font-size: 12px;
|
| 74 |
-
margin: -16px 0 0 -2px;
|
| 75 |
-
padding: 1px;
|
| 76 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tsconfig.app.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compilerOptions": {
|
| 3 |
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
| 4 |
+
"target": "ES2022",
|
| 5 |
+
"useDefineForClassFields": true,
|
| 6 |
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
| 7 |
+
"module": "ESNext",
|
| 8 |
+
"skipLibCheck": true,
|
| 9 |
+
"moduleResolution": "bundler",
|
| 10 |
+
"allowImportingTsExtensions": true,
|
| 11 |
+
"verbatimModuleSyntax": true,
|
| 12 |
+
"moduleDetection": "force",
|
| 13 |
+
"noEmit": true,
|
| 14 |
+
"jsx": "react-jsx",
|
| 15 |
+
"strict": true,
|
| 16 |
+
"noUnusedLocals": true,
|
| 17 |
+
"noUnusedParameters": true,
|
| 18 |
+
"erasableSyntaxOnly": true,
|
| 19 |
+
"noFallthroughCasesInSwitch": true,
|
| 20 |
+
"noUncheckedSideEffectImports": true
|
| 21 |
+
},
|
| 22 |
+
"include": ["src"]
|
| 23 |
+
}
|
tsconfig.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"files": [],
|
| 3 |
+
"references": [
|
| 4 |
+
{ "path": "./tsconfig.app.json" },
|
| 5 |
+
{ "path": "./tsconfig.node.json" }
|
| 6 |
+
]
|
| 7 |
+
}
|
tsconfig.node.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compilerOptions": {
|
| 3 |
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
| 4 |
+
"target": "ES2023",
|
| 5 |
+
"lib": ["ES2023"],
|
| 6 |
+
"module": "ESNext",
|
| 7 |
+
"skipLibCheck": true,
|
| 8 |
+
"moduleResolution": "bundler",
|
| 9 |
+
"allowImportingTsExtensions": true,
|
| 10 |
+
"verbatimModuleSyntax": true,
|
| 11 |
+
"moduleDetection": "force",
|
| 12 |
+
"noEmit": true,
|
| 13 |
+
"strict": true,
|
| 14 |
+
"noUnusedLocals": true,
|
| 15 |
+
"noUnusedParameters": true,
|
| 16 |
+
"erasableSyntaxOnly": true,
|
| 17 |
+
"noFallthroughCasesInSwitch": true,
|
| 18 |
+
"noUncheckedSideEffectImports": true
|
| 19 |
+
},
|
| 20 |
+
"include": ["vite.config.ts"]
|
| 21 |
+
}
|
vite.config.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { defineConfig } from "vite";
|
| 2 |
+
import react from "@vitejs/plugin-react";
|
| 3 |
+
import tailwindcss from "@tailwindcss/vite";
|
| 4 |
+
|
| 5 |
+
export default defineConfig({
|
| 6 |
+
plugins: [react(), tailwindcss()],
|
| 7 |
+
});
|