Hunzla commited on
Commit
8d510d0
0 Parent(s):

Duplicate from Hunzla/whisperaudio

Browse files
Files changed (5) hide show
  1. .gitattributes +35 -0
  2. README.md +14 -0
  3. app.py +106 -0
  4. requirements.txt +3 -0
  5. tasks.json +17 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Whisperaudio
3
+ emoji: 🚀
4
+ colorFrom: green
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.39.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: openrail
11
+ duplicated_from: Hunzla/whisperaudio
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)
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
+
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
+ 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
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"
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)
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"),gr.inputs.Textbox(label="order_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.",
104
+ )
105
+
106
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers[torch]
3
+ soundfile
tasks.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "0": [
3
+ ["کیا آپ میری مدد کر سکتے ہیں","مجھے نمائندے سے بات کرنی ہے","مجھے مدد کی ضرورت ہے","مجھے ایجنٹ سے بات کرنی ہے۔"],
4
+ ["آرڈر کریں ","آرڈر پلیس کر دیں","رکھیں آرڈر","میں نے آرڈر کرنا ہے۔","مجھے آرڈر کرنا ہے"],
5
+ [ "آرڈر کا اسٹیٹس پتا کرنا ہے","آرڈر کی حالت پتا کرنی ہے","آرڈر کی کنڈیشن کیا ہے","اوڈر کی تفیلات جانتی ہے","میں نے آرڈر کیا تھا"]
6
+ ],
7
+ "2": [
8
+ [ "لاہور","لہور","لاهور", "لہوڑ", "لاھور"],
9
+ [ "کراچی", "کرچی", "کراچ","کرچ","کرچے"],
10
+ [ "اسلام آباد", "اسلم آباد","اسلماباد","اسلامباد","اسلمباد","اسلامآبد"]
11
+ ],
12
+ "3": [
13
+ "تیسرا بیان اندراج ۱",
14
+ "تیسرا بیان اندراج ۲",
15
+ "تیسرا بیان اندراج ۳"
16
+ ]
17
+ }