multimodalart HF Staff commited on
Commit
7a3b672
·
verified ·
1 Parent(s): 01519ba

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ samples/binfullness.wav filter=lfs diff=lfs merge=lfs -text
37
+ samples/returntobase.wav filter=lfs diff=lfs merge=lfs -text
38
+ samples/vaccumkitchen.wav filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,33 @@
1
  ---
2
- title: Neudecide
3
- emoji: 🐠
4
- colorFrom: green
5
- colorTo: red
6
  sdk: gradio
7
  sdk_version: 6.29.1
8
- python_version: '3.13'
9
  app_file: app.py
10
- pinned: false
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: NeuDecide
3
+ emoji: 🎙️
4
+ colorFrom: blue
5
+ colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 6.29.1
 
8
  app_file: app.py
9
+ short_description: Speech in, tool calls out — no transcript in between
10
+ python_version: "3.12"
11
  ---
12
 
13
+ A demo of [NeuDecide](https://huggingface.co/neuphonic/neudecide), a tiny (~55M parameter, 43 MB)
14
+ voice-action model from [Neuphonic](https://www.neuphonic.com). Record a spoken command, give it a
15
+ list of tools as JSON, and it emits the matching tool call — no transcript in between and no GPU
16
+ required.
17
+
18
+ ```
19
+ "clean the bathroom" + [cleanRoom, goToBase, getBattery] → [{"name": "cleanRoom", "arguments": {"room": "bathroom"}}]
20
+ ```
21
+
22
+ - **Inputs**: a short voice recording (≤ 30 s, English) and a JSON list of tool definitions
23
+ (`name`, `description`, JSON-Schema `parameters`).
24
+ - **Output**: the tool calls the utterance maps to — a JSON list of `{"name", "arguments"}`
25
+ dicts, or `[]` when no tool applies.
26
+ - **How**: three q4 ONNX graphs (audio encoder, tool encoder, decoder) run on CPU via
27
+ ONNX Runtime with grammar-constrained decoding, using the
28
+ [`neudecide`](https://pypi.org/project/neudecide/) package.
29
+
30
+ Tools are passed in at inference time, so you change what the model can do by editing the JSON —
31
+ try the preset tool sets (robot vacuum, car control, smart home) or paste your own. Weights are
32
+ bundled in `model/`; sample WAVs and preset tools are from the
33
+ [authors' repository](https://github.com/neuphonic/neudecide) (Apache-2.0).
app.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Gradio demo for NeuDecide — a tiny voice-action model.
2
+
3
+ Audio and a list of tools in, a tool call out: no transcript in between.
4
+ Runs the three q4 ONNX graphs on CPU with the `neudecide` package.
5
+ """
6
+
7
+ import json
8
+ import time
9
+ from pathlib import Path
10
+
11
+ import gradio as gr
12
+
13
+ from neudecide import NeuDecide
14
+
15
+ MODEL_DIR = Path(__file__).parent / "model"
16
+ SCENARIOS = json.loads((Path(__file__).parent / "scenarios.json").read_text())
17
+ SCENARIO_CHOICES = [("", "Custom tools")] + [
18
+ (key, f"{sc['label']} ({len(sc['tools'])} tools)") for key, sc in SCENARIOS.items()
19
+ ]
20
+ DEFAULT_TOOLS = SCENARIOS["robot_vacuum"]["tools"]
21
+
22
+ model = NeuDecide(str(MODEL_DIR))
23
+
24
+
25
+ def load_scenario(scenario: str) -> str:
26
+ """Fill the tools box with one of the preset tool lists.
27
+
28
+ Args:
29
+ scenario: a scenario key from scenarios.json, or "" to leave tools as-is.
30
+ """
31
+ sc = SCENARIOS.get(scenario)
32
+ return json.dumps(sc["tools"], indent=2) if sc else gr.update()
33
+
34
+
35
+ def generate(audio, tools_json: str = "", constrained: bool = True):
36
+ """Turn a spoken command and a tool list into tool calls.
37
+
38
+ Args:
39
+ audio: a recording of the command, any sample rate (tuple of
40
+ (sample_rate, numpy waveform), as Gradio's Audio component provides).
41
+ tools_json: a JSON list of tool definitions (name, description,
42
+ JSON-Schema parameters).
43
+ constrained: restrict decoding to valid calls of the given tools.
44
+
45
+ Returns:
46
+ dict with the emitted tool_calls, their count, and the elapsed seconds.
47
+ """
48
+ if audio is None:
49
+ raise gr.Error("Record or upload some audio first.")
50
+ try:
51
+ tools = json.loads(tools_json) if isinstance(tools_json, str) else tools_json
52
+ except json.JSONDecodeError as e:
53
+ raise gr.Error(f"Tools are not valid JSON: {e}")
54
+ if not isinstance(tools, list) or not tools:
55
+ raise gr.Error("Provide at least one tool definition.")
56
+
57
+ sample_rate, waveform = audio[0], audio[1]
58
+ t0 = time.perf_counter()
59
+ calls = model.generate(waveform, tools, sample_rate=sample_rate, constrained=constrained)
60
+ elapsed = time.perf_counter() - t0
61
+
62
+ result = {
63
+ "tool_calls": calls,
64
+ "num_calls": len(calls),
65
+ "seconds": round(elapsed, 3),
66
+ "constrained": constrained,
67
+ }
68
+ if not calls:
69
+ result["note"] = "No tool matched this utterance."
70
+ return result
71
+
72
+
73
+ CSS = """
74
+ #col-container { max-width: 1100px; margin: 0 auto; }
75
+ .dark .gradio-container { color: var(--body-text-color); }
76
+ """
77
+
78
+ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
79
+ with gr.Column(elem_id="col-container"):
80
+ gr.Markdown(
81
+ """
82
+ # NeuDecide — speech in, tool calls out
83
+ **A tiny (~55M param, 43 MB) voice-action model.** Record a spoken command, give it a
84
+ list of tools as JSON, and it emits the matching tool call — no transcript in between,
85
+ no GPU. You change what it can do by changing the JSON, not the weights.
86
+ """
87
+ )
88
+ with gr.Row():
89
+ with gr.Column(scale=1):
90
+ audio_in = gr.Audio(
91
+ label="Voice command (≤ 30 s)",
92
+ type="numpy",
93
+ format="wav",
94
+ sources=["microphone", "upload"],
95
+ )
96
+ scenario_dd = gr.Dropdown(
97
+ choices=SCENARIO_CHOICES,
98
+ value="robot_vacuum",
99
+ label="Preset tool set",
100
+ info="Optional: load a ready-made tool list, then edit it freely.",
101
+ )
102
+ tools_json = gr.Textbox(
103
+ label="Tools (JSON)",
104
+ value=json.dumps(DEFAULT_TOOLS, indent=2),
105
+ lines=14,
106
+ max_lines=20,
107
+ )
108
+ constrained_cb = gr.Checkbox(
109
+ value=True,
110
+ label="Constrain decoding to valid tool calls",
111
+ )
112
+ run_btn = gr.Button("Decide", variant="primary")
113
+ with gr.Column(scale=1):
114
+ out_json = gr.JSON(label="Tool calls")
115
+
116
+ scenario_dd.change(load_scenario, inputs=scenario_dd, outputs=tools_json)
117
+ run_btn.click(
118
+ generate,
119
+ inputs=[audio_in, tools_json, constrained_cb],
120
+ outputs=out_json,
121
+ api_name="generate",
122
+ )
123
+
124
+ gr.Examples(
125
+ examples=[
126
+ ["samples/vaccumkitchen.wav", json.dumps(DEFAULT_TOOLS)],
127
+ ["samples/binfullness.wav", json.dumps(DEFAULT_TOOLS)],
128
+ ["samples/returntobase.wav", json.dumps(DEFAULT_TOOLS)],
129
+ ["samples/command.wav", json.dumps(DEFAULT_TOOLS)],
130
+ ],
131
+ inputs=[audio_in, tools_json],
132
+ outputs=out_json,
133
+ fn=generate,
134
+ label="Try the authors' sample commands",
135
+ cache_examples=True,
136
+ cache_mode="lazy",
137
+ )
138
+
139
+ gr.Markdown(
140
+ """
141
+ ---
142
+ **Model**: [neuphonic/neudecide](https://huggingface.co/neuphonic/neudecide) ·
143
+ **Code**: [github.com/neuphonic/neudecide](https://github.com/neuphonic/neudecide) ·
144
+ `pip install neudecide`
145
+ English only; ≤ 30 s audio; ≤ 1,536 tool tokens; ≤ 128 output tokens. The q4 ONNX
146
+ graphs run here on CPU. Sample WAVs and preset tools come from the authors' repo.
147
+ """
148
+ )
149
+
150
+ demo.launch(mcp_server=True)
model/audio_encoder_q4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ac5c48e1766382736ed8dd4d468568ee583536550fb741ac187219f8cd8da9b
3
+ size 22519972
model/config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "step": 12500,
3
+ "fold": {
4
+ "lora": 0,
5
+ "lora+qat": 112,
6
+ "qat_linear": 147,
7
+ "act_fq": 0,
8
+ "embedding": 1
9
+ },
10
+ "variants": {
11
+ "q4": {
12
+ "graphs": {
13
+ "audio_encoder": "audio_encoder_q4.onnx",
14
+ "tool_encoder": "tool_encoder_q4.onnx",
15
+ "decoder_step": "decoder_step_q4.onnx"
16
+ },
17
+ "scheme": {
18
+ "bits": 4,
19
+ "group_size": 32,
20
+ "embedding": true,
21
+ "audio_encoder": true,
22
+ "conv_bits": 8
23
+ },
24
+ "accuracy_level": 4,
25
+ "compute": "int4 MatMulNBits / GatherBlockQuantized"
26
+ }
27
+ },
28
+ "sample_rate": 16000,
29
+ "max_audio_seconds": 30.0,
30
+ "max_tools_len": 1536,
31
+ "max_answer_len": 128,
32
+ "tools_json": "Python json.dumps(tools) defaults: ', ' and ': ' separators, ensure_ascii",
33
+ "special_tokens": {
34
+ "pad": 0,
35
+ "eos": 1,
36
+ "bos": 2,
37
+ "unk": 3,
38
+ "tool_call": 4,
39
+ "tools": 5
40
+ },
41
+ "vocab_size": 8192,
42
+ "d_model": 512,
43
+ "num_decoder_layers": 8,
44
+ "num_kv_heads": 4,
45
+ "head_dim": 64
46
+ }
model/decoder_step_q4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee68bbb4bbca552b909b41cb1fdbfdf0f9f3c852561e18036044ee2ff461e50d
3
+ size 9951225
model/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
model/tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b39d6892d3b27e66a1782ee624d965e5e656c03e9226cbe036a80389090947ad
3
+ size 124892
model/tool_encoder_q4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a5075ee2868d90ea4be3234eae04001be6886c9730e8746421fa17e84313d85
3
+ size 10090217
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ neudecide==0.1.0
samples/binfullness.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45440609257d430cff2d08ee77dd49f551e160ce94031bf10cefa67a6a5ee156
3
+ size 263152
samples/command.wav ADDED
Binary file (53.8 kB). View file
 
samples/returntobase.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:51a422ccf54579ce6f3e0326f1bf2ac9263ca443592141ac35b6bd0299dffb7e
3
+ size 309888
samples/vaccumkitchen.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:26766453feeaab30da6ec680a19833e299edee33e9b9643521876dc6e53eb907
3
+ size 368308
scenarios.json ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "robot_vacuum": {
3
+ "label": "Robot vacuum",
4
+ "examples": [
5
+ "Clean the kitchen",
6
+ "How full is the bin?",
7
+ "Go back to your dock",
8
+ "Mop the bathroom"
9
+ ],
10
+ "tools": [
11
+ {
12
+ "name": "cleanRoom",
13
+ "description": "Vacuum-cleans the specified room.",
14
+ "parameters": {
15
+ "type": "object",
16
+ "properties": {
17
+ "room": {
18
+ "type": "string",
19
+ "enum": [
20
+ "livingRoom",
21
+ "kitchen",
22
+ "bedroom",
23
+ "bathroom",
24
+ "hallway",
25
+ "office"
26
+ ]
27
+ }
28
+ },
29
+ "required": [
30
+ "room"
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "name": "mopRoom",
36
+ "description": "Mops the specified room's hard flooring.",
37
+ "parameters": {
38
+ "type": "object",
39
+ "properties": {
40
+ "room": {
41
+ "type": "string",
42
+ "enum": [
43
+ "livingRoom",
44
+ "kitchen",
45
+ "bedroom",
46
+ "bathroom",
47
+ "hallway",
48
+ "office"
49
+ ]
50
+ }
51
+ },
52
+ "required": [
53
+ "room"
54
+ ]
55
+ }
56
+ },
57
+ {
58
+ "name": "returnToBase",
59
+ "description": "Sends the vacuum back to its charging dock.",
60
+ "parameters": {
61
+ "type": "object",
62
+ "properties": {},
63
+ "required": []
64
+ }
65
+ },
66
+ {
67
+ "name": "getBatteryLevel",
68
+ "description": "Reports the current battery charge percentage.",
69
+ "parameters": {
70
+ "type": "object",
71
+ "properties": {},
72
+ "required": []
73
+ }
74
+ },
75
+ {
76
+ "name": "getBinLevel",
77
+ "description": "Reports how full the dust bin currently is.",
78
+ "parameters": {
79
+ "type": "object",
80
+ "properties": {},
81
+ "required": []
82
+ }
83
+ }
84
+ ]
85
+ },
86
+ "car_control": {
87
+ "label": "Car control",
88
+ "examples": [
89
+ "Play Bohemian Rhapsody by Queen",
90
+ "Text Sam that I'm running late",
91
+ "Set the temperature to 70",
92
+ "Turn the volume up to 8",
93
+ "Lock the doors"
94
+ ],
95
+ "tools": [
96
+ {
97
+ "name": "playSong",
98
+ "description": "Plays the requested song in the car's media system.",
99
+ "parameters": {
100
+ "type": "object",
101
+ "properties": {
102
+ "song": {
103
+ "type": "string",
104
+ "description": "Song title."
105
+ },
106
+ "artist": {
107
+ "type": "string",
108
+ "description": "Artist name, if given."
109
+ }
110
+ },
111
+ "required": [
112
+ "song"
113
+ ]
114
+ }
115
+ },
116
+ {
117
+ "name": "sendText",
118
+ "description": "Sends a text message to a contact.",
119
+ "parameters": {
120
+ "type": "object",
121
+ "properties": {
122
+ "contact": {
123
+ "type": "string",
124
+ "description": "Who to message."
125
+ },
126
+ "message": {
127
+ "type": "string",
128
+ "description": "The message text."
129
+ }
130
+ },
131
+ "required": [
132
+ "contact",
133
+ "message"
134
+ ]
135
+ }
136
+ },
137
+ {
138
+ "name": "setTemperature",
139
+ "description": "Sets the cabin temperature.",
140
+ "parameters": {
141
+ "type": "object",
142
+ "properties": {
143
+ "temperatureF": {
144
+ "type": "number",
145
+ "minimum": 60,
146
+ "maximum": 85,
147
+ "description": "Target temperature in Fahrenheit."
148
+ },
149
+ "zone": {
150
+ "type": "string",
151
+ "enum": [
152
+ "driver",
153
+ "passenger",
154
+ "all"
155
+ ]
156
+ }
157
+ },
158
+ "required": [
159
+ "temperatureF"
160
+ ]
161
+ }
162
+ },
163
+ {
164
+ "name": "adjustVolume",
165
+ "description": "Sets the media volume level.",
166
+ "parameters": {
167
+ "type": "object",
168
+ "properties": {
169
+ "level": {
170
+ "type": "integer",
171
+ "minimum": 0,
172
+ "maximum": 10
173
+ }
174
+ },
175
+ "required": [
176
+ "level"
177
+ ]
178
+ }
179
+ },
180
+ {
181
+ "name": "lockDoors",
182
+ "description": "Locks or unlocks the car doors.",
183
+ "parameters": {
184
+ "type": "object",
185
+ "properties": {
186
+ "state": {
187
+ "type": "string",
188
+ "enum": [
189
+ "locked",
190
+ "unlocked"
191
+ ]
192
+ }
193
+ },
194
+ "required": [
195
+ "state"
196
+ ]
197
+ }
198
+ }
199
+ ]
200
+ },
201
+ "smart_home": {
202
+ "label": "Smart home",
203
+ "examples": [
204
+ "Turn off the bedroom lights",
205
+ "Dim the living room to 30 percent",
206
+ "Set the thermostat to 21 degrees",
207
+ "Is the front door locked?"
208
+ ],
209
+ "tools": [
210
+ {
211
+ "name": "setLights",
212
+ "description": "Turns the lights in a room on or off.",
213
+ "parameters": {
214
+ "type": "object",
215
+ "properties": {
216
+ "room": {
217
+ "type": "string",
218
+ "enum": [
219
+ "livingRoom",
220
+ "kitchen",
221
+ "bedroom",
222
+ "bathroom",
223
+ "office"
224
+ ]
225
+ },
226
+ "on": {
227
+ "type": "boolean"
228
+ }
229
+ },
230
+ "required": [
231
+ "room",
232
+ "on"
233
+ ]
234
+ }
235
+ },
236
+ {
237
+ "name": "setBrightness",
238
+ "description": "Sets the brightness of the lights in a room.",
239
+ "parameters": {
240
+ "type": "object",
241
+ "properties": {
242
+ "room": {
243
+ "type": "string",
244
+ "enum": [
245
+ "livingRoom",
246
+ "kitchen",
247
+ "bedroom",
248
+ "bathroom",
249
+ "office"
250
+ ]
251
+ },
252
+ "percent": {
253
+ "type": "integer",
254
+ "minimum": 0,
255
+ "maximum": 100
256
+ }
257
+ },
258
+ "required": [
259
+ "room",
260
+ "percent"
261
+ ]
262
+ }
263
+ },
264
+ {
265
+ "name": "setThermostat",
266
+ "description": "Sets the target temperature of the home heating.",
267
+ "parameters": {
268
+ "type": "object",
269
+ "properties": {
270
+ "temperatureC": {
271
+ "type": "number",
272
+ "minimum": 10,
273
+ "maximum": 30,
274
+ "description": "Target temperature in Celsius."
275
+ }
276
+ },
277
+ "required": [
278
+ "temperatureC"
279
+ ]
280
+ }
281
+ },
282
+ {
283
+ "name": "getLockStatus",
284
+ "description": "Reports whether a door is locked.",
285
+ "parameters": {
286
+ "type": "object",
287
+ "properties": {
288
+ "door": {
289
+ "type": "string",
290
+ "enum": [
291
+ "front",
292
+ "back",
293
+ "garage"
294
+ ]
295
+ }
296
+ },
297
+ "required": [
298
+ "door"
299
+ ]
300
+ }
301
+ },
302
+ {
303
+ "name": "startRobotVacuum",
304
+ "description": "Starts the robot vacuum's cleaning cycle.",
305
+ "parameters": {
306
+ "type": "object",
307
+ "properties": {},
308
+ "required": []
309
+ }
310
+ }
311
+ ]
312
+ }
313
+ }