Spaces:
Sleeping
Sleeping
avnishkanungo
commited on
Commit
•
c8a0e87
1
Parent(s):
ac35dc9
Upload folder using huggingface_hub
Browse files- NLToSQL.py +35 -0
- app.py +44 -0
NLToSQL.py
CHANGED
@@ -197,6 +197,32 @@ def record_command():
|
|
197 |
print("Audio saved to variable")
|
198 |
return audio_data
|
199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
|
201 |
if __name__ == '__main__':
|
202 |
|
@@ -247,6 +273,15 @@ if __name__ == '__main__':
|
|
247 |
print("ffmpeg installation successful.")
|
248 |
else:
|
249 |
print("ffmpeg installation failed. Please install it manually.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
|
251 |
valid_interface_type = ["audio", "text", "quit"]
|
252 |
while True:
|
|
|
197 |
print("Audio saved to variable")
|
198 |
return audio_data
|
199 |
|
200 |
+
def check_libportaudio_installed():
|
201 |
+
try:
|
202 |
+
# Run `ffmpeg -version` to check if ffmpeg is installed
|
203 |
+
subprocess.run(['libportaudio2', '-version'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
204 |
+
return True
|
205 |
+
except (subprocess.CalledProcessError, FileNotFoundError):
|
206 |
+
return False
|
207 |
+
|
208 |
+
def install_libportaudio():
|
209 |
+
try:
|
210 |
+
if sys.platform.startswith('linux'):
|
211 |
+
subprocess.run(['sudo', 'apt-get', 'update'], check=True)
|
212 |
+
subprocess.run(['sudo', 'apt-get', 'install', '-y', 'libportaudio2'], check=True)
|
213 |
+
elif sys.platform == 'darwin': # macOS
|
214 |
+
subprocess.run(['/bin/bash', '-c', 'brew install portaudio'], check=True)
|
215 |
+
elif sys.platform == 'win32':
|
216 |
+
print("Please download ffmpeg from https://ffmpeg.org/download.html and install it manually.")
|
217 |
+
return False
|
218 |
+
else:
|
219 |
+
print("Unsupported OS. Please install ffmpeg manually.")
|
220 |
+
return False
|
221 |
+
except subprocess.CalledProcessError as e:
|
222 |
+
print(f"Failed to install ffmpeg: {e}")
|
223 |
+
return False
|
224 |
+
return True
|
225 |
+
|
226 |
|
227 |
if __name__ == '__main__':
|
228 |
|
|
|
273 |
print("ffmpeg installation successful.")
|
274 |
else:
|
275 |
print("ffmpeg installation failed. Please install it manually.")
|
276 |
+
|
277 |
+
if check_libportaudio_installed():
|
278 |
+
print("libportaudio is already installed.")
|
279 |
+
else:
|
280 |
+
print("libportaudio is not installed. Installing ffmpeg...")
|
281 |
+
if install_libportaudio():
|
282 |
+
print("libportaudio installation successful.")
|
283 |
+
else:
|
284 |
+
print("libportaudio installation failed. Please install it manually.")
|
285 |
|
286 |
valid_interface_type = ["audio", "text", "quit"]
|
287 |
while True:
|
app.py
CHANGED
@@ -198,6 +198,32 @@ def sql_translator(filepath, key):
|
|
198 |
|
199 |
print("Audio saved to variable")
|
200 |
return audio_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
|
202 |
|
203 |
db_user = "root"
|
@@ -221,6 +247,24 @@ def sql_translator(filepath, key):
|
|
221 |
|
222 |
execute_query = QuerySQLDataBaseTool(db=db)
|
223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
sql_query = transcribe_speech(filepath)
|
225 |
chain = (
|
226 |
RunnablePassthrough.assign(table_names_to_use=select_table(os.getcwd()+"/database_table_descriptions.csv")) |
|
|
|
198 |
|
199 |
print("Audio saved to variable")
|
200 |
return audio_data
|
201 |
+
|
202 |
+
def check_libportaudio_installed():
|
203 |
+
try:
|
204 |
+
# Run `ffmpeg -version` to check if ffmpeg is installed
|
205 |
+
subprocess.run(['libportaudio2', '-version'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
206 |
+
return True
|
207 |
+
except (subprocess.CalledProcessError, FileNotFoundError):
|
208 |
+
return False
|
209 |
+
|
210 |
+
def install_libportaudio():
|
211 |
+
try:
|
212 |
+
if sys.platform.startswith('linux'):
|
213 |
+
subprocess.run(['sudo', 'apt-get', 'update'], check=True)
|
214 |
+
subprocess.run(['sudo', 'apt-get', 'install', '-y', 'libportaudio2'], check=True)
|
215 |
+
elif sys.platform == 'darwin': # macOS
|
216 |
+
subprocess.run(['/bin/bash', '-c', 'brew install portaudio'], check=True)
|
217 |
+
elif sys.platform == 'win32':
|
218 |
+
print("Please download ffmpeg from https://ffmpeg.org/download.html and install it manually.")
|
219 |
+
return False
|
220 |
+
else:
|
221 |
+
print("Unsupported OS. Please install ffmpeg manually.")
|
222 |
+
return False
|
223 |
+
except subprocess.CalledProcessError as e:
|
224 |
+
print(f"Failed to install ffmpeg: {e}")
|
225 |
+
return False
|
226 |
+
return True
|
227 |
|
228 |
|
229 |
db_user = "root"
|
|
|
247 |
|
248 |
execute_query = QuerySQLDataBaseTool(db=db)
|
249 |
|
250 |
+
if is_ffmpeg_installed():
|
251 |
+
print("ffmpeg is already installed.")
|
252 |
+
else:
|
253 |
+
print("ffmpeg is not installed. Installing ffmpeg...")
|
254 |
+
if install_ffmpeg():
|
255 |
+
print("ffmpeg installation successful.")
|
256 |
+
else:
|
257 |
+
print("ffmpeg installation failed. Please install it manually.")
|
258 |
+
|
259 |
+
if check_libportaudio_installed():
|
260 |
+
print("libportaudio is already installed.")
|
261 |
+
else:
|
262 |
+
print("libportaudio is not installed. Installing ffmpeg...")
|
263 |
+
if install_libportaudio():
|
264 |
+
print("libportaudio installation successful.")
|
265 |
+
else:
|
266 |
+
print("libportaudio installation failed. Please install it manually.")
|
267 |
+
|
268 |
sql_query = transcribe_speech(filepath)
|
269 |
chain = (
|
270 |
RunnablePassthrough.assign(table_names_to_use=select_table(os.getcwd()+"/database_table_descriptions.csv")) |
|