freddyaboulton HF staff commited on
Commit
3112b0d
1 Parent(s): 3c004fa
Files changed (4) hide show
  1. README.md +1 -1
  2. app.py +68 -0
  3. requirements.in +4 -0
  4. requirements.txt +291 -0
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Smollm Voice Code Editor
3
- emoji: 📊
4
  colorFrom: pink
5
  colorTo: blue
6
  sdk: gradio
 
1
  ---
2
  title: Smollm Voice Code Editor
3
+ emoji: ⚡️
4
  colorFrom: pink
5
  colorTo: blue
6
  sdk: gradio
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2
+ import gradio as gr
3
+ from gradio_webrtc import WebRTC, ReplyOnPause, AdditionalOutputs
4
+ import numpy as np
5
+ import os
6
+ from twilio.rest import Client
7
+
8
+ account_sid = os.environ.get("TWILIO_ACCOUNT_SID")
9
+ auth_token = os.environ.get("TWILIO_AUTH_TOKEN")
10
+
11
+ if account_sid and auth_token:
12
+ client = Client(account_sid, auth_token)
13
+
14
+ token = client.tokens.create()
15
+
16
+ rtc_configuration = {
17
+ "iceServers": token.ice_servers,
18
+ "iceTransportPolicy": "relay",
19
+ }
20
+ else:
21
+ rtc_configuration = None
22
+
23
+ checkpoint = "HuggingFaceTB/SmolLM2-1.7B-Instruct"
24
+
25
+ device = "cuda"
26
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
27
+ model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
28
+
29
+ whisper = pipeline(
30
+ model="openai/whisper-large-v3-turbo", device=device
31
+ )
32
+
33
+ system_prompt = "You are an AI coding assistant. Your task is to write single-file HTML applications based on a user's request. You may also be asked to edit your original response. Only return the code needed to fulfill the request."
34
+ user_prompt = "Please write a single-file HTML application to fulfill the following request. Only return the necessary code. Include all necessary imports and styles.\nThe message:{user_message}\nCurrent code you have written:{code}"
35
+
36
+
37
+
38
+ def generate(user_message: tuple[int, np.ndarray],
39
+ history: list[dict],
40
+ code: str):
41
+
42
+ msg_text = whisper({"array": user_message[1], "sampling_rate": user_message[0]})["text"]
43
+ history.append({"role": "user", "content": user_prompt.format(user_message=msg_text, code=code)})
44
+ input_text = tokenizer.apply_chat_template(history, tokenize=False)
45
+ inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
46
+ outputs = model.generate(inputs, max_new_tokens=500, temperature=0.2, top_p=0.9, do_sample=True)
47
+ response = tokenizer.decode(outputs[0])
48
+ output = response[response.rindex("<|im_start|>assistant\n") + len("<|im_start|>assistant\n"):]
49
+ history.append({"role": "assistant", "content": output})
50
+ yield AdditionalOutputs(history, output)
51
+
52
+
53
+ with gr.Blocks() as demo:
54
+ history = gr.State([{"role": "system", "content": system_prompt}])
55
+ with gr.Row():
56
+ code = gr.Code(language="html")
57
+ sandbox = gr.HTML("")
58
+ with gr.Row():
59
+ webrtc = WebRTC(rtc_configuration=rtc_configuration, mode="send", modality="audio")
60
+ webrtc.stream(ReplyOnPause(generate),
61
+ inputs=[webrtc, history, code],
62
+ outputs=[webrtc], time_limit=90)
63
+ webrtc.on_additional_outputs(lambda history, code: (history, code),
64
+ outputs=[history, code])
65
+
66
+ if __name__ == "__main__":
67
+ demo.launch()
68
+
requirements.in ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio_webrtc[vad]==0.0.12
2
+ numba==0.60.0
3
+ twilio
4
+ transformers
requirements.txt ADDED
@@ -0,0 +1,291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file was autogenerated by uv via the following command:
2
+ # uv pip compile requirements.in -o requirements.txt
3
+ aiofiles==23.2.1
4
+ # via gradio
5
+ aiohappyeyeballs==2.4.3
6
+ # via aiohttp
7
+ aiohttp==3.11.2
8
+ # via
9
+ # aiohttp-retry
10
+ # twilio
11
+ aiohttp-retry==2.8.3
12
+ # via twilio
13
+ aioice==0.9.0
14
+ # via aiortc
15
+ aiortc==1.9.0
16
+ # via gradio-webrtc
17
+ aiosignal==1.3.1
18
+ # via aiohttp
19
+ annotated-types==0.7.0
20
+ # via pydantic
21
+ anyio==4.6.2.post1
22
+ # via
23
+ # gradio
24
+ # httpx
25
+ # starlette
26
+ attrs==24.2.0
27
+ # via aiohttp
28
+ audioread==3.0.1
29
+ # via librosa
30
+ av==12.3.0
31
+ # via aiortc
32
+ certifi==2024.8.30
33
+ # via
34
+ # httpcore
35
+ # httpx
36
+ # requests
37
+ cffi==1.17.1
38
+ # via
39
+ # aiortc
40
+ # cryptography
41
+ # pylibsrtp
42
+ # soundfile
43
+ charset-normalizer==3.4.0
44
+ # via requests
45
+ click==8.1.7
46
+ # via
47
+ # typer
48
+ # uvicorn
49
+ coloredlogs==15.0.1
50
+ # via onnxruntime
51
+ cryptography==43.0.3
52
+ # via
53
+ # aiortc
54
+ # pyopenssl
55
+ decorator==5.1.1
56
+ # via librosa
57
+ dnspython==2.7.0
58
+ # via aioice
59
+ fastapi==0.115.5
60
+ # via gradio
61
+ ffmpy==0.4.0
62
+ # via gradio
63
+ filelock==3.16.1
64
+ # via
65
+ # huggingface-hub
66
+ # transformers
67
+ flatbuffers==24.3.25
68
+ # via onnxruntime
69
+ frozenlist==1.5.0
70
+ # via
71
+ # aiohttp
72
+ # aiosignal
73
+ fsspec==2024.10.0
74
+ # via
75
+ # gradio-client
76
+ # huggingface-hub
77
+ google-crc32c==1.6.0
78
+ # via aiortc
79
+ gradio==5.6.0
80
+ # via gradio-webrtc
81
+ gradio-client==1.4.3
82
+ # via gradio
83
+ gradio-webrtc==0.0.12
84
+ # via -r requirements.in
85
+ h11==0.14.0
86
+ # via
87
+ # httpcore
88
+ # uvicorn
89
+ httpcore==1.0.7
90
+ # via httpx
91
+ httpx==0.27.2
92
+ # via
93
+ # gradio
94
+ # gradio-client
95
+ # safehttpx
96
+ huggingface-hub==0.26.2
97
+ # via
98
+ # gradio
99
+ # gradio-client
100
+ # tokenizers
101
+ # transformers
102
+ humanfriendly==10.0
103
+ # via coloredlogs
104
+ idna==3.10
105
+ # via
106
+ # anyio
107
+ # httpx
108
+ # requests
109
+ # yarl
110
+ ifaddr==0.2.0
111
+ # via aioice
112
+ jinja2==3.1.4
113
+ # via gradio
114
+ joblib==1.4.2
115
+ # via
116
+ # librosa
117
+ # scikit-learn
118
+ lazy-loader==0.4
119
+ # via librosa
120
+ librosa==0.10.2.post1
121
+ # via gradio-webrtc
122
+ llvmlite==0.43.0
123
+ # via numba
124
+ markdown-it-py==3.0.0
125
+ # via rich
126
+ markupsafe==2.1.5
127
+ # via
128
+ # gradio
129
+ # jinja2
130
+ mdurl==0.1.2
131
+ # via markdown-it-py
132
+ mpmath==1.3.0
133
+ # via sympy
134
+ msgpack==1.1.0
135
+ # via librosa
136
+ multidict==6.1.0
137
+ # via
138
+ # aiohttp
139
+ # yarl
140
+ numba==0.60.0
141
+ # via
142
+ # -r requirements.in
143
+ # librosa
144
+ numpy==2.0.2
145
+ # via
146
+ # gradio
147
+ # librosa
148
+ # numba
149
+ # onnxruntime
150
+ # pandas
151
+ # scikit-learn
152
+ # scipy
153
+ # soxr
154
+ # transformers
155
+ onnxruntime==1.20.0
156
+ # via gradio-webrtc
157
+ orjson==3.10.11
158
+ # via gradio
159
+ packaging==24.2
160
+ # via
161
+ # gradio
162
+ # gradio-client
163
+ # huggingface-hub
164
+ # lazy-loader
165
+ # onnxruntime
166
+ # pooch
167
+ # transformers
168
+ pandas==2.2.3
169
+ # via gradio
170
+ pillow==11.0.0
171
+ # via gradio
172
+ platformdirs==4.3.6
173
+ # via pooch
174
+ pooch==1.8.2
175
+ # via librosa
176
+ propcache==0.2.0
177
+ # via
178
+ # aiohttp
179
+ # yarl
180
+ protobuf==5.28.3
181
+ # via onnxruntime
182
+ pycparser==2.22
183
+ # via cffi
184
+ pydantic==2.9.2
185
+ # via
186
+ # fastapi
187
+ # gradio
188
+ pydantic-core==2.23.4
189
+ # via pydantic
190
+ pydub==0.25.1
191
+ # via gradio
192
+ pyee==12.1.1
193
+ # via aiortc
194
+ pygments==2.18.0
195
+ # via rich
196
+ pyjwt==2.10.0
197
+ # via twilio
198
+ pylibsrtp==0.10.0
199
+ # via aiortc
200
+ pyopenssl==24.2.1
201
+ # via aiortc
202
+ python-dateutil==2.9.0.post0
203
+ # via pandas
204
+ python-multipart==0.0.12
205
+ # via gradio
206
+ pytz==2024.2
207
+ # via pandas
208
+ pyyaml==6.0.2
209
+ # via
210
+ # gradio
211
+ # huggingface-hub
212
+ # transformers
213
+ regex==2024.11.6
214
+ # via transformers
215
+ requests==2.32.3
216
+ # via
217
+ # huggingface-hub
218
+ # pooch
219
+ # transformers
220
+ # twilio
221
+ rich==13.9.4
222
+ # via typer
223
+ ruff==0.7.4
224
+ # via gradio
225
+ safehttpx==0.1.1
226
+ # via gradio
227
+ safetensors==0.4.5
228
+ # via transformers
229
+ scikit-learn==1.5.2
230
+ # via librosa
231
+ scipy==1.14.1
232
+ # via
233
+ # librosa
234
+ # scikit-learn
235
+ semantic-version==2.10.0
236
+ # via gradio
237
+ shellingham==1.5.4
238
+ # via typer
239
+ six==1.16.0
240
+ # via python-dateutil
241
+ sniffio==1.3.1
242
+ # via
243
+ # anyio
244
+ # httpx
245
+ soundfile==0.12.1
246
+ # via librosa
247
+ soxr==0.5.0.post1
248
+ # via librosa
249
+ starlette==0.41.3
250
+ # via
251
+ # fastapi
252
+ # gradio
253
+ sympy==1.13.3
254
+ # via onnxruntime
255
+ threadpoolctl==3.5.0
256
+ # via scikit-learn
257
+ tokenizers==0.20.3
258
+ # via transformers
259
+ tomlkit==0.12.0
260
+ # via gradio
261
+ tqdm==4.67.0
262
+ # via
263
+ # huggingface-hub
264
+ # transformers
265
+ transformers==4.46.2
266
+ # via -r requirements.in
267
+ twilio==9.3.7
268
+ # via -r requirements.in
269
+ typer==0.13.0
270
+ # via gradio
271
+ typing-extensions==4.12.2
272
+ # via
273
+ # fastapi
274
+ # gradio
275
+ # gradio-client
276
+ # huggingface-hub
277
+ # librosa
278
+ # pydantic
279
+ # pydantic-core
280
+ # pyee
281
+ # typer
282
+ tzdata==2024.2
283
+ # via pandas
284
+ urllib3==2.2.3
285
+ # via requests
286
+ uvicorn==0.32.0
287
+ # via gradio
288
+ websockets==12.0
289
+ # via gradio-client
290
+ yarl==1.17.2
291
+ # via aiohttp