Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,19 +2,7 @@ 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)
|
10 |
-
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
11 |
-
s.connect(("8.8.8.8", 80))
|
12 |
-
local_ip = s.getsockname()[0]
|
13 |
-
s.close()
|
14 |
-
return local_ip
|
15 |
-
except Exception as e:
|
16 |
-
print(f"Error getting local IP: {e}")
|
17 |
-
return None
|
18 |
|
19 |
|
20 |
|
@@ -49,28 +37,7 @@ def find_most_similar_command(statement, command_list):
|
|
49 |
|
50 |
return best_match,reply
|
51 |
|
52 |
-
|
53 |
-
col_names={'1':"name",'3':"address",'4':"order"}
|
54 |
-
def send_data_to_db(menu_id,col_value,order_id):
|
55 |
-
import requests
|
56 |
-
col_name=col_names[menu_id]
|
57 |
-
# API endpoint URL
|
58 |
-
url = 'https://pizzahut.softinfix.tech/api/save_order?'+col_name+'='+col_value+"&order_id"+"="+order_id
|
59 |
-
payload = {}
|
60 |
-
headers = {}
|
61 |
-
|
62 |
-
response = requests.request("GET", url, headers=headers, data=payload)
|
63 |
-
|
64 |
-
# Print response
|
65 |
-
print(response.status_code)
|
66 |
-
print(response.text)
|
67 |
-
|
68 |
-
def transcribe_the_command(audio,menu_id,order_id):
|
69 |
-
local_ip = get_local_ip()
|
70 |
-
if local_ip:
|
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"
|
@@ -79,25 +46,20 @@ def transcribe_the_command(audio,menu_id,order_id):
|
|
79 |
print(menu_id)
|
80 |
|
81 |
transcript = asr_pipe(file_name)["text"]
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
most_similar_command,reply = find_most_similar_command(transcript, commands)
|
90 |
-
print(f"Given Statement: {transcript}")
|
91 |
-
print(f"Most Similar Command: {most_similar_command}\n")
|
92 |
-
print(reply)
|
93 |
-
return reply
|
94 |
# get_text_from_voice("urdu.wav")
|
95 |
import gradio as gr
|
96 |
|
97 |
|
98 |
iface = gr.Interface(
|
99 |
fn=transcribe_the_command,
|
100 |
-
inputs=[gr.inputs.Audio(label="Recorded Audio",source="microphone"),gr.inputs.Textbox(label="menu_id")
|
101 |
outputs="text",
|
102 |
title="Whisper Small Urdu Command",
|
103 |
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.",
|
|
|
2 |
asr_pipe = pipeline("automatic-speech-recognition", model="Abdullah17/whisper-small-urdu")
|
3 |
from difflib import SequenceMatcher
|
4 |
import json
|
|
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
|
|
|
37 |
|
38 |
return best_match,reply
|
39 |
|
40 |
+
def transcribe_the_command(audio,menu_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
import soundfile as sf
|
42 |
sample_rate, audio_data = audio
|
43 |
file_name = "recorded_audio.wav"
|
|
|
46 |
print(menu_id)
|
47 |
|
48 |
transcript = asr_pipe(file_name)["text"]
|
49 |
+
commands=urdu_data[menu_id]
|
50 |
+
print(commands)
|
51 |
+
most_similar_command,reply = find_most_similar_command(transcript, commands)
|
52 |
+
print(f"Given Statement: {transcript}")
|
53 |
+
print(f"Most Similar Command: {most_similar_command}\n")
|
54 |
+
print(reply)
|
55 |
+
return reply
|
|
|
|
|
|
|
|
|
|
|
56 |
# get_text_from_voice("urdu.wav")
|
57 |
import gradio as gr
|
58 |
|
59 |
|
60 |
iface = gr.Interface(
|
61 |
fn=transcribe_the_command,
|
62 |
+
inputs=[gr.inputs.Audio(label="Recorded Audio",source="microphone"),gr.inputs.Textbox(label="menu_id")],
|
63 |
outputs="text",
|
64 |
title="Whisper Small Urdu Command",
|
65 |
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.",
|