This commit is contained in:
dawoodkhan82 2020-07-14 12:17:52 -04:00
commit bdbdc3ded6
2 changed files with 28 additions and 13 deletions

View File

@ -2,12 +2,12 @@
# Welcome to `gradio` :rocket:
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:
<p align="center">
<img src="https://i.ibb.co/m0skD0j/bert.gif" alt="drawing"/>
</p>
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

View File

@ -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)
shortcuts[shortcut] = cls(**parameters)