gradio/test/test_interface.py

36 lines
1.3 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):
2020-08-11 23:44:33 +08:00
io = gr.Interface(inputs='sketchpad', outputs='text', fn=lambda x: x,
analytics_enabled=False)
2020-08-11 04:52:43 +08:00
self.assertIsInstance(io.input_interfaces[0], gradio.inputs.Image)
2020-06-12 03:31:44 +08:00
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-08-11 23:44:33 +08:00
io = gr.Interface(inputs=inp, outputs='text', fn=lambda x: x,
2020-08-11 00:27:29 +08:00
analytics_enabled=False)
2020-06-12 03:31:44 +08:00
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()
2020-08-11 23:44:33 +08:00
io = gr.Interface(inputs='sketchpad', outputs=out, fn=lambda x: x,
2020-08-11 00:27:29 +08:00
analytics_enabled=False)
2020-06-12 03:31:44 +08:00
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
2020-08-11 23:44:33 +08:00
io = gr.Interface(inputs='textbox', outputs='text', fn=model,
2020-08-11 00:27:29 +08:00
analytics_enabled=False)
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()