audio flagging

This commit is contained in:
aliabd 2020-08-02 23:01:59 -07:00
parent 7595e1e41b
commit 82d622028c
2 changed files with 13 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import time
import warnings import warnings
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
import base64
import numpy as np import numpy as np
import PIL.Image import PIL.Image
import PIL.ImageOps import PIL.ImageOps
@ -397,7 +398,7 @@ class Webcam(AbstractInput):
im = preprocessing_utils.decode_base64_to_image(data) im = preprocessing_utils.decode_base64_to_image(data)
timestamp = datetime.datetime.now() timestamp = datetime.datetime.now()
filename = f'input_{timestamp.strftime("%Y-%m-%d-%H-%M-%S")}.png' filename = f'input_{timestamp.strftime("%Y-%m-%d-%H-%M-%S")}.png'
im.save(f'{dir}/{filename}', 'PNG') im.save('{}/{}'.format(dir, filename), 'PNG')
return filename return filename
@ -436,6 +437,15 @@ class Microphone(AbstractInput):
_, signal = scipy.io.wavfile.read(file_obj.name) _, signal = scipy.io.wavfile.read(file_obj.name)
return signal return signal
def rebuild(self, dir, data):
inp = data.split(';')[1].split(',')[1]
wav_obj = base64.b64decode(inp)
timestamp = datetime.datetime.now()
filename = f'input_{timestamp.strftime("%Y-%m-%d-%H-%M-%S")}.wav'
with open("{}/{}".format(dir, filename), "wb+") as f:
f.write(wav_obj)
return filename
# Automatically adds all shortcut implementations in AbstractInput into a dictionary. # Automatically adds all shortcut implementations in AbstractInput into a dictionary.
shortcuts = {} shortcuts = {}

View File

@ -4,7 +4,6 @@ interface using the input and output types.
""" """
import tempfile import tempfile
import traceback
import webbrowser import webbrowser
import gradio.inputs import gradio.inputs
@ -217,7 +216,8 @@ class Interface:
def launch(self, inline=None, inbrowser=None, share=False, debug=False): def launch(self, inline=None, inbrowser=None, share=False, debug=False):
""" """
Parameters Parameters
share (bool): whether to create a publicly shareable link from your computer for the interface. share (bool): whether to create a publicly shareable link from
your computer for the interface.
""" """
output_directory = tempfile.mkdtemp() output_directory = tempfile.mkdtemp()