zinoubm commited on
Commit
4f8f8b7
·
1 Parent(s): bb8d122

added final touches

Browse files
.env CHANGED
@@ -1 +1,2 @@
1
- MODEL = ada:ft-personal-2023-02-17-17-56-33
 
 
1
+ MODEL = ada:ft-personal-2023-02-17-17-56-33
2
+ OPENAI_API_KEY = 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
__pycache__/constants.cpython-38.pyc ADDED
Binary file (1.23 kB). View file
 
__pycache__/run_command_responses.cpython-38.pyc CHANGED
Binary files a/__pycache__/run_command_responses.cpython-38.pyc and b/__pycache__/run_command_responses.cpython-38.pyc differ
 
app.py CHANGED
@@ -1,45 +1,11 @@
1
- import os
2
  import gradio as gr
3
- import numpy as np
4
  import librosa
5
- import torch
6
- from transformers import Speech2TextProcessor, Speech2TextForConditionalGeneration
7
- from dotenv import load_dotenv
8
  import openai
9
- from run_command_responses import ResponseManager as rs
10
 
11
- resoponses = {
12
- "heated_seats_on": rs.activate_heated_seats,
13
- "heated_seats_off": rs.deactivate_heated_seats,
14
- "cooled_seats_on": rs.activate_cooled_seats,
15
- "cooled_seats_off": rs.deactivate_cooled_seats,
16
- "massage_seats_on": rs.activate_massage_seats,
17
- "massage_seats_off": rs.deactivate_massage_seats,
18
- }
19
-
20
- id2label = {
21
- 1: "massage_seats_on",
22
- 2: "massage_seats_off",
23
- 3: "heated_seats_on",
24
- 4: "heated_seats_off",
25
- 5: "cooled_seats_on",
26
- 6: "cooled_seats_off",
27
- }
28
-
29
- load_dotenv()
30
-
31
- os.environ["PATH"] += ".\env\Lib\site-packages\ffprobe"
32
-
33
- OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
34
- MODEL = os.getenv("MODEL")
35
 
36
  openai.api_key = OPENAI_API_KEY
37
 
38
- model = Speech2TextForConditionalGeneration.from_pretrained(
39
- "facebook/s2t-small-librispeech-asr"
40
- )
41
- processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-librispeech-asr")
42
-
43
 
44
  def get_command(command, model, id2label):
45
  completion = openai.Completion.create(
@@ -50,7 +16,11 @@ def get_command(command, model, id2label):
50
  return result
51
 
52
 
53
- def transcribe(audio):
 
 
 
 
54
  input, rate = librosa.load(
55
  audio, sr=16000
56
  ) # Downsample original frequency to 16000hrz
@@ -60,13 +30,23 @@ def transcribe(audio):
60
  )
61
  transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)
62
  result = get_command(transcription, MODEL, id2label)
63
- resoponses.get(result)()
64
- return result
65
 
66
 
67
  if __name__ == "__main__":
68
  gr.Interface(
69
  fn=transcribe,
70
- inputs=gr.Audio(source="microphone", type="filepath"),
71
- outputs="text",
 
 
 
 
 
 
 
 
 
 
72
  ).launch()
 
 
1
  import gradio as gr
 
2
  import librosa
 
 
 
3
  import openai
4
+ from constants import *
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  openai.api_key = OPENAI_API_KEY
8
 
 
 
 
 
 
9
 
10
  def get_command(command, model, id2label):
11
  completion = openai.Completion.create(
 
16
  return result
17
 
18
 
19
+ def transcribe(audio, text):
20
+ if text:
21
+ result = get_command(text, MODEL, id2label)
22
+ return "Text provided by the user", text_respnses[result], None
23
+
24
  input, rate = librosa.load(
25
  audio, sr=16000
26
  ) # Downsample original frequency to 16000hrz
 
30
  )
31
  transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)
32
  result = get_command(transcription, MODEL, id2label)
33
+ audio_res = resoponses.get(result)()
34
+ return transcription, text_respnses[result], audio_res
35
 
36
 
37
  if __name__ == "__main__":
38
  gr.Interface(
39
  fn=transcribe,
40
+ inputs=[
41
+ gr.Audio(label="", source="microphone", type="filepath"),
42
+ gr.Textbox(label="If you prefer type your command (more accurate)"),
43
+ ],
44
+ outputs=[
45
+ gr.Textbox(
46
+ label="Input Transcription (Please check that this matches what you've said)"
47
+ ),
48
+ gr.Textbox(label="Machine Response (Text Version)"),
49
+ gr.Audio(label="Machine Response (Audio Version)"),
50
+ ],
51
+ allow_flagging="auto",
52
  ).launch()
command_responses/cooled_seats_activated.m4a DELETED
Binary file (50.6 kB)
 
command_responses/cooled_seats_deactivated.m4a DELETED
Binary file (58.3 kB)
 
command_responses/heated_seats_activated.m4a DELETED
Binary file (73.1 kB)
 
command_responses/heated_seats_deactivated.m4a DELETED
Binary file (58.6 kB)
 
command_responses/massage_seats_activated.m4a DELETED
Binary file (71.1 kB)
 
command_responses/massage_seats_deactivated.m4a DELETED
Binary file (70.3 kB)
 
commands.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class ResponseManager:
2
+ def activate_heated_seats(self):
3
+ return "assets\command_responses\heated_activated.wav"
4
+
5
+ def deactivate_heated_seats(self):
6
+ return "assets\command_responses\heated_deactivated.wav"
7
+
8
+ def activate_cooled_seats(self):
9
+ return "assets\command_responses\cooled_activated.wav"
10
+
11
+ def deactivate_cooled_seats(self):
12
+ return "assets\command_responses\cooled_deactivated.wav"
13
+
14
+ def activate_massage_seats(self):
15
+ return "assets\command_responses\massage_activated.wav"
16
+
17
+ def deactivate_massage_seats(self):
18
+ return "assets\command_responses\massage_deactivated.wav"
constants.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from commands import ResponseManager
2
+ from dotenv import load_dotenv
3
+ from transformers import Speech2TextProcessor, Speech2TextForConditionalGeneration
4
+ import os
5
+
6
+ load_dotenv()
7
+
8
+ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
9
+ MODEL = os.getenv("MODEL")
10
+
11
+ rs = ResponseManager()
12
+
13
+ resoponses = {
14
+ "heated_seats_on": rs.activate_heated_seats,
15
+ "heated_seats_off": rs.deactivate_heated_seats,
16
+ "cooled_seats_on": rs.activate_cooled_seats,
17
+ "cooled_seats_off": rs.deactivate_cooled_seats,
18
+ "massage_seats_on": rs.activate_massage_seats,
19
+ "massage_seats_off": rs.deactivate_massage_seats,
20
+ }
21
+
22
+ id2label = {
23
+ 1: "massage_seats_on",
24
+ 2: "massage_seats_off",
25
+ 3: "heated_seats_on",
26
+ 4: "heated_seats_off",
27
+ 5: "cooled_seats_on",
28
+ 6: "cooled_seats_off",
29
+ }
30
+
31
+ text_respnses = {
32
+ "massage_seats_on": "Massage seats activated",
33
+ "massage_seats_off": "Massage seats deactivated",
34
+ "heated_seats_on": "Heated seats activated",
35
+ "heated_seats_off": "Heated seats deactivated",
36
+ "cooled_seats_on": "Cooled seats activated",
37
+ "cooled_seats_off": "Cooled seats deactivated",
38
+ }
39
+
40
+ model = Speech2TextForConditionalGeneration.from_pretrained(
41
+ "facebook/s2t-small-librispeech-asr"
42
+ )
43
+
44
+ processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-librispeech-asr")
flagged/audio/tmp7zujjp6r.wav ADDED
Binary file (16.7 kB). View file
 
flagged/audio/tmpxmty_reu.wav ADDED
Binary file (16.7 kB). View file
 
flagged/component 0/tmp4mx6cxo6.wav ADDED
Binary file (10.1 kB). View file
 
flagged/component 0/tmpj5vph7ui.wav ADDED
Binary file (9.56 kB). View file
 
flagged/log.csv ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ audio,output,flag,username,timestamp
2
+ C:\Users\admin\Desktop\DS JRP\Programming\Python\Portfolio\Voice_Commands\flagged\audio\tmp7zujjp6r.wav,,,,2023-02-18 19:27:17.163146
3
+ C:\Users\admin\Desktop\DS JRP\Programming\Python\Portfolio\Voice_Commands\flagged\audio\tmpxmty_reu.wav,,,,2023-02-18 19:27:19.327085
4
+ C:\Users\admin\Desktop\DS JRP\Programming\Python\Portfolio\Voice_Commands\flagged\component 0\tmp4mx6cxo6.wav,,,,2023-02-19 19:21:00.276808
5
+ C:\Users\admin\Desktop\DS JRP\Programming\Python\Portfolio\Voice_Commands\flagged\component 0\tmpj5vph7ui.wav,,,,2023-02-19 19:22:46.434333
6
+ ,my neck is cold,,,2023-02-19 19:28:56.486805
7
+ ,my neck need no more heating,,,2023-02-19 19:29:16.234959
packages.txt DELETED
@@ -1 +0,0 @@
1
- python3-gi
 
 
run_command_responses.py DELETED
@@ -1,21 +0,0 @@
1
- from playsound import playsound
2
-
3
-
4
- class ResponseManager:
5
- def activate_heated_seats():
6
- playsound("assets\command_responses\heated_activated.wav")
7
-
8
- def deactivate_heated_seats():
9
- playsound("assets\command_responses\heated_deactivated.wav")
10
-
11
- def activate_cooled_seats():
12
- playsound("assets\command_responses\cooled_activated.wav")
13
-
14
- def deactivate_cooled_seats():
15
- playsound("assets\command_responses\cooled_deactivated.wav")
16
-
17
- def activate_massage_seats():
18
- playsound("assets\command_responses\massage_activated.wav")
19
-
20
- def deactivate_massage_seats():
21
- playsound("assets\command_responses\massage_deactivated.wav")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
script.py DELETED
@@ -1,12 +0,0 @@
1
- import os
2
- from pydub import AudioSegment
3
-
4
- path = "command_responses"
5
- file_names = os.listdir(path)
6
- res_path = "assets\command_responses"
7
-
8
- for file_name in file_names:
9
- m4a_file = file_name
10
- wav_filename = os.path.splitext(file_name)[0] + ".wav"
11
- track = AudioSegment.from_file(os.path.join(path, m4a_file), format="m4a")
12
- file_handle = track.export(os.path.join(res_path, wav_filename), format="wav")