Hunzla commited on
Commit
757dd46
1 Parent(s): 8d510d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -1,9 +1,11 @@
1
  from transformers import pipeline
2
  asr_pipe = pipeline("automatic-speech-recognition", model="Abdullah17/whisper-small-urdu")
 
3
  from difflib import SequenceMatcher
4
  import json
5
  import socket
6
-
 
7
  def get_local_ip():
8
  try:
9
  # Create a socket connection to a remote host (here, google.com)
@@ -50,6 +52,7 @@ def find_most_similar_command(statement, command_list):
50
  return best_match,reply
51
 
52
  transcript_only=["1","3","4"]
 
53
  col_names={'1':"name",'3':"address",'4':"order"}
54
  def send_data_to_db(menu_id,col_value,order_id):
55
  import requests
@@ -71,19 +74,28 @@ def transcribe_the_command(audio,menu_id,order_id):
71
  print(f"Local IP Address: {local_ip}")
72
  else:
73
  print("Local IP could not be determined.")
74
- import soundfile as sf
75
  sample_rate, audio_data = audio
76
  file_name = "recorded_audio.wav"
77
  sf.write(file_name, audio_data, sample_rate)
78
  # Convert stereo to mono by averaging the two channels
79
  print(menu_id)
80
 
81
- transcript = asr_pipe(file_name)["text"]
82
  if menu_id in transcript_only:
 
83
  col_value=transcript
84
  send_data_to_db(menu_id,col_value,order_id)
85
  print("data uploaded successfully!")
 
 
 
 
 
 
 
 
86
  else:
 
87
  commands=urdu_data[menu_id]
88
  print(commands)
89
  most_similar_command,reply = find_most_similar_command(transcript, commands)
@@ -92,7 +104,6 @@ def transcribe_the_command(audio,menu_id,order_id):
92
  print(reply)
93
  return reply
94
  # get_text_from_voice("urdu.wav")
95
- import gradio as gr
96
 
97
 
98
  iface = gr.Interface(
 
1
  from transformers import pipeline
2
  asr_pipe = pipeline("automatic-speech-recognition", model="Abdullah17/whisper-small-urdu")
3
+ transcript_pipe = pipeline("automatic-speech-recognition", model="ihanif/whisper-medium-urdu")
4
  from difflib import SequenceMatcher
5
  import json
6
  import socket
7
+ import soundfile as sf
8
+ import gradio as gr
9
  def get_local_ip():
10
  try:
11
  # Create a socket connection to a remote host (here, google.com)
 
52
  return best_match,reply
53
 
54
  transcript_only=["1","3","4"]
55
+ match_and_save=["2"]
56
  col_names={'1':"name",'3':"address",'4':"order"}
57
  def send_data_to_db(menu_id,col_value,order_id):
58
  import requests
 
74
  print(f"Local IP Address: {local_ip}")
75
  else:
76
  print("Local IP could not be determined.")
77
+
78
  sample_rate, audio_data = audio
79
  file_name = "recorded_audio.wav"
80
  sf.write(file_name, audio_data, sample_rate)
81
  # Convert stereo to mono by averaging the two channels
82
  print(menu_id)
83
 
 
84
  if menu_id in transcript_only:
85
+ transcript = transcript_pipe(file_name)["text"]
86
  col_value=transcript
87
  send_data_to_db(menu_id,col_value,order_id)
88
  print("data uploaded successfully!")
89
+ elif menu_id in match_and_save:
90
+ transcript = asr_pipe(file_name)["text"]
91
+ commands=urdu_data[menu_id]
92
+ most_similar_command,reply = find_most_similar_command(transcript, commands)
93
+ print(f"Given Statement: {transcript}")
94
+ print(f"Most Similar Command: {most_similar_command}\n")
95
+ print(reply)
96
+ send_data_to_db(menu_id,reply,order_id)
97
  else:
98
+ transcript = asr_pipe(file_name)["text"]
99
  commands=urdu_data[menu_id]
100
  print(commands)
101
  most_similar_command,reply = find_most_similar_command(transcript, commands)
 
104
  print(reply)
105
  return reply
106
  # get_text_from_voice("urdu.wav")
 
107
 
108
 
109
  iface = gr.Interface(