fixed output component issues causing tests to fail

This commit is contained in:
Abubakar Abid 2021-10-22 07:07:24 -05:00
parent e82308eee7
commit cf9d179794
3 changed files with 6 additions and 6 deletions

View File

@ -53,7 +53,7 @@ class TestCallingLoadInterface(unittest.TestCase):
def test_image_classification_model(self): def test_image_classification_model(self):
interface_info = gr.external.load_interface("models/google/vit-base-patch16-224") interface_info = gr.external.load_interface("models/google/vit-base-patch16-224")
io = gr.Interface(**interface_info) io = gr.Interface(**interface_info)
output = io("images/lion.jpg") output = io("test/images/lion.jpg")
self.assertGreater(output['lion'], 0.5) self.assertGreater(output['lion'], 0.5)
def test_translation_model(self): def test_translation_model(self):
@ -75,7 +75,7 @@ class TestCallingLoadInterface(unittest.TestCase):
interface_info = gr.external.load_interface("spaces/abidlabs/image-identity") interface_info = gr.external.load_interface("spaces/abidlabs/image-identity")
io = gr.Interface(**interface_info) io = gr.Interface(**interface_info)
output = io("images/lion.jpg") output = io("test/images/lion.jpg")
assertIsFile(output) assertIsFile(output)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -83,7 +83,7 @@ class TestImage(unittest.TestCase):
open_and_rotate, open_and_rotate,
gr.inputs.Image(shape=(30, 10), type="file"), gr.inputs.Image(shape=(30, 10), type="file"),
"image") "image")
output = iface.process([x_img])[0][0][0] output = iface.process([x_img])[0][0]
self.assertEqual(gr.processing_utils.decode_base64_to_image(output).size, (10, 30)) self.assertEqual(gr.processing_utils.decode_base64_to_image(output).size, (10, 30))

View File

@ -62,15 +62,15 @@ class TestImage(unittest.TestCase):
def test_as_component(self): def test_as_component(self):
y_img = gr.processing_utils.decode_base64_to_image(gr.test_data.BASE64_IMAGE) y_img = gr.processing_utils.decode_base64_to_image(gr.test_data.BASE64_IMAGE)
image_output = gr.outputs.Image() image_output = gr.outputs.Image()
self.assertTrue(image_output.postprocess(y_img)[0].startswith("data:image/png;base64,iVBORw0KGgoAAA")) self.assertTrue(image_output.postprocess(y_img).startswith("data:image/png;base64,iVBORw0KGgoAAA"))
self.assertTrue(image_output.postprocess(np.array(y_img))[0].startswith("data:image/png;base64,iVBORw0KGgoAAA")) self.assertTrue(image_output.postprocess(np.array(y_img)).startswith("data:image/png;base64,iVBORw0KGgoAAA"))
def test_in_interface(self): def test_in_interface(self):
def generate_noise(width, height): def generate_noise(width, height):
return np.random.randint(0, 256, (width, height, 3)) return np.random.randint(0, 256, (width, height, 3))
iface = gr.Interface(generate_noise, ["slider", "slider"], "image") iface = gr.Interface(generate_noise, ["slider", "slider"], "image")
self.assertTrue(iface.process([10, 20])[0][0][0].startswith("data:image/png;base64")) self.assertTrue(iface.process([10, 20])[0][0].startswith("data:image/png;base64"))
class TestKeyValues(unittest.TestCase): class TestKeyValues(unittest.TestCase):
def test_in_interface(self): def test_in_interface(self):