Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -16,93 +16,93 @@ def get_local_ip():
|
|
16 |
print(f"Error getting local IP: {e}")
|
17 |
return None
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
#
|
26 |
-
#
|
27 |
-
#
|
28 |
-
#
|
29 |
-
#
|
30 |
-
#
|
31 |
-
#
|
32 |
-
#
|
33 |
-
#
|
34 |
-
#
|
35 |
-
#
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
#
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
#
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
#
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
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()
|