def test_in_interface(self): x_img = gr.test_data.BASE64_IMAGE def rgb_distribution(img): rgb_dist = np.mean(img, axis=(0, 1)) rgb_dist /= np.sum(rgb_dist) rgb_dist = np.round(rgb_dist, decimals=2) return { "red": rgb_dist[0], "green": rgb_dist[1], "blue": rgb_dist[2], } iface = gr.Interface(rgb_distribution, "image", "label") output = iface.process([x_img])[0][0] self.assertDictEqual( output, { 'label': 'red', 'confidences': [{ 'label': 'red', 'confidence': 0.44 }, { 'label': 'green', 'confidence': 0.28 }, { 'label': 'blue', 'confidence': 0.28 }] })
def test_in_interface(self): def generate_noise(width, height): return np.random.randint(0, 256, (width, height, 3)) iface = gr.Interface(generate_noise, ["slider", "slider"], "image") self.assertTrue( iface.process([10, 20])[0][0].startswith("data:image/png;base64"))
def test_in_interface(self): def generate_noise(duration): return 8000, np.random.randint(-256, 256, (duration, 3)) iface = gr.Interface(generate_noise, "slider", "audio") self.assertTrue( iface.process([100])[0][0].startswith("data:audio/wav;base64"))
def test_in_interface(self): def bold_text(text): return "<strong>" + text + "</strong>" iface = gr.Interface(bold_text, "text", "html") self.assertEqual( iface.process(["test"])[0][0], "<strong>test</strong>")
def test_in_interface(self): carousel_output = gr.outputs.Carousel(["text", "image"], label="Disease") def report(img): results = [] for i, mode in enumerate(["Red", "Green", "Blue"]): color_filter = np.array([0, 0, 0]) color_filter[i] = 1 results.append([mode, img * color_filter]) return results iface = gr.Interface(report, gr.inputs.Image(type="numpy"), carousel_output) self.assertEqual( iface.process([gr.test_data.BASE64_IMAGE])[0], [[[ 'Red', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD0AAABECAIAAAC9Laq3AAAFFElEQVR4nO3aT2gcVRzA8U+MTZq6xZBKdYvFFYyCtFq0UO3FehEUe1E8+AeaUw+C2pPiyS14UQ9tvXlroZ5EqVgrKmq8aAQjVXvQNuIWYxtLIlsSog0tehgnndmdmZ3ZXdMU8j2Et+/NvPfN2/f7vTeT9PzjquSaKy3QJiveS8uK99Ky4r20r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ch3GknWScuYLqJb9muHIafBaTsKurhr3xw7SRyOaL6Da9yM/4Fs6tZgvoG3dt76N+gfaDbBaHMV3YgAAAABJRU5ErkJggg==' ]]])
def test_in_interface(self): x_img = media_data.BASE64_IMAGE def rgb_distribution(img): rgb_dist = np.mean(img, axis=(0, 1)) rgb_dist /= np.sum(rgb_dist) rgb_dist = np.round(rgb_dist, decimals=2) return { "red": rgb_dist[0], "green": rgb_dist[1], "blue": rgb_dist[2], } iface = gr.Interface(rgb_distribution, "image", "label") output = iface.process([x_img])[0] self.assertDictEqual( output, { "label": "red", "confidences": [ {"label": "red", "confidence": 0.44}, {"label": "green", "confidence": 0.28}, {"label": "blue", "confidence": 0.28}, ], }, )
def test_as_component(self): def write_file(content): with open("test.txt", "w") as f: f.write(content) return "test.txt" iface = gr.Interface(write_file, "text", "file") self.assertDictEqual( iface.process(["hello world"])[0], { "name": "test.txt", "size": 11, "data": "data:text/plain;base64,aGVsbG8gd29ybGQ=", }, ) file_output = gr.outputs.File() with tempfile.TemporaryDirectory() as tmpdirname: to_save = file_output.save_flagged( tmpdirname, "file_output", [media_data.BASE64_FILE], None ) self.assertEqual("file_output/0", to_save) to_save = file_output.save_flagged( tmpdirname, "file_output", [media_data.BASE64_FILE], None ) self.assertEqual("file_output/1", to_save)
def test_speech_recognition_model(self): interface_info = gr.external.load_interface( "models/facebook/wav2vec2-base-960h") io = gr.Interface(**interface_info) io.api_mode = True output = io("gradio/test_data/test_audio.wav") self.assertIsNotNone(output)
def test_speech_recognition_model(self): interface_info = gr.external.load_interface( "models/jonatasgrosman/wav2vec2-large-xlsr-53-english") io = gr.Interface(**interface_info) io.api_mode = True output = io("test/test_data/test_audio.wav") self.assertIsNotNone(output)
def test_input_output_mapping(self): io = gr.Interface(inputs='sketchpad', outputs='text', fn=lambda x: x, analytics_enabled=False) self.assertIsInstance(io.input_interfaces[0], gradio.inputs.Image) self.assertIsInstance(io.output_interfaces[0], gradio.outputs.Textbox)
def test_numerical_to_label_space(self): interface_info = gr.external.load_interface( "spaces/abidlabs/titanic-survival") io = gr.Interface(**interface_info) io.api_mode = True output = io("male", 77, 10) self.assertLess(output['Survives'], 0.5)
def test_in_interface(self): checkboxes_input = gr.inputs.CheckboxGroup(["a", "b", "c"]) iface = gr.Interface(lambda x: "|".join(x), checkboxes_input, "textbox") self.assertEqual(iface.process([["a", "c"]])[0], ["a|c"]) self.assertEqual(iface.process([[]])[0], [""]) checkboxes_input = gr.inputs.CheckboxGroup(["a", "b", "c"], type="index") iface = gr.Interface(lambda x: "|".join(map(str, x)), checkboxes_input, "textbox", interpretation="default") self.assertEqual(iface.process([["a", "c"]])[0], ["0|2"]) scores, alternative_outputs = iface.interpret([["a", "c"]]) self.assertEqual(scores, [[[-1, None], [None, -1], [-1, None]]]) self.assertEqual(alternative_outputs, [[['2'], ['0|2|1'], ['0']]])
def test_image_classification_model(self): interface_info = gr.external.load_interface( "models/google/vit-base-patch16-224") io = gr.Interface(**interface_info) io.api_mode = True output = io("test/test_data/lion.jpg") self.assertGreater(output['lion'], 0.5)
def launch_interface(args): io = gradio.Interface(inputs=args.inputs, outputs=args.outputs, model=mdl, model_type='pyfunc') httpd, _, _ = io.launch(share=args.share, validate=False) class ServiceExit(Exception): """ Custom exception which is used to trigger the clean exit of all running threads and the main program. """ pass def service_shutdown(signum, frame): print('Shutting server down due to signal {}'.format(signum)) httpd.shutdown() raise ServiceExit signal.signal(signal.SIGTERM, service_shutdown) signal.signal(signal.SIGINT, service_shutdown) try: # Keep the main thread running, otherwise signals are ignored. while True: time.sleep(0.5) except ServiceExit: pass
def test_in_interface(self): def check_odd(array): return array % 2 == 0 iface = gr.Interface(check_odd, "numpy", "numpy") self.assertEqual( iface.process([[2, 3, 4]])[0][0], {"data": [[True, False, True]]})
def test_output_interface_is_instance(self): out = gradio.outputs.Label() io = gr.Interface(inputs='sketchpad', outputs=out, fn=lambda x: x, analytics_enabled=False) self.assertEqual(io.output_interfaces[0], out)
def test_input_interface_is_instance(self): inp = gradio.inputs.Image() io = gr.Interface(inputs=inp, outputs='text', fn=lambda x: x, analytics_enabled=False) self.assertEqual(io.input_interfaces[0], inp)
def test_in_interface(self): Image3D = media_data.BASE64_MODEL3D iface = gr.Interface(lambda x: x, "model3d", "model3d") self.assertEqual( iface.process([Image3D])[0]["data"], Image3D["data"].replace("@file/gltf", ""), )
def interact(self, add_residual=False, source='upload', label=None, share=False): """ Uses gradio to create a small interactive interface for the separation algorithm. Fair warning, there may be some race conditions with this... When you call this from a notebook, the interface will be displayed below the cell. When you call this from a regular Python script, you'll see a link print out (a localhost link and a gradio link if you called this with sharing on). The sessions will last for the duration of the notebook or the script. To use this functionality, you must install gradio: `pip install gradio`. Args: add_residual: Whether or not to add the residual signal. source: Either "upload" (upload a file to separate), or "microphone", record. share: Whether or not to create a public gradio link. kwargs: Keyword arguments to gradio. Example: >>> import nussl >>> nussl.separation.primitive.HPSS( >>> nussl.AudioSignal()).interact() """ try: import gradio except: # pragma: no cover raise ImportError( "To use this functionality, you must install gradio: " "pip install gradio.") def _separate(file_obj): # pragma: no cover mix = AudioSignal(file_obj.name) self.audio_signal = mix estimates = self() if add_residual: estimates.append(mix - estimates[0]) estimates = {f'Estimate {i}': s for i, s in enumerate(estimates)} html = play_utils.multitrack(estimates, ext='.mp3', display=False) return html if label is None: label = f"Separation via {type(self).__name__}" audio_in = gradio.inputs.Audio(source=source, type="file", label=label) gradio.Interface( fn=_separate, inputs=audio_in, outputs="html", ).launch(share=share)
def test_sentiment_model(self): interface_info = gr.external.load_interface( "models/distilbert-base-uncased-finetuned-sst-2-english", alias="sentiment_classifier") io = gr.Interface(**interface_info) io.api_mode = True output = io("I am happy, I love you.") self.assertGreater(output['POSITIVE'], 0.5)
def test_text_to_image_model(self): interface_info = gr.external.load_interface( "models/osanseviero/BigGAN-deep-128") io = gr.Interface(**interface_info) io.api_mode = True filename = io("chest") self.assertTrue( filename.endswith(".jpg") or filename.endswith(".jpeg"))
def test_show_error(self): io = gr.Interface(lambda x: 1 / x, "number", "number") app, _, _ = io.launch(show_error=True, prevent_thread_lock=True) client = app.test_client() response = client.post('/api/predict/', json={"data": [0]}) self.assertEqual(response.status_code, 500) self.assertTrue("error" in response.get_json()) io.close()
def test_in_interface(self): x_file = gr.test_data.BASE64_FILE def get_size_of_file(file_obj): return os.path.getsize(file_obj.name) iface = gr.Interface(get_size_of_file, "file", "number") self.assertEqual(iface.process([[x_file]])[0], [10558])
def test_in_interface(self): iface = gr.Interface(lambda x: x**2, "slider", "textbox") self.assertEqual(iface.process([2])[0], ['4']) iface = gr.Interface(lambda x: x**2, "slider", "textbox", interpretation="default") scores, alternative_outputs = iface.interpret([2]) self.assertEqual(scores, [[ -4.0, 200.08163265306123, 812.3265306122449, 1832.7346938775513, 3261.3061224489797, 5098.040816326531, 7342.938775510205, 9996.0 ]]) self.assertEqual( alternative_outputs, [[['0.0'], ['204.08163265306123'], ['816.3265306122449'], ['1836.7346938775513'], ['3265.3061224489797'], ['5102.040816326531'], ['7346.938775510205'], ['10000.0']]])
def test_in_interface(self): iface = gr.Interface(lambda x: x**2, "number", "textbox") self.assertEqual(iface.process([2])[0], ['4.0']) iface = gr.Interface(lambda x: x**2, "number", "textbox", interpretation="default") scores, alternative_outputs = iface.interpret([2]) self.assertEqual(scores, [[(1.94, -0.23640000000000017), (1.96, -0.15840000000000032), (1.98, -0.07960000000000012), [2, None], (2.02, 0.08040000000000003), (2.04, 0.16159999999999997), (2.06, 0.24359999999999982)]]) self.assertEqual(alternative_outputs, [[['3.7636'], ['3.8415999999999997'], ['3.9204'], ['4.0804'], ['4.1616'], ['4.2436']]])
def test_prediction(self): def model(x): return 2 * x io = gr.Interface(inputs='textbox', outputs='text', fn=model, analytics_enabled=False) self.assertEqual(io.predict[0](11), 22)
def launch(): """ Launch gradio instance """ typer.echo("Launching gradio instance") _, gradio_interface_url, _ = gr.Interface( fn=greet, inputs="text", outputs="text" ).launch() typer.launch(gradio_interface_url)
def test_state_value(self): io = gr.Interface(lambda x: len(x), "text", "label") io.launch(prevent_thread_lock=True) app, _, _ = io.launch(prevent_thread_lock=True) with app.test_request_context(): networking.set_state("test") client = app.test_client() client.post('/api/predict/', json={"data": [0]}) self.assertEquals(networking.get_state(), "test")
def gradio_gui(): """ gradioのGui画面を定義する """ image = gr.inputs.Image(label="Input Image", ) output = gr.outputs.Image(label="Output Image", type="numpy") interface = gr.Interface(fn=predict, inputs=image, outputs=output) interface.launch()
def test_image_to_image_space(self): def assertIsFile(path): if not pathlib.Path(path).resolve().is_file(): raise AssertionError("File does not exist: %s" % str(path)) interface_info = gr.external.load_interface( "spaces/abidlabs/image-identity") io = gr.Interface(**interface_info) output = io("test/test_data/lion.jpg") assertIsFile(output)