From d177d8a66cf8b0e4a31d9bde36b4fbb69b77e94e Mon Sep 17 00:00:00 2001 From: Mohamed El-Geish Date: Sun, 12 Jul 2020 21:13:19 -0700 Subject: [PATCH 1/5] Fixed microphone shortcut and preprocessing --- gradio/inputs.py | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/gradio/inputs.py b/gradio/inputs.py index cfd1c51e3f..b84365ce80 100644 --- a/gradio/inputs.py +++ b/gradio/inputs.py @@ -4,15 +4,18 @@ This module defines various classes that can serve as the `input` to an interfac automatically added to a registry, which allows them to be easily referenced in other parts of the code. """ -from abc import ABC, abstractmethod -from gradio import preprocessing_utils, validation_data -import numpy as np -import PIL.Image, PIL.ImageOps +import datetime +import json +import os import time import warnings -import json -import datetime -import os +from abc import ABC, abstractmethod + +import numpy as np +import PIL.Image +import PIL.ImageOps +import scipy.io.wavfile +from gradio import preprocessing_utils, validation_data # Where to find the static resources associated with each template. # BASE_INPUT_INTERFACE_TEMPLATE_PATH = 'static/js/interfaces/input/{}.js' @@ -269,20 +272,32 @@ class Image(AbstractInput): class Microphone(AbstractInput): - def __init__(self, label=None): + def __init__(self, preprocessing=None, label=None): super().__init__(label) + if preprocessing is None or preprocessing == "mfcc": + self.preprocessing = preprocessing + else: + raise ValueError("unexpected value for preprocessing", preprocessing) + + @classmethod + def get_shortcut_implementations(cls): + return { + "microphone": {}, + } def preprocess(self, inp): """ By default, no pre-processing is applied to a microphone input file """ file_obj = preprocessing_utils.decode_base64_to_wav_file(inp) - mfcc_array = preprocessing_utils.generate_mfcc_features_from_audio_file(file_obj.name) - return mfcc_array + if self.preprocessing == "mfcc": + return preprocessing_utils.generate_mfcc_features_from_audio_file(file_obj.name) + _, signal = scipy.io.wavfile.read(file_obj.name) + return signal # Automatically adds all shortcut implementations in AbstractInput into a dictionary. shortcuts = {} for cls in AbstractInput.__subclasses__(): for shortcut, parameters in cls.get_shortcut_implementations().items(): - shortcuts[shortcut] = cls(**parameters) \ No newline at end of file + shortcuts[shortcut] = cls(**parameters) From 6bba4e1e5fe466c6858ce35bfb6b1c213d2834d5 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 14 Jul 2020 06:48:34 -0500 Subject: [PATCH 2/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c1b293028d..ecf1b7c039 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ # Welcome to `gradio` :rocket: +Gradio allows you to quickly create customizable UI components around your TensorFlow or PyTorch models, or even arbitrary Python functions. Mix and match components to support any combination of inputs and outputs. Our core library is free and open-source!. Gradio makes it easy for you to "play around" with your model in your browser by dragging-and-dropping in your own images (or pasting your own text, recording your own voice, etc.) and seeing what the model outputs. Gradio can also generate a share link which allows anyone, anywhere to use the interface as the model continues to run on your machine. +

drawing

-At Gradio, we often try to understand what inputs a model is particularly sensitive to. To help facilitate this, we've developed and open-sourced `gradio`, a python library that allows you to quickly create input and output interfaces over trained models to make it easy for you to "play around" with your model in your browser by dragging-and-dropping in your own images (or pasting your own text, recording your own voice, etc.) and seeing what the model outputs. `gradio` can also generate a share link which allows anyone, anywhere to use the interface as the model continues to run on your machine. - Gradio is useful for: * Creating demos of your machine learning code for clients / collaborators / users * Getting feedback on model performance from users From 703ca497b4abea7a8951606474ed5583371c3050 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 14 Jul 2020 06:49:08 -0500 Subject: [PATCH 3/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ecf1b7c039..820d7e7d93 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Welcome to `gradio` :rocket: -Gradio allows you to quickly create customizable UI components around your TensorFlow or PyTorch models, or even arbitrary Python functions. Mix and match components to support any combination of inputs and outputs. Our core library is free and open-source!. Gradio makes it easy for you to "play around" with your model in your browser by dragging-and-dropping in your own images (or pasting your own text, recording your own voice, etc.) and seeing what the model outputs. Gradio can also generate a share link which allows anyone, anywhere to use the interface as the model continues to run on your machine. +Gradio allows you to quickly create customizable UI components around your TensorFlow or PyTorch models, or even arbitrary Python functions. Mix and match components to support any combination of inputs and outputs. Our core library is free and open-source!. Gradio makes it easy for you to "play around" with your model in your browser by dragging-and-dropping in your own images (or pasting your own text, recording your own voice, etc.) and seeing what the model outputs. Gradio can also generate a share link which allows anyone, anywhere to use the interface as the model continues to run on your machine. Take a look:

drawing From 493f58e92e10ddeeb38e097116547b8d8713d9e4 Mon Sep 17 00:00:00 2001 From: Ali Abdalla Date: Tue, 14 Jul 2020 06:42:01 -0700 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 820d7e7d93..3fe6f8706f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Welcome to `gradio` :rocket: -Gradio allows you to quickly create customizable UI components around your TensorFlow or PyTorch models, or even arbitrary Python functions. Mix and match components to support any combination of inputs and outputs. Our core library is free and open-source!. Gradio makes it easy for you to "play around" with your model in your browser by dragging-and-dropping in your own images (or pasting your own text, recording your own voice, etc.) and seeing what the model outputs. Gradio can also generate a share link which allows anyone, anywhere to use the interface as the model continues to run on your machine. Take a look: +Quickly create customizable UI components around your TensorFlow or PyTorch models, or even arbitrary Python functions. Mix and match components to support any combination of inputs and outputs. Gradio makes it easy for you to "play around" with your model in your browser by dragging-and-dropping in your own images (or pasting your own text, recording your own voice, etc.) and seeing what the model outputs. You can also generate a share link which allows anyone, anywhere to use the interface as the model continues to run on your machine. Our core library is free and open-source! Take a look:

drawing From 064aef577264e81bf090508ae4183cab95d7dec1 Mon Sep 17 00:00:00 2001 From: dawoodkhan82 Date: Tue, 14 Jul 2020 12:17:46 -0400 Subject: [PATCH 5/5] send analytics on background thread --- gradio/networking.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/gradio/networking.py b/gradio/networking.py index 6eaf8c25b7..4412073f23 100644 --- a/gradio/networking.py +++ b/gradio/networking.py @@ -116,6 +116,17 @@ def get_first_available_port(initial, final): ) ) +def send_prediction_analytics(interface): + data = {'input_interface': interface.input_interfaces, + 'output_interface': interface.output_interfaces, + } + try: + requests.post( + analytics_url + 'gradio-prediction-analytics/', + data=data) + except requests.ConnectionError: + pass # do not push analytics if no network + def serve_files_in_background(interface, port, directory_to_serve=None, server_name=LOCALHOST_NAME): class HTTPHandler(SimpleHTTPRequestHandler): @@ -160,17 +171,11 @@ def serve_files_in_background(interface, port, directory_to_serve=None, server_n # f.write(json.dumps(output_flag)) # f.write("\n") - # Prepare return json dictionary. self.wfile.write(json.dumps(output).encode()) - data = {'input_interface': interface.input_interfaces, - 'output_interface': interface.output_interfaces, - } - try: - requests.post( - analytics_url + 'gradio-prediction-analytics/', - data=data) - except requests.ConnectionError: - pass # do not push analytics if no network + + analytics_thread = threading.Thread( + target=send_prediction_analytics, args=[interface]) + analytics_thread.start() elif self.path == "/api/flag/": self._set_headers()