gradio/test/test_interface.py

32 lines
1.1 KiB
Python
Raw Normal View History

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):
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
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)
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)
def test_prediction(self):
2019-06-19 04:13:50 +08:00
def model(x):
return 2*x
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()