2019-02-28 13:51:51 +08:00
|
|
|
import unittest
|
2019-03-08 05:53:34 +08:00
|
|
|
import numpy as np
|
2020-06-10 08:00:30 +08:00
|
|
|
import gradio as gr
|
2019-02-28 13:51:51 +08:00
|
|
|
import gradio.inputs
|
|
|
|
import gradio.outputs
|
|
|
|
|
|
|
|
|
|
|
|
class TestInterface(unittest.TestCase):
|
|
|
|
def test_input_output_mapping(self):
|
2020-07-07 13:51:07 +08:00
|
|
|
io = gr.Interface(inputs='SketCHPad', outputs='textBOX', fn=lambda x: x)
|
2020-06-12 03:31:44 +08:00
|
|
|
self.assertIsInstance(io.input_interfaces[0], gradio.inputs.Sketchpad)
|
|
|
|
self.assertIsInstance(io.output_interfaces[0], gradio.outputs.Textbox)
|
2019-02-28 13:51:51 +08:00
|
|
|
|
2019-03-06 14:45:08 +08:00
|
|
|
def test_input_interface_is_instance(self):
|
2020-07-01 07:11:35 +08:00
|
|
|
inp = gradio.inputs.Image()
|
2020-06-12 03:31:44 +08:00
|
|
|
io = gr.Interface(inputs=inp, outputs='textBOX', fn=lambda x: x)
|
|
|
|
self.assertEqual(io.input_interfaces[0], inp)
|
2019-03-06 14:45:08 +08:00
|
|
|
|
|
|
|
def test_output_interface_is_instance(self):
|
2020-06-12 03:31:44 +08:00
|
|
|
out = gradio.outputs.Label()
|
|
|
|
io = gr.Interface(inputs='SketCHPad', outputs=out, fn=lambda x: x)
|
|
|
|
self.assertEqual(io.output_interfaces[0], out)
|
2019-03-06 14:45:08 +08:00
|
|
|
|
2020-07-07 13:51:07 +08:00
|
|
|
def test_prediction(self):
|
2019-06-19 04:13:50 +08:00
|
|
|
def model(x):
|
|
|
|
return 2*x
|
2020-07-07 13:51:07 +08:00
|
|
|
io = gr.Interface(inputs='textbox', outputs='textBOX', fn=model)
|
|
|
|
self.assertEqual(io.predict[0](11), 22)
|
2019-03-08 05:53:34 +08:00
|
|
|
|
2019-02-28 13:51:51 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-06-19 04:13:50 +08:00
|
|
|
unittest.main()
|