voldemortuk commited on
Commit
99a7b2f
·
verified ·
1 Parent(s): e392657

Delete app/chatbot_gradio_runner.ipynb

Browse files
Files changed (1) hide show
  1. app/chatbot_gradio_runner.ipynb +0 -349
app/chatbot_gradio_runner.ipynb DELETED
@@ -1,349 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "# Generative AI for Audio Application"
8
- ]
9
- },
10
- {
11
- "cell_type": "markdown",
12
- "metadata": {},
13
- "source": [
14
- "#### Restart Kernel (If needed)"
15
- ]
16
- },
17
- {
18
- "cell_type": "code",
19
- "execution_count": 1,
20
- "metadata": {},
21
- "outputs": [
22
- {
23
- "data": {
24
- "text/plain": [
25
- "{'status': 'ok', 'restart': True}"
26
- ]
27
- },
28
- "execution_count": 1,
29
- "metadata": {},
30
- "output_type": "execute_result"
31
- }
32
- ],
33
- "source": [
34
- "import IPython\n",
35
- "\n",
36
- "app = IPython.Application.instance()\n",
37
- "app.kernel.do_shutdown(True)"
38
- ]
39
- },
40
- {
41
- "cell_type": "code",
42
- "execution_count": 3,
43
- "metadata": {},
44
- "outputs": [
45
- {
46
- "name": "stdout",
47
- "output_type": "stream",
48
- "text": [
49
- "Collecting gradio\n",
50
- " Using cached gradio-4.44.1-py3-none-any.whl (18.1 MB)\n",
51
- "Collecting aiofiles<24.0,>=22.0\n",
52
- " Using cached aiofiles-23.2.1-py3-none-any.whl (15 kB)\n",
53
- "Collecting uvicorn>=0.14.0\n",
54
- " Using cached uvicorn-0.34.0-py3-none-any.whl (62 kB)\n",
55
- "Collecting typing-extensions~=4.0\n",
56
- " Using cached typing_extensions-4.12.2-py3-none-any.whl (37 kB)\n",
57
- "Collecting jinja2<4.0\n",
58
- " Using cached jinja2-3.1.5-py3-none-any.whl (134 kB)\n",
59
- "Collecting huggingface-hub>=0.19.3\n",
60
- " Using cached huggingface_hub-0.27.1-py3-none-any.whl (450 kB)\n",
61
- "Collecting pydub\n",
62
- " Using cached pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n",
63
- "Collecting markupsafe~=2.0\n",
64
- " Using cached MarkupSafe-2.1.5-cp39-cp39-macosx_10_9_x86_64.whl (14 kB)\n",
65
- "Collecting numpy<3.0,>=1.0\n",
66
- " Using cached numpy-2.0.2-cp39-cp39-macosx_10_9_x86_64.whl (21.2 MB)\n",
67
- "Collecting tomlkit==0.12.0\n",
68
- " Using cached tomlkit-0.12.0-py3-none-any.whl (37 kB)\n",
69
- "Collecting pandas<3.0,>=1.0\n",
70
- " Using cached pandas-2.2.3-cp39-cp39-macosx_10_9_x86_64.whl (12.6 MB)\n",
71
- "Collecting ffmpy\n",
72
- " Using cached ffmpy-0.5.0-py3-none-any.whl (6.0 kB)\n",
73
- "Collecting importlib-resources<7.0,>=1.3\n",
74
- " Using cached importlib_resources-6.5.2-py3-none-any.whl (37 kB)\n",
75
- "Collecting fastapi<1.0\n",
76
- " Using cached fastapi-0.115.7-py3-none-any.whl (94 kB)\n",
77
- "Collecting pillow<11.0,>=8.0\n",
78
- " Using cached pillow-10.4.0-cp39-cp39-macosx_10_10_x86_64.whl (3.5 MB)\n",
79
- "Collecting gradio-client==1.3.0\n",
80
- " Using cached gradio_client-1.3.0-py3-none-any.whl (318 kB)\n",
81
- "Collecting httpx>=0.24.1\n",
82
- " Using cached httpx-0.28.1-py3-none-any.whl (73 kB)\n",
83
- "Collecting anyio<5.0,>=3.0\n",
84
- " Using cached anyio-4.8.0-py3-none-any.whl (96 kB)\n",
85
- "Collecting pydantic>=2.0\n",
86
- " Using cached pydantic-2.10.6-py3-none-any.whl (431 kB)\n",
87
- "Collecting pyyaml<7.0,>=5.0\n",
88
- " Using cached PyYAML-6.0.2-cp39-cp39-macosx_10_9_x86_64.whl (184 kB)\n",
89
- "Collecting semantic-version~=2.0\n",
90
- " Using cached semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\n",
91
- "Collecting orjson~=3.0\n",
92
- " Using cached orjson-3.10.15-cp39-cp39-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl (250 kB)\n",
93
- "Collecting python-multipart>=0.0.9\n",
94
- " Using cached python_multipart-0.0.20-py3-none-any.whl (24 kB)\n",
95
- "Collecting ruff>=0.2.2\n",
96
- " Using cached ruff-0.9.3-py3-none-macosx_10_12_x86_64.whl (11.6 MB)\n",
97
- "Collecting matplotlib~=3.0\n",
98
- " Using cached matplotlib-3.9.4-cp39-cp39-macosx_10_12_x86_64.whl (7.9 MB)\n",
99
- "Collecting urllib3~=2.0\n",
100
- " Using cached urllib3-2.3.0-py3-none-any.whl (128 kB)\n",
101
- "Collecting typer<1.0,>=0.12\n",
102
- " Using cached typer-0.15.1-py3-none-any.whl (44 kB)\n",
103
- "Collecting packaging\n",
104
- " Using cached packaging-24.2-py3-none-any.whl (65 kB)\n",
105
- "Collecting websockets<13.0,>=10.0\n",
106
- " Using cached websockets-12.0-cp39-cp39-macosx_10_9_x86_64.whl (121 kB)\n",
107
- "Collecting fsspec\n",
108
- " Using cached fsspec-2024.12.0-py3-none-any.whl (183 kB)\n",
109
- "Collecting exceptiongroup>=1.0.2\n",
110
- " Using cached exceptiongroup-1.2.2-py3-none-any.whl (16 kB)\n",
111
- "Collecting idna>=2.8\n",
112
- " Using cached idna-3.10-py3-none-any.whl (70 kB)\n",
113
- "Collecting sniffio>=1.1\n",
114
- " Using cached sniffio-1.3.1-py3-none-any.whl (10 kB)\n",
115
- "Collecting starlette<0.46.0,>=0.40.0\n",
116
- " Using cached starlette-0.45.3-py3-none-any.whl (71 kB)\n",
117
- "Collecting httpcore==1.*\n",
118
- " Using cached httpcore-1.0.7-py3-none-any.whl (78 kB)\n",
119
- "Collecting certifi\n",
120
- " Using cached certifi-2024.12.14-py3-none-any.whl (164 kB)\n",
121
- "Collecting h11<0.15,>=0.13\n",
122
- " Using cached h11-0.14.0-py3-none-any.whl (58 kB)\n",
123
- "Collecting requests\n",
124
- " Using cached requests-2.32.3-py3-none-any.whl (64 kB)\n",
125
- "Collecting tqdm>=4.42.1\n",
126
- " Using cached tqdm-4.67.1-py3-none-any.whl (78 kB)\n",
127
- "Collecting filelock\n",
128
- " Using cached filelock-3.17.0-py3-none-any.whl (16 kB)\n",
129
- "Collecting zipp>=3.1.0\n",
130
- " Using cached zipp-3.21.0-py3-none-any.whl (9.6 kB)\n",
131
- "Collecting fonttools>=4.22.0\n",
132
- " Using cached fonttools-4.55.6-cp39-cp39-macosx_10_9_x86_64.whl (2.3 MB)\n",
133
- "Collecting pyparsing>=2.3.1\n",
134
- " Using cached pyparsing-3.2.1-py3-none-any.whl (107 kB)\n",
135
- "Collecting python-dateutil>=2.7\n",
136
- " Using cached python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)\n",
137
- "Collecting contourpy>=1.0.1\n",
138
- " Using cached contourpy-1.3.0-cp39-cp39-macosx_10_9_x86_64.whl (265 kB)\n",
139
- "Collecting cycler>=0.10\n",
140
- " Using cached cycler-0.12.1-py3-none-any.whl (8.3 kB)\n",
141
- "Collecting kiwisolver>=1.3.1\n",
142
- " Using cached kiwisolver-1.4.7-cp39-cp39-macosx_10_9_x86_64.whl (65 kB)\n",
143
- "Collecting pytz>=2020.1\n",
144
- " Using cached pytz-2024.2-py2.py3-none-any.whl (508 kB)\n",
145
- "Collecting tzdata>=2022.7\n",
146
- " Using cached tzdata-2025.1-py2.py3-none-any.whl (346 kB)\n",
147
- "Collecting pydantic-core==2.27.2\n",
148
- " Using cached pydantic_core-2.27.2-cp39-cp39-macosx_10_12_x86_64.whl (1.9 MB)\n",
149
- "Collecting annotated-types>=0.6.0\n",
150
- " Using cached annotated_types-0.7.0-py3-none-any.whl (13 kB)\n",
151
- "Collecting six>=1.5\n",
152
- " Using cached six-1.17.0-py2.py3-none-any.whl (11 kB)\n",
153
- "Collecting shellingham>=1.3.0\n",
154
- " Using cached shellingham-1.5.4-py2.py3-none-any.whl (9.8 kB)\n",
155
- "Collecting rich>=10.11.0\n",
156
- " Using cached rich-13.9.4-py3-none-any.whl (242 kB)\n",
157
- "Collecting click>=8.0.0\n",
158
- " Using cached click-8.1.8-py3-none-any.whl (98 kB)\n",
159
- "Collecting pygments<3.0.0,>=2.13.0\n",
160
- " Using cached pygments-2.19.1-py3-none-any.whl (1.2 MB)\n",
161
- "Collecting markdown-it-py>=2.2.0\n",
162
- " Using cached markdown_it_py-3.0.0-py3-none-any.whl (87 kB)\n",
163
- "Collecting mdurl~=0.1\n",
164
- " Using cached mdurl-0.1.2-py3-none-any.whl (10.0 kB)\n",
165
- "Collecting charset-normalizer<4,>=2\n",
166
- " Using cached charset_normalizer-3.4.1-cp39-cp39-macosx_10_9_universal2.whl (197 kB)\n",
167
- "Installing collected packages: urllib3, typing-extensions, sniffio, mdurl, idna, h11, exceptiongroup, charset-normalizer, certifi, zipp, tqdm, six, requests, pyyaml, pygments, pydantic-core, packaging, numpy, markdown-it-py, httpcore, fsspec, filelock, anyio, annotated-types, websockets, tzdata, starlette, shellingham, rich, pytz, python-dateutil, pyparsing, pydantic, pillow, markupsafe, kiwisolver, importlib-resources, huggingface-hub, httpx, fonttools, cycler, contourpy, click, uvicorn, typer, tomlkit, semantic-version, ruff, python-multipart, pydub, pandas, orjson, matplotlib, jinja2, gradio-client, ffmpy, fastapi, aiofiles, gradio\n",
168
- "Successfully installed aiofiles-23.2.1 annotated-types-0.7.0 anyio-4.8.0 certifi-2024.12.14 charset-normalizer-3.4.1 click-8.1.8 contourpy-1.3.0 cycler-0.12.1 exceptiongroup-1.2.2 fastapi-0.115.7 ffmpy-0.5.0 filelock-3.17.0 fonttools-4.55.6 fsspec-2024.12.0 gradio-4.44.1 gradio-client-1.3.0 h11-0.14.0 httpcore-1.0.7 httpx-0.28.1 huggingface-hub-0.27.1 idna-3.10 importlib-resources-6.5.2 jinja2-3.1.5 kiwisolver-1.4.7 markdown-it-py-3.0.0 markupsafe-2.1.5 matplotlib-3.9.4 mdurl-0.1.2 numpy-2.0.2 orjson-3.10.15 packaging-24.2 pandas-2.2.3 pillow-10.4.0 pydantic-2.10.6 pydantic-core-2.27.2 pydub-0.25.1 pygments-2.19.1 pyparsing-3.2.1 python-dateutil-2.9.0.post0 python-multipart-0.0.20 pytz-2024.2 pyyaml-6.0.2 requests-2.32.3 rich-13.9.4 ruff-0.9.3 semantic-version-2.10.0 shellingham-1.5.4 six-1.17.0 sniffio-1.3.1 starlette-0.45.3 tomlkit-0.12.0 tqdm-4.67.1 typer-0.15.1 typing-extensions-4.12.2 tzdata-2025.1 urllib3-2.3.0 uvicorn-0.34.0 websockets-12.0 zipp-3.21.0\n",
169
- "\u001b[33mWARNING: You are using pip version 21.2.3; however, version 24.3.1 is available.\n",
170
- "You should consider upgrading via the '/Users/voldemort/Downloads/Solution 2/venv/bin/python3 -m pip install --upgrade pip' command.\u001b[0m\n"
171
- ]
172
- }
173
- ],
174
- "source": [
175
- "!pip install gradio"
176
- ]
177
- },
178
- {
179
- "cell_type": "markdown",
180
- "metadata": {},
181
- "source": [
182
- "# Import Libraries\n",
183
- "Most of the complexity for the chatbot is in [customizable_chatbot.py](./customizable_chatbot.py) that uses [audio.py](./audio.py) internally for the audio capabilities."
184
- ]
185
- },
186
- {
187
- "cell_type": "code",
188
- "execution_count": 4,
189
- "metadata": {},
190
- "outputs": [
191
- {
192
- "ename": "ModuleNotFoundError",
193
- "evalue": "No module named 'gradio'",
194
- "output_type": "error",
195
- "traceback": [
196
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
197
- "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
198
- "Cell \u001b[0;32mIn[4], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mos\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mgradio\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mgr\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mgenai_voice\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mbots\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mchatbot\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ChatBot\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mgenai_voice\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mconfig\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdefaults\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Config\n",
199
- "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'gradio'"
200
- ]
201
- }
202
- ],
203
- "source": [
204
- "import os\n",
205
- "import gradio as gr\n",
206
- "from genai_voice.bots.chatbot import ChatBot\n",
207
- "from genai_voice.config.defaults import Config\n",
208
- "from genai_voice.logger.log_utils import log, LogLevels"
209
- ]
210
- },
211
- {
212
- "cell_type": "code",
213
- "execution_count": null,
214
- "metadata": {},
215
- "outputs": [],
216
- "source": [
217
- "log(f'Configuration: {Config()}', log_level=LogLevels.ON)"
218
- ]
219
- },
220
- {
221
- "cell_type": "markdown",
222
- "metadata": {},
223
- "source": [
224
- "## Set Current Working Directory \n",
225
- "\n",
226
- "We want to simulate running this notebook from the project root just as it would work when using `Poetry` scripts."
227
- ]
228
- },
229
- {
230
- "cell_type": "code",
231
- "execution_count": null,
232
- "metadata": {},
233
- "outputs": [],
234
- "source": [
235
- "curr_wrk_dir = os.getcwd()\n",
236
- "log(f'Before directory change: {curr_wrk_dir}')\n",
237
- "if curr_wrk_dir.endswith('app'):\n",
238
- " log(f'Changing directory to root')\n",
239
- " os.chdir('..')\n",
240
- " curr_wrk_dir = os.getcwd()\n",
241
- "log(f'Before directory change: {curr_wrk_dir}')"
242
- ]
243
- },
244
- {
245
- "cell_type": "markdown",
246
- "metadata": {},
247
- "source": [
248
- "# Create Data for LLM Context \n",
249
- "\n",
250
- "`Poetry` scripts allow us to install our code as a package and run functions executables. \n",
251
- "\n",
252
- "We will use the `ExtractWebPagesAndSaveData` script, that is defined in `pyproject.toml` to scrape, extract and generate the file that the LLM will use as context data.\n",
253
- "\n",
254
- "`SAMPLE_URLS` have been defined under provided under `genai_voice.data_utils.urls.py`. Feel free to modify the links in that file to customize the source of data. \n",
255
- "\n",
256
- "> **DISCLAIMER:** Be responsible when scraping data that is not yours, complying with the EULA of the sites and conducting it in a legal fashion. Also remember that most sites will throttle scrapes, so do this with caution. \n",
257
- "\n",
258
- "> **NOTE:** This is an optional step. It just shows you have you can get custom data for your LLM context. We have provided the data for this project. "
259
- ]
260
- },
261
- {
262
- "cell_type": "code",
263
- "execution_count": null,
264
- "metadata": {},
265
- "outputs": [],
266
- "source": [
267
- "!poetry run ExtractWebPagesAndSaveData"
268
- ]
269
- },
270
- {
271
- "cell_type": "markdown",
272
- "metadata": {},
273
- "source": [
274
- "## Gradio Interface\n",
275
- "This launches the UI, you will probably need to allow the browser to use the microphone to enable the audio functions."
276
- ]
277
- },
278
- {
279
- "cell_type": "code",
280
- "execution_count": 5,
281
- "metadata": {},
282
- "outputs": [
283
- {
284
- "ename": "NameError",
285
- "evalue": "name 'ChatBot' is not defined",
286
- "output_type": "error",
287
- "traceback": [
288
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
289
- "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
290
- "Cell \u001b[0;32mIn[5], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;124;03m\"\"\"Run Chatbot app\"\"\"\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m chatbot \u001b[38;5;241m=\u001b[39m \u001b[43mChatBot\u001b[49m(enable_speakers\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m, threaded\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m 3\u001b[0m history \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_response\u001b[39m(audio):\n",
291
- "\u001b[0;31mNameError\u001b[0m: name 'ChatBot' is not defined"
292
- ]
293
- }
294
- ],
295
- "source": [
296
- "\"\"\"Run Chatbot app\"\"\"\n",
297
- "chatbot = ChatBot(enable_speakers=True, threaded=True)\n",
298
- "history = []\n",
299
- "\n",
300
- "def get_response(audio):\n",
301
- " \"\"\"Get Audio Response From Chatbot\"\"\"\n",
302
- " if not audio:\n",
303
- " raise ValueError(\"No audio file provided.\")\n",
304
- " prompt = chatbot.get_prompt_from_gradio_audio(audio)\n",
305
- " log(f\"Transcribed prompt: {prompt}\", log_level=LogLevels.ON)\n",
306
- " response = chatbot.respond(prompt, history)\n",
307
- " log(f\"Chatbot response: {response}\", log_level=LogLevels.ON)\n",
308
- " history.append([prompt, response])\n",
309
- " return response\n",
310
- "\n",
311
- "demo = gr.Interface(\n",
312
- " get_response,\n",
313
- " gr.Audio(sources=\"microphone\"),\n",
314
- " None,\n",
315
- " title=\"Wanderwise Travel Assistant\"\n",
316
- ")\n",
317
- "demo.launch()"
318
- ]
319
- },
320
- {
321
- "cell_type": "code",
322
- "execution_count": null,
323
- "metadata": {},
324
- "outputs": [],
325
- "source": []
326
- }
327
- ],
328
- "metadata": {
329
- "kernelspec": {
330
- "display_name": "Python 3 (ipykernel)",
331
- "language": "python",
332
- "name": "python3"
333
- },
334
- "language_info": {
335
- "codemirror_mode": {
336
- "name": "ipython",
337
- "version": 3
338
- },
339
- "file_extension": ".py",
340
- "mimetype": "text/x-python",
341
- "name": "python",
342
- "nbconvert_exporter": "python",
343
- "pygments_lexer": "ipython3",
344
- "version": "3.9.7"
345
- }
346
- },
347
- "nbformat": 4,
348
- "nbformat_minor": 4
349
- }