MaxBrodeurUrbas commited on
Commit
c5a679a
·
1 Parent(s): e75e1f6

adding meta data for feedback loop

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -3,6 +3,7 @@ import requests
3
  import json
4
  from json.decoder import JSONDecodeError
5
  import time
 
6
  import sys
7
  from subprocess import call
8
  from pip._internal import main as pip
@@ -34,6 +35,10 @@ from io import BytesIO
34
  run_cmd('pip -q install pydub')
35
  from pydub import AudioSegment
36
 
 
 
 
 
37
  def predict(audio_file_path):
38
  if(audio_file_path == None):
39
  output = "Please record your voice using the record button before submitting :)"
@@ -51,6 +56,10 @@ def predict(audio_file_path):
51
  # If authentication is enabled, set the authorization header
52
  headers['Authorization'] = f'Bearer {key}'
53
  # Make the request and display the response
 
 
 
 
54
  resp = requests.post(scoring_uri, input_data, headers=headers)
55
  try:
56
  obj = json.loads(resp.text)
@@ -88,6 +97,14 @@ def predict(audio_file_path):
88
 
89
  btn_label_dict = {'Child': 'child_unknown', 'Teen Female': 'teens_female', 'Teen Male':'teens_male', 'Adult Female':'twenties+_female', 'Adult Male':'twenties+_male'}
90
 
 
 
 
 
 
 
 
 
91
  def send_flag_correction(btn):
92
  correct_label = btn
93
  correct_label = btn_label_dict[btn]
@@ -97,7 +114,7 @@ def send_flag_correction(btn):
97
  headers['Authorization'] = f'Bearer {key}'
98
 
99
  # format a json object containing the correct_label variable
100
- input_data = json.dumps({"correct_label": correct_label})
101
 
102
  resp = requests.post(scoring_uri + "?feedback", input_data, headers=headers)
103
  print(resp.text)
 
3
  import json
4
  from json.decoder import JSONDecodeError
5
  import time
6
+ import uuid
7
  import sys
8
  from subprocess import call
9
  from pip._internal import main as pip
 
35
  run_cmd('pip -q install pydub')
36
  from pydub import AudioSegment
37
 
38
+ current_session_id = ""
39
+ DEMO_APP_ID = "demo_app_id"
40
+ DEMO_USER_ID = "demo_user_id"
41
+
42
  def predict(audio_file_path):
43
  if(audio_file_path == None):
44
  output = "Please record your voice using the record button before submitting :)"
 
56
  # If authentication is enabled, set the authorization header
57
  headers['Authorization'] = f'Bearer {key}'
58
  # Make the request and display the response
59
+ global current_session_id
60
+ current_session_id = str(uuid.uuid4())
61
+
62
+ input_data = append_auth_bytes(input_data)
63
  resp = requests.post(scoring_uri, input_data, headers=headers)
64
  try:
65
  obj = json.loads(resp.text)
 
97
 
98
  btn_label_dict = {'Child': 'child_unknown', 'Teen Female': 'teens_female', 'Teen Male':'teens_male', 'Adult Female':'twenties+_female', 'Adult Male':'twenties+_male'}
99
 
100
+ def append_auth_bytes(input_data):
101
+ auth_string = DEMO_APP_ID + str(len(DEMO_APP_ID)) + DEMO_USER_ID + str(len(DEMO_USER_ID)) + current_session_id + str(len(current_session_id))
102
+ print(auth_string)
103
+ auth_bytes = bytes(auth_string, 'utf-8')
104
+
105
+ new_input_data = input_data + auth_bytes
106
+ return new_input_data
107
+
108
  def send_flag_correction(btn):
109
  correct_label = btn
110
  correct_label = btn_label_dict[btn]
 
114
  headers['Authorization'] = f'Bearer {key}'
115
 
116
  # format a json object containing the correct_label variable
117
+ input_data = json.dumps({"correct_label": correct_label, "session_id": current_session_id})
118
 
119
  resp = requests.post(scoring_uri + "?feedback", input_data, headers=headers)
120
  print(resp.text)