From 82d622028c9969fb7dbf4a65433df539d7ef9f28 Mon Sep 17 00:00:00 2001 From: aliabd Date: Sun, 2 Aug 2020 23:01:59 -0700 Subject: [PATCH] audio flagging --- gradio/inputs.py | 12 +++++++++++- gradio/interface.py | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gradio/inputs.py b/gradio/inputs.py index 8901b8427a..1e828304e2 100644 --- a/gradio/inputs.py +++ b/gradio/inputs.py @@ -11,6 +11,7 @@ import time import warnings from abc import ABC, abstractmethod +import base64 import numpy as np import PIL.Image import PIL.ImageOps @@ -397,7 +398,7 @@ class Webcam(AbstractInput): im = preprocessing_utils.decode_base64_to_image(data) timestamp = datetime.datetime.now() 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 @@ -436,6 +437,15 @@ class Microphone(AbstractInput): _, signal = scipy.io.wavfile.read(file_obj.name) 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. shortcuts = {} diff --git a/gradio/interface.py b/gradio/interface.py index 5f4cdf7f7e..08ef9786bf 100644 --- a/gradio/interface.py +++ b/gradio/interface.py @@ -4,7 +4,6 @@ interface using the input and output types. """ import tempfile -import traceback import webbrowser import gradio.inputs @@ -217,7 +216,8 @@ class Interface: def launch(self, inline=None, inbrowser=None, share=False, debug=False): """ 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()