Hunzla commited on
Commit
bb688fe
1 Parent(s): 89a1cb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -90
app.py CHANGED
@@ -16,93 +16,93 @@ def get_local_ip():
16
  print(f"Error getting local IP: {e}")
17
  return None
18
 
19
- local_ip = get_local_ip()
20
- if local_ip:
21
- print(f"Local IP Address: {local_ip}")
22
- else:
23
- print("Local IP could not be determined.")
24
-
25
- # with open("tasks.json", "r",encoding="utf-8") as json_file:
26
- # urdu_data = json.load(json_file)
27
- # # List of commands
28
- # # commands = [
29
- # # "نمائندے ایجنٹ نمائندہ",
30
- # # " سم ایکٹیویٹ ",
31
- # # " سم بلاک بند ",
32
- # # "موبائل پیکیجز انٹرنیٹ پیکیج",
33
- # # " چالان جمع چلان",
34
- # # " گانا "
35
- # # ]
36
- # # replies = [
37
- # # 1,2,
38
- # # ]
39
- # # Function to find the most similar command
40
- # def find_most_similar_command(statement, command_list):
41
- # best_match = None
42
- # highest_similarity = 0
43
- # i=0
44
- # for sub_list in command_list:
45
- # for command in sub_list:
46
- # similarity = SequenceMatcher(None, statement, command).ratio()
47
- # print(i,"similarity",similarity)
48
- # if similarity > highest_similarity:
49
- # highest_similarity = similarity
50
- # best_match = command
51
- # reply=i
52
- # i+=1
53
-
54
- # return best_match,reply
55
-
56
-
57
- # def send_data_to_db(order_id,col_name):
58
- # import requests
59
-
60
- # # API endpoint URL
61
- # url = 'https://pizzahut.softinfix.tech/api/save_order/'+order_id
62
-
63
- # # Data to send (in dictionary format)
64
- # data = {
65
- # col_name: col_value,
66
- # }
67
-
68
- # # Send POST request with data
69
- # response = requests.post(url, data=data)
70
-
71
- # # Print response
72
- # print(response.status_code)
73
- # print(response.text)
74
-
75
- # def transcribe_the_command(audio,menu_id,order_id,db_col="0"):
76
-
77
- # import soundfile as sf
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
- # transcript = asr_pipe(file_name)["text"]
85
- # if menu_id == "transcript_only":
86
- # reply=transcript
87
- # print(reply)
88
- # else:
89
- # commands=urdu_data[menu_id]
90
- # print(commands)
91
- # most_similar_command,reply = find_most_similar_command(transcript, commands)
92
- # print(f"Given Statement: {transcript}")
93
- # print(f"Most Similar Command: {most_similar_command}\n")
94
- # print(reply)
95
- # return reply
96
- # # get_text_from_voice("urdu.wav")
97
- # import gradio as gr
98
-
99
-
100
- # iface = gr.Interface(
101
- # fn=transcribe_the_command,
102
- # inputs=[gr.inputs.Audio(label="Recorded Audio",source="microphone"),gr.inputs.Textbox(label="id"),gr.inputs.Textbox(label="col_name(optional)")],
103
- # outputs="text",
104
- # title="Whisper Small Urdu Command",
105
- # description="Realtime demo for Urdu speech recognition using a fine-tuned Whisper small model and outputting the estimated command on the basis of speech transcript.",
106
- # )
107
-
108
- # iface.launch()
 
16
  print(f"Error getting local IP: {e}")
17
  return None
18
 
19
+
20
+
21
+ with open("tasks.json", "r",encoding="utf-8") as json_file:
22
+ urdu_data = json.load(json_file)
23
+ # List of commands
24
+ # commands = [
25
+ # "نمائندے ایجنٹ نمائندہ",
26
+ # " سم ایکٹیویٹ ",
27
+ # " سم بلاک بند ",
28
+ # "موبائل پیکیجز انٹرنیٹ پیکیج",
29
+ # " چالان جمع چلان",
30
+ # " گانا "
31
+ # ]
32
+ # replies = [
33
+ # 1,2,
34
+ # ]
35
+ # Function to find the most similar command
36
+ def find_most_similar_command(statement, command_list):
37
+ best_match = None
38
+ highest_similarity = 0
39
+ i=0
40
+ for sub_list in command_list:
41
+ for command in sub_list:
42
+ similarity = SequenceMatcher(None, statement, command).ratio()
43
+ print(i,"similarity",similarity)
44
+ if similarity > highest_similarity:
45
+ highest_similarity = similarity
46
+ best_match = command
47
+ reply=i
48
+ i+=1
49
+
50
+ return best_match,reply
51
+
52
+
53
+ def send_data_to_db(order_id,col_name):
54
+ import requests
55
+
56
+ # API endpoint URL
57
+ url = 'https://pizzahut.softinfix.tech/api/save_order/'+order_id
58
+
59
+ # Data to send (in dictionary format)
60
+ data = {
61
+ col_name: col_value,
62
+ }
63
+
64
+ # Send POST request with data
65
+ response = requests.post(url, data=data)
66
+
67
+ # Print response
68
+ print(response.status_code)
69
+ print(response.text)
70
+
71
+ def transcribe_the_command(audio,menu_id,order_id,db_col="0"):
72
+ local_ip = get_local_ip()
73
+ if local_ip:
74
+ print(f"Local IP Address: {local_ip}")
75
+ else:
76
+ print("Local IP could not be determined.")
77
+ import soundfile as sf
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
+ transcript = asr_pipe(file_name)["text"]
85
+ if menu_id == "transcript_only":
86
+ reply=transcript
87
+ print(reply)
88
+ else:
89
+ commands=urdu_data[menu_id]
90
+ print(commands)
91
+ most_similar_command,reply = find_most_similar_command(transcript, commands)
92
+ print(f"Given Statement: {transcript}")
93
+ print(f"Most Similar Command: {most_similar_command}\n")
94
+ print(reply)
95
+ return reply
96
+ # get_text_from_voice("urdu.wav")
97
+ import gradio as gr
98
+
99
+
100
+ iface = gr.Interface(
101
+ fn=transcribe_the_command,
102
+ inputs=[gr.inputs.Audio(label="Recorded Audio",source="microphone"),gr.inputs.Textbox(label="id"),gr.inputs.Textbox(label="col_name(optional)")],
103
+ outputs="text",
104
+ title="Whisper Small Urdu Command",
105
+ description="Realtime demo for Urdu speech recognition using a fine-tuned Whisper small model and outputting the estimated command on the basis of speech transcript.",
106
+ )
107
+
108
+ iface.launch()