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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -84
app.py CHANGED
@@ -22,87 +22,87 @@ if 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()
 
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()