Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_postprocessing_1D_array_no_confidences(self):
array = np.array([0.1, 0.2, 0, 0.7, 0])
true_label = {outputs.Label.LABEL_KEY: 3}
out = outputs.Label(show_confidences=False)
label = json.loads(out.postprocess(array))
self.assertDictEqual(label, true_label)
def test_set_sample_data(self):
test_array = ["test1", "test2", "test3"]
temp_dir = tempfile.mkdtemp()
inp = inputs.Sketchpad()
out = outputs.Label()
networking.build_template(temp_dir, inp, out)
networking.set_sample_data_in_config_file(temp_dir, test_array)
# We need to come up with a better way so that the config file isn't invalid json unless
# the following parameters are set... (TODO: abidlabs)
networking.set_always_flagged_in_config_file(temp_dir, False)
networking.set_disabled_in_config_file(temp_dir, False)
config_file = os.path.join(temp_dir, 'static/config.json')
with open(config_file) as json_file:
data = json.load(json_file)
self.assertTrue(test_array == data["sample_inputs"])
def test_postprocessing_int(self):
true_label_array = np.array([[[3]]])
true_label = {outputs.Label.LABEL_KEY: 3}
out = outputs.Label()
label = json.loads(out.postprocess(true_label_array))
self.assertDictEqual(label, true_label)
def test_path_exists(self):
out = outputs.Label()
path = outputs.BASE_OUTPUT_INTERFACE_TEMPLATE_PATH.format(out.get_name())
self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_preprocessing(self):
inp = inputs.ImageUpload()
inp.image_height = 48
inp.image_width = 48
array = inp.preprocess(BASE64_IMG)
self.assertEqual(array.shape, (1, 48, 48, 3))
def test_preprocessing(self):
inp = inputs.Webcam()
array = inp.preprocess(BASE64_IMG)
self.assertEqual(array.shape, (1, 224, 224, 3))
def test_input_output_mapping(self):
io = Interface(inputs='SketCHPad', outputs='textBOX', model=lambda x: x, model_type='function')
self.assertIsInstance(io.input_interface, gradio.inputs.Sketchpad)
self.assertIsInstance(io.output_interface, gradio.outputs.Textbox)
def test_path_exists(self):
inp = inputs.Sketchpad()
path = inputs.BASE_INPUT_INTERFACE_JS_PATH.format(inp.get_name())
self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_path_exists(self):
inp = inputs.Sketchpad()
path = inputs.BASE_INPUT_INTERFACE_JS_PATH.format(inp.get_name())
self.assertTrue(os.path.exists(os.path.join(PACKAGE_NAME, path)))
def test_input_interface_is_instance(self):
inp = gradio.inputs.ImageUpload()
io = Interface(inputs=inp, outputs='textBOX', model=lambda x: x, model_type='function')
self.assertEqual(io.input_interface, inp)