Spaces:
Sleeping
Sleeping
avnishkanungo
commited on
Commit
•
7c30d23
1
Parent(s):
6bdf49f
Upload folder using huggingface_hub
Browse files- NLToSQL.py +1 -0
- NLToSQL_test.ipynb +6 -6
- app.py +35 -20
- gradio_demo.ipynb +529 -16
- requirements.txt +276 -16
NLToSQL.py
CHANGED
@@ -226,6 +226,7 @@ def install_libportaudio():
|
|
226 |
|
227 |
if __name__ == '__main__':
|
228 |
|
|
|
229 |
parser = ArgumentParser()
|
230 |
parser.add_argument('--example_path', type=str, default=os.getcwd()+"/few_shot_samples.json")
|
231 |
parser.add_argument('--desc_path', type=str, default=os.getcwd()+"/database_table_descriptions.csv")
|
|
|
226 |
|
227 |
if __name__ == '__main__':
|
228 |
|
229 |
+
# Please configure your DB credentials and paths of the files for few shot learning and fine tuning
|
230 |
parser = ArgumentParser()
|
231 |
parser.add_argument('--example_path', type=str, default=os.getcwd()+"/few_shot_samples.json")
|
232 |
parser.add_argument('--desc_path', type=str, default=os.getcwd()+"/database_table_descriptions.csv")
|
NLToSQL_test.ipynb
CHANGED
@@ -317,14 +317,14 @@
|
|
317 |
},
|
318 |
{
|
319 |
"cell_type": "code",
|
320 |
-
"execution_count":
|
321 |
"metadata": {},
|
322 |
"outputs": [
|
323 |
{
|
324 |
"name": "stdout",
|
325 |
"output_type": "stream",
|
326 |
"text": [
|
327 |
-
"(
|
328 |
]
|
329 |
}
|
330 |
],
|
@@ -332,13 +332,13 @@
|
|
332 |
"import mysql.connector\n",
|
333 |
"\n",
|
334 |
"# Create a connection to the MySQL server\n",
|
335 |
-
"conn = mysql.connector.connect(user='
|
336 |
"\n",
|
337 |
"# Create a cursor to interact with the MySQL server\n",
|
338 |
"cursor = conn.cursor()\n",
|
339 |
"\n",
|
340 |
"# Execute the SELECT query\n",
|
341 |
-
"cursor.execute(\"SELECT COUNT(*) AS numberOfEmployees FROM employees
|
342 |
"\n",
|
343 |
"# Fetch all the results\n",
|
344 |
"records = cursor.fetchall()\n",
|
@@ -361,7 +361,7 @@
|
|
361 |
},
|
362 |
{
|
363 |
"cell_type": "code",
|
364 |
-
"execution_count":
|
365 |
"metadata": {},
|
366 |
"outputs": [
|
367 |
{
|
@@ -547,7 +547,7 @@
|
|
547 |
"import os\n",
|
548 |
"\n",
|
549 |
"db_user = \"root\"\n",
|
550 |
-
"db_password = \"
|
551 |
"db_host = \"localhost\"\n",
|
552 |
"db_name = \"classicmodels\"\n",
|
553 |
"from langchain_community.utilities.sql_database import SQLDatabase\n",
|
|
|
317 |
},
|
318 |
{
|
319 |
"cell_type": "code",
|
320 |
+
"execution_count": 34,
|
321 |
"metadata": {},
|
322 |
"outputs": [
|
323 |
{
|
324 |
"name": "stdout",
|
325 |
"output_type": "stream",
|
326 |
"text": [
|
327 |
+
"(23,)\n"
|
328 |
]
|
329 |
}
|
330 |
],
|
|
|
332 |
"import mysql.connector\n",
|
333 |
"\n",
|
334 |
"# Create a connection to the MySQL server\n",
|
335 |
+
"conn = mysql.connector.connect(user='admin', password = 'avnishk96' ,host='demo-db.cdm44iseol25.us-east-1.rds.amazonaws.com', database='classicmodels')\n",
|
336 |
"\n",
|
337 |
"# Create a cursor to interact with the MySQL server\n",
|
338 |
"cursor = conn.cursor()\n",
|
339 |
"\n",
|
340 |
"# Execute the SELECT query\n",
|
341 |
+
"cursor.execute(\"SELECT COUNT(*) AS numberOfEmployees FROM employees;\")\n",
|
342 |
"\n",
|
343 |
"# Fetch all the results\n",
|
344 |
"records = cursor.fetchall()\n",
|
|
|
361 |
},
|
362 |
{
|
363 |
"cell_type": "code",
|
364 |
+
"execution_count": 36,
|
365 |
"metadata": {},
|
366 |
"outputs": [
|
367 |
{
|
|
|
547 |
"import os\n",
|
548 |
"\n",
|
549 |
"db_user = \"root\"\n",
|
550 |
+
"db_password = \"\"\n",
|
551 |
"db_host = \"localhost\"\n",
|
552 |
"db_name = \"classicmodels\"\n",
|
553 |
"from langchain_community.utilities.sql_database import SQLDatabase\n",
|
app.py
CHANGED
@@ -226,9 +226,9 @@ def sql_translator(filepath, key):
|
|
226 |
return True
|
227 |
|
228 |
|
229 |
-
db_user = "
|
230 |
-
db_password = ""
|
231 |
-
db_host = "
|
232 |
db_name = "classicmodels"
|
233 |
|
234 |
db = SQLDatabase.from_uri(f"mysql+pymysql://{db_user}:{db_password}@{db_host}/{db_name}")
|
@@ -265,7 +265,12 @@ def sql_translator(filepath, key):
|
|
265 |
else:
|
266 |
print("libportaudio installation failed. Please install it manually.")
|
267 |
|
268 |
-
|
|
|
|
|
|
|
|
|
|
|
269 |
chain = (
|
270 |
RunnablePassthrough.assign(table_names_to_use=select_table(os.getcwd()+"/database_table_descriptions.csv")) |
|
271 |
RunnablePassthrough.assign(query=generate_query).assign(
|
@@ -282,25 +287,35 @@ def sql_translator(filepath, key):
|
|
282 |
|
283 |
|
284 |
def create_interface():
|
285 |
-
with gr.Blocks() as interface:
|
286 |
-
gr.Markdown("## Audio and Text Processing Interface")
|
287 |
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
|
300 |
-
|
301 |
-
|
|
|
|
|
|
|
|
|
|
|
302 |
|
303 |
-
return interface
|
304 |
|
305 |
|
306 |
if __name__ == "__main__":
|
|
|
226 |
return True
|
227 |
|
228 |
|
229 |
+
db_user = "admin"
|
230 |
+
db_password = "avnishk96"
|
231 |
+
db_host = "demo-db.cdm44iseol25.us-east-1.rds.amazonaws.com"
|
232 |
db_name = "classicmodels"
|
233 |
|
234 |
db = SQLDatabase.from_uri(f"mysql+pymysql://{db_user}:{db_password}@{db_host}/{db_name}")
|
|
|
265 |
else:
|
266 |
print("libportaudio installation failed. Please install it manually.")
|
267 |
|
268 |
+
if os.path.isfile(filepath):
|
269 |
+
sql_query = transcribe_speech(filepath)
|
270 |
+
else:
|
271 |
+
sql_query = filepath
|
272 |
+
|
273 |
+
# sql_query = transcribe_speech(filepath)
|
274 |
chain = (
|
275 |
RunnablePassthrough.assign(table_names_to_use=select_table(os.getcwd()+"/database_table_descriptions.csv")) |
|
276 |
RunnablePassthrough.assign(query=generate_query).assign(
|
|
|
287 |
|
288 |
|
289 |
def create_interface():
|
|
|
|
|
290 |
|
291 |
+
demo = gr.Blocks()
|
292 |
+
|
293 |
+
mic_transcribe = gr.Interface(
|
294 |
+
fn=sql_translator,
|
295 |
+
# key_input = gr.Textbox(lines=2, placeholder="Enter text here...", label="Open AI Key"),
|
296 |
+
# audio_input = gr.Audio(sources="microphone", type="filepath"),
|
297 |
+
inputs = [gr.Audio(sources="microphone", type="filepath"),gr.Textbox(lines=2, placeholder="Enter text here...", label="Open AI Key")],
|
298 |
+
outputs=gr.components.Textbox(),
|
299 |
+
)
|
300 |
+
|
301 |
+
file_transcribe = gr.Interface(
|
302 |
+
fn=sql_translator,
|
303 |
+
# key_input = gr.Textbox(lines=2, placeholder="Enter text here...", label="Open AI Key"),
|
304 |
+
# query_input = gr.Textbox(lines=2, placeholder="Enter text here...", label="Input Text..."),
|
305 |
+
inputs = [gr.Textbox(lines=2, placeholder="Enter text here...", label="Input Text...") ,gr.Textbox(lines=2, placeholder="Enter text here...", label="Open AI Key")],
|
306 |
+
# inputs=gr.Audio(sources="upload", type="filepath"),
|
307 |
+
outputs=gr.components.Textbox(),
|
308 |
+
)
|
309 |
|
310 |
+
with demo:
|
311 |
+
gr.TabbedInterface(
|
312 |
+
[mic_transcribe, file_transcribe],
|
313 |
+
["Transcribe Microphone", "Transcribe Audio File"],
|
314 |
+
)
|
315 |
+
|
316 |
+
demo.launch(debug=True)
|
317 |
|
318 |
+
# return interface
|
319 |
|
320 |
|
321 |
if __name__ == "__main__":
|
gradio_demo.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
@@ -43,7 +43,7 @@
|
|
43 |
},
|
44 |
{
|
45 |
"cell_type": "code",
|
46 |
-
"execution_count":
|
47 |
"metadata": {},
|
48 |
"outputs": [
|
49 |
{
|
@@ -63,7 +63,7 @@
|
|
63 |
},
|
64 |
{
|
65 |
"cell_type": "code",
|
66 |
-
"execution_count":
|
67 |
"metadata": {},
|
68 |
"outputs": [],
|
69 |
"source": [
|
@@ -105,7 +105,7 @@
|
|
105 |
},
|
106 |
{
|
107 |
"cell_type": "code",
|
108 |
-
"execution_count":
|
109 |
"metadata": {},
|
110 |
"outputs": [],
|
111 |
"source": [
|
@@ -156,7 +156,7 @@
|
|
156 |
},
|
157 |
{
|
158 |
"cell_type": "code",
|
159 |
-
"execution_count":
|
160 |
"metadata": {},
|
161 |
"outputs": [],
|
162 |
"source": [
|
@@ -177,7 +177,7 @@
|
|
177 |
},
|
178 |
{
|
179 |
"cell_type": "code",
|
180 |
-
"execution_count":
|
181 |
"metadata": {},
|
182 |
"outputs": [],
|
183 |
"source": [
|
@@ -210,7 +210,7 @@
|
|
210 |
},
|
211 |
{
|
212 |
"cell_type": "code",
|
213 |
-
"execution_count":
|
214 |
"metadata": {},
|
215 |
"outputs": [],
|
216 |
"source": [
|
@@ -258,11 +258,12 @@
|
|
258 |
},
|
259 |
{
|
260 |
"cell_type": "code",
|
261 |
-
"execution_count":
|
262 |
"metadata": {},
|
263 |
"outputs": [],
|
264 |
"source": [
|
265 |
"def sql_translator(filepath,key):\n",
|
|
|
266 |
" db_user = \"root\"\n",
|
267 |
" db_password = \"\"\n",
|
268 |
" db_host = \"localhost\"\n",
|
@@ -302,7 +303,7 @@
|
|
302 |
},
|
303 |
{
|
304 |
"cell_type": "code",
|
305 |
-
"execution_count":
|
306 |
"metadata": {},
|
307 |
"outputs": [],
|
308 |
"source": [
|
@@ -311,10 +312,19 @@
|
|
311 |
" gr.Markdown(\"## Audio and Text Processing Interface\")\n",
|
312 |
"\n",
|
313 |
" # Text input component\n",
|
314 |
-
" text_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"
|
315 |
" \n",
|
316 |
" # Audio input component\n",
|
317 |
" audio_input = gr.Audio(sources=\"microphone\", type=\"filepath\", label=\"Record or Upload Audio\")\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
" \n",
|
319 |
" # Button to trigger processing\n",
|
320 |
" process_button = gr.Button(\"Process\")\n",
|
@@ -328,15 +338,31 @@
|
|
328 |
" return interface"
|
329 |
]
|
330 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
{
|
332 |
"cell_type": "code",
|
333 |
-
"execution_count":
|
334 |
"metadata": {},
|
335 |
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
{
|
337 |
"data": {
|
338 |
"text/html": [
|
339 |
-
"<div><iframe src=\"
|
340 |
],
|
341 |
"text/plain": [
|
342 |
"<IPython.core.display.HTML object>"
|
@@ -345,27 +371,514 @@
|
|
345 |
"metadata": {},
|
346 |
"output_type": "display_data"
|
347 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
{
|
349 |
"data": {
|
350 |
"text/plain": []
|
351 |
},
|
352 |
-
"execution_count":
|
353 |
"metadata": {},
|
354 |
"output_type": "execute_result"
|
355 |
}
|
356 |
],
|
357 |
"source": [
|
358 |
"interface = create_interface()\n",
|
359 |
-
"interface.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
360 |
]
|
361 |
},
|
362 |
{
|
363 |
"cell_type": "code",
|
364 |
-
"execution_count":
|
365 |
"metadata": {},
|
366 |
"outputs": [],
|
367 |
"source": [
|
368 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
]
|
370 |
},
|
371 |
{
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
|
|
43 |
},
|
44 |
{
|
45 |
"cell_type": "code",
|
46 |
+
"execution_count": 2,
|
47 |
"metadata": {},
|
48 |
"outputs": [
|
49 |
{
|
|
|
63 |
},
|
64 |
{
|
65 |
"cell_type": "code",
|
66 |
+
"execution_count": 3,
|
67 |
"metadata": {},
|
68 |
"outputs": [],
|
69 |
"source": [
|
|
|
105 |
},
|
106 |
{
|
107 |
"cell_type": "code",
|
108 |
+
"execution_count": 4,
|
109 |
"metadata": {},
|
110 |
"outputs": [],
|
111 |
"source": [
|
|
|
156 |
},
|
157 |
{
|
158 |
"cell_type": "code",
|
159 |
+
"execution_count": 5,
|
160 |
"metadata": {},
|
161 |
"outputs": [],
|
162 |
"source": [
|
|
|
177 |
},
|
178 |
{
|
179 |
"cell_type": "code",
|
180 |
+
"execution_count": 6,
|
181 |
"metadata": {},
|
182 |
"outputs": [],
|
183 |
"source": [
|
|
|
210 |
},
|
211 |
{
|
212 |
"cell_type": "code",
|
213 |
+
"execution_count": 7,
|
214 |
"metadata": {},
|
215 |
"outputs": [],
|
216 |
"source": [
|
|
|
258 |
},
|
259 |
{
|
260 |
"cell_type": "code",
|
261 |
+
"execution_count": 8,
|
262 |
"metadata": {},
|
263 |
"outputs": [],
|
264 |
"source": [
|
265 |
"def sql_translator(filepath,key):\n",
|
266 |
+
" # Please configure your DB credentials and paths of the files for few shot learning and fine tuning\n",
|
267 |
" db_user = \"root\"\n",
|
268 |
" db_password = \"\"\n",
|
269 |
" db_host = \"localhost\"\n",
|
|
|
303 |
},
|
304 |
{
|
305 |
"cell_type": "code",
|
306 |
+
"execution_count": 17,
|
307 |
"metadata": {},
|
308 |
"outputs": [],
|
309 |
"source": [
|
|
|
312 |
" gr.Markdown(\"## Audio and Text Processing Interface\")\n",
|
313 |
"\n",
|
314 |
" # Text input component\n",
|
315 |
+
" text_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Open AI Key\")\n",
|
316 |
" \n",
|
317 |
" # Audio input component\n",
|
318 |
" audio_input = gr.Audio(sources=\"microphone\", type=\"filepath\", label=\"Record or Upload Audio\")\n",
|
319 |
+
"\n",
|
320 |
+
" # with gr.TabbedInterface([\"Audio Input\", \"Text Input\"]) as tabs:\n",
|
321 |
+
" # with gr.Tab(\"Audio Input\"):\n",
|
322 |
+
" # audio_input = gr.Audio(source=\"microphone\", type=\"filepath\", label=\"Record or Upload Audio\")\n",
|
323 |
+
" # selected_input = audio_input # Reference to the selected input component\n",
|
324 |
+
"\n",
|
325 |
+
" # with gr.Tab(\"Text Input\"):\n",
|
326 |
+
" # query_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Input Text\")\n",
|
327 |
+
" # selected_input = query_input # Reference to the selected input component\n",
|
328 |
" \n",
|
329 |
" # Button to trigger processing\n",
|
330 |
" process_button = gr.Button(\"Process\")\n",
|
|
|
338 |
" return interface"
|
339 |
]
|
340 |
},
|
341 |
+
{
|
342 |
+
"cell_type": "markdown",
|
343 |
+
"metadata": {},
|
344 |
+
"source": [
|
345 |
+
"# Just Audio UI"
|
346 |
+
]
|
347 |
+
},
|
348 |
{
|
349 |
"cell_type": "code",
|
350 |
+
"execution_count": 18,
|
351 |
"metadata": {},
|
352 |
"outputs": [
|
353 |
+
{
|
354 |
+
"name": "stdout",
|
355 |
+
"output_type": "stream",
|
356 |
+
"text": [
|
357 |
+
"Running on local URL: http://127.0.0.1:7861\n",
|
358 |
+
"\n",
|
359 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
360 |
+
]
|
361 |
+
},
|
362 |
{
|
363 |
"data": {
|
364 |
"text/html": [
|
365 |
+
"<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
366 |
],
|
367 |
"text/plain": [
|
368 |
"<IPython.core.display.HTML object>"
|
|
|
371 |
"metadata": {},
|
372 |
"output_type": "display_data"
|
373 |
},
|
374 |
+
{
|
375 |
+
"name": "stdout",
|
376 |
+
"output_type": "stream",
|
377 |
+
"text": [
|
378 |
+
"Keyboard interruption in main thread... closing server.\n"
|
379 |
+
]
|
380 |
+
},
|
381 |
{
|
382 |
"data": {
|
383 |
"text/plain": []
|
384 |
},
|
385 |
+
"execution_count": 18,
|
386 |
"metadata": {},
|
387 |
"output_type": "execute_result"
|
388 |
}
|
389 |
],
|
390 |
"source": [
|
391 |
"interface = create_interface()\n",
|
392 |
+
"interface.launch(debug=True)"
|
393 |
+
]
|
394 |
+
},
|
395 |
+
{
|
396 |
+
"cell_type": "markdown",
|
397 |
+
"metadata": {},
|
398 |
+
"source": [
|
399 |
+
"# Audio and Text UI(Version 1)"
|
400 |
]
|
401 |
},
|
402 |
{
|
403 |
"cell_type": "code",
|
404 |
+
"execution_count": 9,
|
405 |
"metadata": {},
|
406 |
"outputs": [],
|
407 |
"source": [
|
408 |
+
"demo = gr.Blocks()\n",
|
409 |
+
"\n",
|
410 |
+
"# key_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Open AI Key\")\n",
|
411 |
+
"# audio_input = gr.Audio(sources=\"microphone\", type=\"filepath\")\n",
|
412 |
+
"# query_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Input Text...\")\n",
|
413 |
+
"\n",
|
414 |
+
"mic_transcribe = gr.Interface(\n",
|
415 |
+
" fn=sql_translator,\n",
|
416 |
+
" # key_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Open AI Key\"),\n",
|
417 |
+
" # audio_input = gr.Audio(sources=\"microphone\", type=\"filepath\"),\n",
|
418 |
+
" inputs = [gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Open AI Key\"), gr.Audio(sources=\"microphone\", type=\"filepath\")],\n",
|
419 |
+
" outputs=gr.components.Textbox(),\n",
|
420 |
+
")\n",
|
421 |
+
"\n",
|
422 |
+
"file_transcribe = gr.Interface(\n",
|
423 |
+
" fn=sql_translator,\n",
|
424 |
+
" # key_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Open AI Key\"),\n",
|
425 |
+
" # query_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Input Text...\"),\n",
|
426 |
+
" inputs = [gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Open AI Key\"), gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Input Text...\")],\n",
|
427 |
+
" # inputs=gr.Audio(sources=\"upload\", type=\"filepath\"),\n",
|
428 |
+
" outputs=gr.components.Textbox(),\n",
|
429 |
+
")\n",
|
430 |
+
"\n"
|
431 |
+
]
|
432 |
+
},
|
433 |
+
{
|
434 |
+
"cell_type": "code",
|
435 |
+
"execution_count": 10,
|
436 |
+
"metadata": {},
|
437 |
+
"outputs": [
|
438 |
+
{
|
439 |
+
"name": "stdout",
|
440 |
+
"output_type": "stream",
|
441 |
+
"text": [
|
442 |
+
"Running on local URL: http://127.0.0.1:7861\n",
|
443 |
+
"\n",
|
444 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
445 |
+
]
|
446 |
+
},
|
447 |
+
{
|
448 |
+
"data": {
|
449 |
+
"text/html": [
|
450 |
+
"<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
451 |
+
],
|
452 |
+
"text/plain": [
|
453 |
+
"<IPython.core.display.HTML object>"
|
454 |
+
]
|
455 |
+
},
|
456 |
+
"metadata": {},
|
457 |
+
"output_type": "display_data"
|
458 |
+
},
|
459 |
+
{
|
460 |
+
"name": "stdout",
|
461 |
+
"output_type": "stream",
|
462 |
+
"text": [
|
463 |
+
"Keyboard interruption in main thread... closing server.\n"
|
464 |
+
]
|
465 |
+
},
|
466 |
+
{
|
467 |
+
"data": {
|
468 |
+
"text/plain": []
|
469 |
+
},
|
470 |
+
"execution_count": 10,
|
471 |
+
"metadata": {},
|
472 |
+
"output_type": "execute_result"
|
473 |
+
}
|
474 |
+
],
|
475 |
+
"source": [
|
476 |
+
"with demo:\n",
|
477 |
+
" gr.TabbedInterface(\n",
|
478 |
+
" [mic_transcribe, file_transcribe],\n",
|
479 |
+
" [\"Transcribe Microphone\", \"Transcribe Audio File\"],\n",
|
480 |
+
" )\n",
|
481 |
+
"\n",
|
482 |
+
"demo.launch(debug=True)"
|
483 |
+
]
|
484 |
+
},
|
485 |
+
{
|
486 |
+
"cell_type": "markdown",
|
487 |
+
"metadata": {},
|
488 |
+
"source": [
|
489 |
+
"# Audio and Text UI (Version 2)\n",
|
490 |
+
"## Run all the 3 cells below:"
|
491 |
+
]
|
492 |
+
},
|
493 |
+
{
|
494 |
+
"cell_type": "code",
|
495 |
+
"execution_count": 19,
|
496 |
+
"metadata": {},
|
497 |
+
"outputs": [],
|
498 |
+
"source": [
|
499 |
+
"def create_new_interface(translate_function):\n",
|
500 |
+
" demo = gr.Blocks()\n",
|
501 |
+
" \n",
|
502 |
+
" # demo = gr.Blocks()\n",
|
503 |
+
"\n",
|
504 |
+
"# key_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Open AI Key\")\n",
|
505 |
+
"# audio_input = gr.Audio(sources=\"microphone\", type=\"filepath\")\n",
|
506 |
+
"# query_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Input Text...\")\n",
|
507 |
+
"\n",
|
508 |
+
" mic_transcribe = gr.Interface(\n",
|
509 |
+
" fn=translate_function,\n",
|
510 |
+
" # key_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Open AI Key\"),\n",
|
511 |
+
" # audio_input = gr.Audio(sources=\"microphone\", type=\"filepath\"),\n",
|
512 |
+
" inputs = [gr.Audio(sources=\"microphone\", type=\"filepath\"),gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Open AI Key\")],\n",
|
513 |
+
" outputs=gr.components.Textbox(),\n",
|
514 |
+
" )\n",
|
515 |
+
"\n",
|
516 |
+
" file_transcribe = gr.Interface(\n",
|
517 |
+
" fn=translate_function,\n",
|
518 |
+
" # key_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Open AI Key\"),\n",
|
519 |
+
" # query_input = gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Input Text...\"),\n",
|
520 |
+
" inputs = [gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Input Text...\") ,gr.Textbox(lines=2, placeholder=\"Enter text here...\", label=\"Open AI Key\")],\n",
|
521 |
+
" # inputs=gr.Audio(sources=\"upload\", type=\"filepath\"),\n",
|
522 |
+
" outputs=gr.components.Textbox(),\n",
|
523 |
+
" )\n",
|
524 |
+
"\n",
|
525 |
+
" with demo:\n",
|
526 |
+
" gr.TabbedInterface(\n",
|
527 |
+
" [mic_transcribe, file_transcribe],\n",
|
528 |
+
" [\"Transcribe Microphone\", \"Transcribe Audio File\"],\n",
|
529 |
+
" )\n",
|
530 |
+
" \n",
|
531 |
+
" demo.launch(debug=True)\n",
|
532 |
+
"\n",
|
533 |
+
" # return interface"
|
534 |
+
]
|
535 |
+
},
|
536 |
+
{
|
537 |
+
"cell_type": "code",
|
538 |
+
"execution_count": 23,
|
539 |
+
"metadata": {},
|
540 |
+
"outputs": [],
|
541 |
+
"source": [
|
542 |
+
"def sql_translator1(filepath, key): \n",
|
543 |
+
" def select_table(desc_path):\n",
|
544 |
+
" def get_table_details():\n",
|
545 |
+
" # Read the CSV file into a DataFrame\n",
|
546 |
+
" table_description = pd.read_csv(desc_path) ##\"/teamspace/studios/this_studio/database_table_descriptions.csv\"\n",
|
547 |
+
" table_docs = []\n",
|
548 |
+
"\n",
|
549 |
+
" # Iterate over the DataFrame rows to create Document objects\n",
|
550 |
+
" table_details = \"\"\n",
|
551 |
+
" for index, row in table_description.iterrows():\n",
|
552 |
+
" table_details = table_details + \"Table Name:\" + row['Table'] + \"\\n\" + \"Table Description:\" + row['Description'] + \"\\n\\n\"\n",
|
553 |
+
"\n",
|
554 |
+
" return table_details\n",
|
555 |
+
" \n",
|
556 |
+
" class Table(BaseModel):\n",
|
557 |
+
" \"\"\"Table in SQL database.\"\"\"\n",
|
558 |
+
"\n",
|
559 |
+
" name: str = Field(description=\"Name of table in SQL database.\")\n",
|
560 |
+
" \n",
|
561 |
+
" table_details_prompt = f\"\"\"Return the names of ALL the SQL tables that MIGHT be relevant to the user question. \\\n",
|
562 |
+
" The tables are:\n",
|
563 |
+
"\n",
|
564 |
+
" {get_table_details()}\n",
|
565 |
+
"\n",
|
566 |
+
" Remember to include ALL POTENTIALLY RELEVANT tables, even if you're not sure that they're needed.\"\"\"\n",
|
567 |
+
"\n",
|
568 |
+
" table_chain = create_extraction_chain_pydantic(Table, llm, system_message=table_details_prompt)\n",
|
569 |
+
" \n",
|
570 |
+
" def get_tables(tables: List[Table]) -> List[str]:\n",
|
571 |
+
" tables = [table.name for table in tables]\n",
|
572 |
+
" return tables\n",
|
573 |
+
"\n",
|
574 |
+
" select_table = {\"input\": itemgetter(\"question\")} | create_extraction_chain_pydantic(Table, llm, system_message=table_details_prompt) | get_tables\n",
|
575 |
+
"\n",
|
576 |
+
" return select_table\n",
|
577 |
+
"\n",
|
578 |
+
"\n",
|
579 |
+
" def prompt_creation(example_path):\n",
|
580 |
+
"\n",
|
581 |
+
" with open(example_path, 'r') as file: ##'/teamspace/studios/this_studio/few_shot_samples.json'\n",
|
582 |
+
" data = json.load(file)\n",
|
583 |
+
"\n",
|
584 |
+
" examples = data[\"examples\"]\n",
|
585 |
+
"\n",
|
586 |
+
" example_prompt = ChatPromptTemplate.from_messages(\n",
|
587 |
+
" [\n",
|
588 |
+
" (\"human\", \"{input}\\nSQLQuery:\"),\n",
|
589 |
+
" (\"ai\", \"{query}\"),\n",
|
590 |
+
" ]\n",
|
591 |
+
" )\n",
|
592 |
+
"\n",
|
593 |
+
" vectorstore = Chroma()\n",
|
594 |
+
" vectorstore.delete_collection()\n",
|
595 |
+
" example_selector = SemanticSimilarityExampleSelector.from_examples(\n",
|
596 |
+
" examples,\n",
|
597 |
+
" OpenAIEmbeddings(),\n",
|
598 |
+
" vectorstore,\n",
|
599 |
+
" k=2,\n",
|
600 |
+
" input_keys=[\"input\"],\n",
|
601 |
+
" )\n",
|
602 |
+
" \n",
|
603 |
+
" few_shot_prompt = FewShotChatMessagePromptTemplate(\n",
|
604 |
+
" example_prompt=example_prompt,\n",
|
605 |
+
" example_selector=example_selector,\n",
|
606 |
+
" input_variables=[\"input\",\"top_k\"],\n",
|
607 |
+
" )\n",
|
608 |
+
"\n",
|
609 |
+
"\n",
|
610 |
+
" final_prompt = ChatPromptTemplate.from_messages(\n",
|
611 |
+
" [\n",
|
612 |
+
" (\"system\", \"You are a MySQL expert. Given an input question, create a syntactically correct MySQL query to run. Unless otherwise specificed.\\n\\nHere is the relevant table info: {table_info}\\n\\nBelow are a number of examples of questions and their corresponding SQL queries.\"),\n",
|
613 |
+
" few_shot_prompt,\n",
|
614 |
+
" MessagesPlaceholder(variable_name=\"messages\"),\n",
|
615 |
+
" (\"human\", \"{input}\"),\n",
|
616 |
+
" ]\n",
|
617 |
+
" )\n",
|
618 |
+
"\n",
|
619 |
+
" print(few_shot_prompt.format(input=\"How many products are there?\"))\n",
|
620 |
+
" \n",
|
621 |
+
" return final_prompt\n",
|
622 |
+
"\n",
|
623 |
+
" def rephrase_answer():\n",
|
624 |
+
" answer_prompt = PromptTemplate.from_template(\n",
|
625 |
+
" \"\"\"Given the following user question, corresponding SQL query, and SQL result, answer the user question.\n",
|
626 |
+
"\n",
|
627 |
+
" Question: {question}\n",
|
628 |
+
" SQL Query: {query}\n",
|
629 |
+
" SQL Result: {result}\n",
|
630 |
+
" Answer: \"\"\"\n",
|
631 |
+
" )\n",
|
632 |
+
"\n",
|
633 |
+
" rephrase_answer = answer_prompt | llm | StrOutputParser()\n",
|
634 |
+
"\n",
|
635 |
+
" return rephrase_answer\n",
|
636 |
+
"\n",
|
637 |
+
"\n",
|
638 |
+
" def is_ffmpeg_installed():\n",
|
639 |
+
" try:\n",
|
640 |
+
" # Run `ffmpeg -version` to check if ffmpeg is installed\n",
|
641 |
+
" subprocess.run(['ffmpeg', '-version'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
|
642 |
+
" return True\n",
|
643 |
+
" except (subprocess.CalledProcessError, FileNotFoundError):\n",
|
644 |
+
" return False\n",
|
645 |
+
"\n",
|
646 |
+
" def install_ffmpeg():\n",
|
647 |
+
" try:\n",
|
648 |
+
" if sys.platform.startswith('linux'):\n",
|
649 |
+
" subprocess.run(['sudo', 'apt-get', 'update'], check=True)\n",
|
650 |
+
" subprocess.run(['sudo', 'apt-get', 'install', '-y', 'ffmpeg'], check=True)\n",
|
651 |
+
" elif sys.platform == 'darwin': # macOS\n",
|
652 |
+
" subprocess.run(['/bin/bash', '-c', 'brew install ffmpeg'], check=True)\n",
|
653 |
+
" elif sys.platform == 'win32':\n",
|
654 |
+
" print(\"Please download ffmpeg from https://ffmpeg.org/download.html and install it manually.\")\n",
|
655 |
+
" return False\n",
|
656 |
+
" else:\n",
|
657 |
+
" print(\"Unsupported OS. Please install ffmpeg manually.\")\n",
|
658 |
+
" return False\n",
|
659 |
+
" except subprocess.CalledProcessError as e:\n",
|
660 |
+
" print(f\"Failed to install ffmpeg: {e}\")\n",
|
661 |
+
" return False\n",
|
662 |
+
" return True\n",
|
663 |
+
"\n",
|
664 |
+
" def transcribe_speech(filepath):\n",
|
665 |
+
" output = pipe(\n",
|
666 |
+
" filepath,\n",
|
667 |
+
" max_new_tokens=256,\n",
|
668 |
+
" generate_kwargs={\n",
|
669 |
+
" \"task\": \"transcribe\",\n",
|
670 |
+
" \"language\": \"english\",\n",
|
671 |
+
" }, # update with the language you've fine-tuned on\n",
|
672 |
+
" chunk_length_s=30,\n",
|
673 |
+
" batch_size=8,\n",
|
674 |
+
" )\n",
|
675 |
+
" return output[\"text\"]\n",
|
676 |
+
" \n",
|
677 |
+
" # def record_command():\n",
|
678 |
+
" # sample_rate = 16000 # Sample rate in Hz\n",
|
679 |
+
" # duration = 8 # Duration in seconds\n",
|
680 |
+
"\n",
|
681 |
+
" # print(\"Recording...\")\n",
|
682 |
+
"\n",
|
683 |
+
" # # Record audio\n",
|
684 |
+
" # audio = sd.rec(int(sample_rate * duration), samplerate=sample_rate, channels=1, dtype='float32')\n",
|
685 |
+
" # sd.wait() # Wait until recording is finished\n",
|
686 |
+
"\n",
|
687 |
+
" # print(\"Recording finished\")\n",
|
688 |
+
"\n",
|
689 |
+
" # # Convert the audio to a binary stream and save it to a variable\n",
|
690 |
+
" # audio_buffer = io.BytesIO()\n",
|
691 |
+
" # soundfile.write(audio_buffer, audio, sample_rate, format='WAV')\n",
|
692 |
+
" # audio_buffer.seek(0) # Reset buffer position to the beginning\n",
|
693 |
+
"\n",
|
694 |
+
" # # The audio file is now saved in audio_buffer\n",
|
695 |
+
" # # You can read it again using soundfile or any other audio library\n",
|
696 |
+
" # audio_data, sample_rate = soundfile.read(audio_buffer)\n",
|
697 |
+
"\n",
|
698 |
+
" # # Optional: Save the audio to a file for verification\n",
|
699 |
+
" # # with open('recorded_audio.wav', 'wb') as f:\n",
|
700 |
+
" # # f.write(audio_buffer.getbuffer())\n",
|
701 |
+
"\n",
|
702 |
+
" # print(\"Audio saved to variable\")\n",
|
703 |
+
" # return audio_data\n",
|
704 |
+
" \n",
|
705 |
+
" def check_libportaudio_installed():\n",
|
706 |
+
" try:\n",
|
707 |
+
" # Run `ffmpeg -version` to check if ffmpeg is installed\n",
|
708 |
+
" subprocess.run(['libportaudio2', '-version'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
|
709 |
+
" return True\n",
|
710 |
+
" except (subprocess.CalledProcessError, FileNotFoundError):\n",
|
711 |
+
" return False\n",
|
712 |
+
"\n",
|
713 |
+
" def install_libportaudio():\n",
|
714 |
+
" try:\n",
|
715 |
+
" if sys.platform.startswith('linux'):\n",
|
716 |
+
" subprocess.run(['sudo', 'apt-get', 'update'], check=True)\n",
|
717 |
+
" subprocess.run(['sudo', 'apt-get', 'install', '-y', 'libportaudio2'], check=True)\n",
|
718 |
+
" elif sys.platform == 'darwin': # macOS\n",
|
719 |
+
" subprocess.run(['/bin/bash', '-c', 'brew install portaudio'], check=True)\n",
|
720 |
+
" elif sys.platform == 'win32':\n",
|
721 |
+
" print(\"Please download ffmpeg from https://ffmpeg.org/download.html and install it manually.\")\n",
|
722 |
+
" return False\n",
|
723 |
+
" else:\n",
|
724 |
+
" print(\"Unsupported OS. Please install ffmpeg manually.\")\n",
|
725 |
+
" return False\n",
|
726 |
+
" except subprocess.CalledProcessError as e:\n",
|
727 |
+
" print(f\"Failed to install ffmpeg: {e}\")\n",
|
728 |
+
" return False\n",
|
729 |
+
" return True\n",
|
730 |
+
"\n",
|
731 |
+
" # Please configure your DB credentials and paths of the files for few shot learning and fine tuning\n",
|
732 |
+
" db_user = \"root\"\n",
|
733 |
+
" db_password = \"\"\n",
|
734 |
+
" db_host = \"localhost\"\n",
|
735 |
+
" db_name = \"classicmodels\"\n",
|
736 |
+
"\n",
|
737 |
+
" db = SQLDatabase.from_uri(f\"mysql+pymysql://{db_user}:{db_password}@{db_host}/{db_name}\")\n",
|
738 |
+
" # print(db.dialect)\n",
|
739 |
+
" # print(db.get_usable_table_names())\n",
|
740 |
+
" # print(db.table_info)\n",
|
741 |
+
" os.environ[\"OPENAI_API_KEY\"] = key\n",
|
742 |
+
"\n",
|
743 |
+
" llm = ChatOpenAI(model=\"gpt-3.5-turbo\", temperature=0)\n",
|
744 |
+
"\n",
|
745 |
+
" history = ChatMessageHistory()\n",
|
746 |
+
"\n",
|
747 |
+
" final_prompt = prompt_creation(os.getcwd()+\"/few_shot_samples.json\")\n",
|
748 |
+
"\n",
|
749 |
+
" generate_query = create_sql_query_chain(llm, db, final_prompt)\n",
|
750 |
+
"\n",
|
751 |
+
" execute_query = QuerySQLDataBaseTool(db=db)\n",
|
752 |
+
"\n",
|
753 |
+
" if is_ffmpeg_installed():\n",
|
754 |
+
" print(\"ffmpeg is already installed.\")\n",
|
755 |
+
" else:\n",
|
756 |
+
" print(\"ffmpeg is not installed. Installing ffmpeg...\")\n",
|
757 |
+
" if install_ffmpeg():\n",
|
758 |
+
" print(\"ffmpeg installation successful.\")\n",
|
759 |
+
" else:\n",
|
760 |
+
" print(\"ffmpeg installation failed. Please install it manually.\")\n",
|
761 |
+
" \n",
|
762 |
+
" if check_libportaudio_installed():\n",
|
763 |
+
" print(\"libportaudio is already installed.\")\n",
|
764 |
+
" else:\n",
|
765 |
+
" print(\"libportaudio is not installed. Installing ffmpeg...\")\n",
|
766 |
+
" if install_libportaudio():\n",
|
767 |
+
" print(\"libportaudio installation successful.\")\n",
|
768 |
+
" else:\n",
|
769 |
+
" print(\"libportaudio installation failed. Please install it manually.\")\n",
|
770 |
+
"\n",
|
771 |
+
" if os.path.isfile(filepath):\n",
|
772 |
+
" sql_query = transcribe_speech(filepath)\n",
|
773 |
+
" else:\n",
|
774 |
+
" sql_query = filepath\n",
|
775 |
+
" \n",
|
776 |
+
" chain = (\n",
|
777 |
+
" RunnablePassthrough.assign(table_names_to_use=select_table(os.getcwd()+\"/database_table_descriptions.csv\")) |\n",
|
778 |
+
" RunnablePassthrough.assign(query=generate_query).assign(\n",
|
779 |
+
" result=itemgetter(\"query\") | execute_query\n",
|
780 |
+
" )\n",
|
781 |
+
" | rephrase_answer()\n",
|
782 |
+
" )\n",
|
783 |
+
"\n",
|
784 |
+
" output = chain.invoke({\"question\": sql_query, \"messages\":history.messages})\n",
|
785 |
+
" history.add_user_message(sql_query)\n",
|
786 |
+
" history.add_ai_message(output)\n",
|
787 |
+
"\n",
|
788 |
+
" return output\n"
|
789 |
+
]
|
790 |
+
},
|
791 |
+
{
|
792 |
+
"cell_type": "code",
|
793 |
+
"execution_count": 24,
|
794 |
+
"metadata": {},
|
795 |
+
"outputs": [
|
796 |
+
{
|
797 |
+
"name": "stdout",
|
798 |
+
"output_type": "stream",
|
799 |
+
"text": [
|
800 |
+
"Running on local URL: http://127.0.0.1:7861\n",
|
801 |
+
"\n",
|
802 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
803 |
+
]
|
804 |
+
},
|
805 |
+
{
|
806 |
+
"data": {
|
807 |
+
"text/html": [
|
808 |
+
"<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
809 |
+
],
|
810 |
+
"text/plain": [
|
811 |
+
"<IPython.core.display.HTML object>"
|
812 |
+
]
|
813 |
+
},
|
814 |
+
"metadata": {},
|
815 |
+
"output_type": "display_data"
|
816 |
+
},
|
817 |
+
{
|
818 |
+
"name": "stdout",
|
819 |
+
"output_type": "stream",
|
820 |
+
"text": [
|
821 |
+
"Human: List the product lines and the number of products in each line.\n",
|
822 |
+
"SQLQuery:\n",
|
823 |
+
"AI: SELECT productLine, COUNT(*) AS numberOfProducts FROM products GROUP BY productLine;\n",
|
824 |
+
"Human: How many employees are there\n",
|
825 |
+
"SQLQuery:\n",
|
826 |
+
"AI: SELECT COUNT(*) FROM 'Employee'\n",
|
827 |
+
"ffmpeg is already installed.\n",
|
828 |
+
"Failed to install ffmpeg: Command '['/bin/bash', '-c', 'brew install ffmpeg']' returned non-zero exit status 127.\n",
|
829 |
+
"ffmpeg installation failed. Please install it manually.\n",
|
830 |
+
"libportaudio is not installed. Installing ffmpeg...\n",
|
831 |
+
"Failed to install ffmpeg: Command '['/bin/bash', '-c', 'brew install portaudio']' returned non-zero exit status 127.\n",
|
832 |
+
"libportaudio installation failed. Please install it manually.\n"
|
833 |
+
]
|
834 |
+
},
|
835 |
+
{
|
836 |
+
"name": "stderr",
|
837 |
+
"output_type": "stream",
|
838 |
+
"text": [
|
839 |
+
"/bin/bash: brew: command not found\n",
|
840 |
+
"/bin/bash: brew: command not found\n",
|
841 |
+
"/Users/avnishkanungo/anaconda3/envs/DLStudioEnv/lib/python3.10/site-packages/transformers/models/whisper/generation_whisper.py:480: FutureWarning: The input name `inputs` is deprecated. Please make sure to use `input_features` instead.\n",
|
842 |
+
" warnings.warn(\n"
|
843 |
+
]
|
844 |
+
},
|
845 |
+
{
|
846 |
+
"name": "stdout",
|
847 |
+
"output_type": "stream",
|
848 |
+
"text": [
|
849 |
+
"Human: List the product lines and the number of products in each line.\n",
|
850 |
+
"SQLQuery:\n",
|
851 |
+
"AI: SELECT productLine, COUNT(*) AS numberOfProducts FROM products GROUP BY productLine;\n",
|
852 |
+
"Human: List the product names and their respective buy prices.\n",
|
853 |
+
"SQLQuery:\n",
|
854 |
+
"AI: SELECT productName, buyPrice FROM products;\n",
|
855 |
+
"ffmpeg is already installed.\n",
|
856 |
+
"Failed to install ffmpeg: Command '['/bin/bash', '-c', 'brew install ffmpeg']' returned non-zero exit status 127.\n",
|
857 |
+
"ffmpeg installation failed. Please install it manually.\n",
|
858 |
+
"libportaudio is not installed. Installing ffmpeg...\n",
|
859 |
+
"Failed to install ffmpeg: Command '['/bin/bash', '-c', 'brew install portaudio']' returned non-zero exit status 127.\n",
|
860 |
+
"libportaudio installation failed. Please install it manually.\n"
|
861 |
+
]
|
862 |
+
},
|
863 |
+
{
|
864 |
+
"name": "stderr",
|
865 |
+
"output_type": "stream",
|
866 |
+
"text": [
|
867 |
+
"/bin/bash: brew: command not found\n",
|
868 |
+
"/bin/bash: brew: command not found\n"
|
869 |
+
]
|
870 |
+
},
|
871 |
+
{
|
872 |
+
"name": "stdout",
|
873 |
+
"output_type": "stream",
|
874 |
+
"text": [
|
875 |
+
"Keyboard interruption in main thread... closing server.\n"
|
876 |
+
]
|
877 |
+
}
|
878 |
+
],
|
879 |
+
"source": [
|
880 |
+
"create_new_interface(sql_translator1)\n",
|
881 |
+
"# interface_new.launch(debug=True)"
|
882 |
]
|
883 |
},
|
884 |
{
|
requirements.txt
CHANGED
@@ -1,16 +1,276 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
absl-py==2.1.0
|
2 |
+
accelerate==0.31.0
|
3 |
+
aiofiles==23.2.1
|
4 |
+
aiohttp==3.9.5
|
5 |
+
aiosignal==1.3.1
|
6 |
+
altair==5.3.0
|
7 |
+
annotated-types==0.7.0
|
8 |
+
anyio==4.4.0
|
9 |
+
argon2-cffi==23.1.0
|
10 |
+
argon2-cffi-bindings==21.2.0
|
11 |
+
arrow==1.3.0
|
12 |
+
asgiref==3.8.1
|
13 |
+
asttokens==2.4.1
|
14 |
+
async-lru==2.0.4
|
15 |
+
async-timeout==4.0.3
|
16 |
+
attrs==23.2.0
|
17 |
+
audioread==3.0.1
|
18 |
+
awscrt==0.20.11
|
19 |
+
Babel==2.15.0
|
20 |
+
backoff==2.2.1
|
21 |
+
bcrypt==4.1.3
|
22 |
+
beautifulsoup4==4.12.3
|
23 |
+
bitsandbytes==0.43.1
|
24 |
+
bleach==6.1.0
|
25 |
+
boto3==1.34.129
|
26 |
+
botocore==1.34.129
|
27 |
+
build==1.2.1
|
28 |
+
cachetools==5.3.3
|
29 |
+
certifi==2024.6.2
|
30 |
+
cffi==1.16.0
|
31 |
+
charset-normalizer==3.3.2
|
32 |
+
chroma-hnswlib==0.7.3
|
33 |
+
chromadb==0.5.3
|
34 |
+
click==8.1.7
|
35 |
+
coloredlogs==15.0.1
|
36 |
+
comm==0.2.2
|
37 |
+
contourpy==1.2.1
|
38 |
+
cycler==0.12.1
|
39 |
+
dataclasses-json==0.6.7
|
40 |
+
datasets==2.20.0
|
41 |
+
debugpy==1.8.1
|
42 |
+
decorator==5.1.1
|
43 |
+
defusedxml==0.7.1
|
44 |
+
Deprecated==1.2.14
|
45 |
+
dill==0.3.8
|
46 |
+
distro==1.9.0
|
47 |
+
dnspython==2.6.1
|
48 |
+
email_validator==2.1.2
|
49 |
+
exceptiongroup==1.2.1
|
50 |
+
executing==2.0.1
|
51 |
+
fastapi==0.111.0
|
52 |
+
fastapi-cli==0.0.4
|
53 |
+
fastjsonschema==2.20.0
|
54 |
+
ffmpy==0.3.2
|
55 |
+
filelock==3.15.3
|
56 |
+
fire==0.6.0
|
57 |
+
flatbuffers==24.3.25
|
58 |
+
fonttools==4.53.0
|
59 |
+
fqdn==1.5.1
|
60 |
+
frozenlist==1.4.1
|
61 |
+
fsspec==2024.5.0
|
62 |
+
google-auth==2.30.0
|
63 |
+
google-auth-oauthlib==1.2.0
|
64 |
+
googleapis-common-protos==1.63.2
|
65 |
+
gradio==4.37.2
|
66 |
+
gradio_client==1.0.2
|
67 |
+
greenlet==3.0.3
|
68 |
+
grpcio==1.64.1
|
69 |
+
h11==0.14.0
|
70 |
+
httpcore==1.0.5
|
71 |
+
httptools==0.6.1
|
72 |
+
httpx==0.27.0
|
73 |
+
huggingface-hub==0.23.4
|
74 |
+
humanfriendly==10.0
|
75 |
+
idna==3.7
|
76 |
+
importlib_metadata==7.1.0
|
77 |
+
importlib_resources==6.4.0
|
78 |
+
ipykernel==6.26.0
|
79 |
+
ipython==8.17.2
|
80 |
+
ipywidgets==8.1.1
|
81 |
+
isoduration==20.11.0
|
82 |
+
jedi==0.19.1
|
83 |
+
Jinja2==3.1.4
|
84 |
+
jmespath==1.0.1
|
85 |
+
joblib==1.4.2
|
86 |
+
json5==0.9.25
|
87 |
+
jsonpatch==1.33
|
88 |
+
jsonpointer==3.0.0
|
89 |
+
jsonschema==4.22.0
|
90 |
+
jsonschema-specifications==2023.12.1
|
91 |
+
jupyter-events==0.10.0
|
92 |
+
jupyter-lsp==2.2.5
|
93 |
+
jupyter_client==8.6.2
|
94 |
+
jupyter_core==5.7.2
|
95 |
+
jupyter_server==2.14.1
|
96 |
+
jupyter_server_terminals==0.5.3
|
97 |
+
jupyterlab==4.2.0
|
98 |
+
jupyterlab_pygments==0.3.0
|
99 |
+
jupyterlab_server==2.27.2
|
100 |
+
jupyterlab_widgets==3.0.11
|
101 |
+
kiwisolver==1.4.5
|
102 |
+
kubernetes==30.1.0
|
103 |
+
langchain==0.2.5
|
104 |
+
langchain-community==0.2.5
|
105 |
+
langchain-core==0.2.9
|
106 |
+
langchain-huggingface==0.0.3
|
107 |
+
langchain-openai==0.1.9
|
108 |
+
langchain-text-splitters==0.2.1
|
109 |
+
langsmith==0.1.82
|
110 |
+
lazy_loader==0.4
|
111 |
+
librosa==0.10.2.post1
|
112 |
+
lightning==2.3.0
|
113 |
+
lightning-cloud==0.5.69
|
114 |
+
lightning-utilities==0.11.2
|
115 |
+
lightning_sdk==0.1.10
|
116 |
+
litdata==0.2.10
|
117 |
+
llvmlite==0.43.0
|
118 |
+
Markdown==3.6
|
119 |
+
markdown-it-py==3.0.0
|
120 |
+
MarkupSafe==2.1.5
|
121 |
+
marshmallow==3.21.3
|
122 |
+
matplotlib==3.8.2
|
123 |
+
matplotlib-inline==0.1.7
|
124 |
+
mdurl==0.1.2
|
125 |
+
mistune==3.0.2
|
126 |
+
mmh3==4.1.0
|
127 |
+
monotonic==1.6
|
128 |
+
mpmath==1.3.0
|
129 |
+
msgpack==1.0.8
|
130 |
+
multidict==6.0.5
|
131 |
+
multiprocess==0.70.16
|
132 |
+
mypy-extensions==1.0.0
|
133 |
+
mysql-connector-python==8.4.0
|
134 |
+
nbclient==0.10.0
|
135 |
+
nbconvert==7.16.4
|
136 |
+
nbformat==5.10.4
|
137 |
+
nest-asyncio==1.6.0
|
138 |
+
networkx==3.3
|
139 |
+
notebook_shim==0.2.4
|
140 |
+
numba==0.60.0
|
141 |
+
numpy==1.26.4
|
142 |
+
nvidia-cublas-cu12==12.1.3.1
|
143 |
+
nvidia-cuda-cupti-cu12==12.1.105
|
144 |
+
nvidia-cuda-nvrtc-cu12==12.1.105
|
145 |
+
nvidia-cuda-runtime-cu12==12.1.105
|
146 |
+
nvidia-cudnn-cu12==8.9.2.26
|
147 |
+
nvidia-cufft-cu12==11.0.2.54
|
148 |
+
nvidia-curand-cu12==10.3.2.106
|
149 |
+
nvidia-cusolver-cu12==11.4.5.107
|
150 |
+
nvidia-cusparse-cu12==12.1.0.106
|
151 |
+
nvidia-nccl-cu12==2.19.3
|
152 |
+
nvidia-nvjitlink-cu12==12.5.40
|
153 |
+
nvidia-nvtx-cu12==12.1.105
|
154 |
+
oauthlib==3.2.2
|
155 |
+
onnxruntime==1.18.0
|
156 |
+
openai==1.35.3
|
157 |
+
opentelemetry-api==1.25.0
|
158 |
+
opentelemetry-exporter-otlp-proto-common==1.25.0
|
159 |
+
opentelemetry-exporter-otlp-proto-grpc==1.25.0
|
160 |
+
opentelemetry-instrumentation==0.46b0
|
161 |
+
opentelemetry-instrumentation-asgi==0.46b0
|
162 |
+
opentelemetry-instrumentation-fastapi==0.46b0
|
163 |
+
opentelemetry-proto==1.25.0
|
164 |
+
opentelemetry-sdk==1.25.0
|
165 |
+
opentelemetry-semantic-conventions==0.46b0
|
166 |
+
opentelemetry-util-http==0.46b0
|
167 |
+
orjson==3.10.5
|
168 |
+
overrides==7.7.0
|
169 |
+
packaging==24.1
|
170 |
+
pandas==2.1.4
|
171 |
+
pandocfilters==1.5.1
|
172 |
+
parso==0.8.4
|
173 |
+
pexpect==4.9.0
|
174 |
+
pillow==10.3.0
|
175 |
+
platformdirs==4.2.2
|
176 |
+
pooch==1.8.2
|
177 |
+
posthog==3.5.0
|
178 |
+
prometheus_client==0.20.0
|
179 |
+
prompt_toolkit==3.0.47
|
180 |
+
protobuf==4.23.4
|
181 |
+
psutil==6.0.0
|
182 |
+
ptyprocess==0.7.0
|
183 |
+
pure-eval==0.2.2
|
184 |
+
pyarrow==16.1.0
|
185 |
+
pyarrow-hotfix==0.6
|
186 |
+
pyasn1==0.6.0
|
187 |
+
pyasn1_modules==0.4.0
|
188 |
+
pycparser==2.22
|
189 |
+
pydantic==2.7.4
|
190 |
+
pydantic_core==2.18.4
|
191 |
+
pydub==0.25.1
|
192 |
+
Pygments==2.18.0
|
193 |
+
PyJWT==2.8.0
|
194 |
+
PyMySQL==1.1.1
|
195 |
+
pyparsing==3.1.2
|
196 |
+
PyPika==0.48.9
|
197 |
+
pyproject_hooks==1.1.0
|
198 |
+
python-dateutil==2.9.0.post0
|
199 |
+
python-dotenv==1.0.1
|
200 |
+
python-json-logger==2.0.7
|
201 |
+
python-multipart==0.0.9
|
202 |
+
pytorch-lightning==2.3.0
|
203 |
+
pytz==2024.1
|
204 |
+
PyYAML==6.0.1
|
205 |
+
pyzmq==26.0.3
|
206 |
+
referencing==0.35.1
|
207 |
+
regex==2024.5.15
|
208 |
+
requests==2.32.3
|
209 |
+
requests-oauthlib==2.0.0
|
210 |
+
rfc3339-validator==0.1.4
|
211 |
+
rfc3986-validator==0.1.1
|
212 |
+
rich==13.7.1
|
213 |
+
rpds-py==0.18.1
|
214 |
+
rsa==4.9
|
215 |
+
ruff==0.5.0
|
216 |
+
s3transfer==0.10.1
|
217 |
+
safetensors==0.4.3
|
218 |
+
scikit-learn==1.3.2
|
219 |
+
scipy==1.11.4
|
220 |
+
semantic-version==2.10.0
|
221 |
+
Send2Trash==1.8.3
|
222 |
+
sentence-transformers==3.0.1
|
223 |
+
sentencepiece==0.2.0
|
224 |
+
shellingham==1.5.4
|
225 |
+
simple-term-menu==1.6.4
|
226 |
+
six==1.16.0
|
227 |
+
sniffio==1.3.1
|
228 |
+
soundfile==0.12.1
|
229 |
+
soupsieve==2.5
|
230 |
+
soxr==0.3.7
|
231 |
+
SQLAlchemy==2.0.31
|
232 |
+
stack-data==0.6.3
|
233 |
+
starlette==0.37.2
|
234 |
+
sympy==1.12.1
|
235 |
+
tenacity==8.4.2
|
236 |
+
tensorboard==2.15.1
|
237 |
+
tensorboard-data-server==0.7.2
|
238 |
+
termcolor==2.4.0
|
239 |
+
terminado==0.18.1
|
240 |
+
threadpoolctl==3.5.0
|
241 |
+
tiktoken==0.7.0
|
242 |
+
tinycss2==1.3.0
|
243 |
+
tokenizers==0.19.1
|
244 |
+
tomli==2.0.1
|
245 |
+
tomlkit==0.12.0
|
246 |
+
toolz==0.12.1
|
247 |
+
torch==2.2.1+cu121
|
248 |
+
torchmetrics==1.3.1
|
249 |
+
torchvision==0.17.1+cu121
|
250 |
+
tornado==6.4.1
|
251 |
+
tqdm==4.66.4
|
252 |
+
traitlets==5.14.3
|
253 |
+
transformers==4.41.2
|
254 |
+
triton==2.2.0
|
255 |
+
typer==0.12.3
|
256 |
+
types-python-dateutil==2.9.0.20240316
|
257 |
+
typing-inspect==0.9.0
|
258 |
+
typing_extensions==4.12.2
|
259 |
+
tzdata==2024.1
|
260 |
+
ujson==5.10.0
|
261 |
+
uri-template==1.3.0
|
262 |
+
urllib3==2.2.2
|
263 |
+
uvicorn==0.30.1
|
264 |
+
uvloop==0.19.0
|
265 |
+
watchfiles==0.22.0
|
266 |
+
wcwidth==0.2.13
|
267 |
+
webcolors==24.6.0
|
268 |
+
webencodings==0.5.1
|
269 |
+
websocket-client==1.8.0
|
270 |
+
websockets==11.0.3
|
271 |
+
Werkzeug==3.0.3
|
272 |
+
widgetsnbextension==4.0.11
|
273 |
+
wrapt==1.16.0
|
274 |
+
xxhash==3.4.1
|
275 |
+
yarl==1.9.4
|
276 |
+
zipp==3.19.2
|