From 5bf64861985d16af963395c926c5ba141153c162 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Sat, 23 Jan 2021 15:54:28 -0600 Subject: [PATCH] fixed permission issue in windows --- gradio/inputs.py | 4 ++-- gradio/outputs.py | 2 +- gradio/processing_utils.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gradio/inputs.py b/gradio/inputs.py index c4241ecfea..52f6d820f0 100644 --- a/gradio/inputs.py +++ b/gradio/inputs.py @@ -645,7 +645,7 @@ class Image(InputComponent): elif self.type == "numpy": return np.array(im) elif self.type == "file": - file_obj = tempfile.NamedTemporaryFile(suffix=("."+fmt.lower() if fmt is not None else ".png")) + file_obj = tempfile.NamedTemporaryFile(delete=False, suffix=("."+fmt.lower() if fmt is not None else ".png")) im.save(file_obj.name) return file_obj else: @@ -789,7 +789,7 @@ class Audio(InputComponent): leave_one_out_data = np.copy(data) start, stop = boundaries[index], boundaries[index + 1] leave_one_out_data[start:stop] = 0 - file = tempfile.NamedTemporaryFile() + file = tempfile.NamedTemporaryFile(delete=False) scipy.io.wavfile.write(file, sample_rate, leave_one_out_data) out_data = processing_utils.encode_file_to_base64(file.name, type="audio", ext="wav") leave_one_out_sets.append(out_data) diff --git a/gradio/outputs.py b/gradio/outputs.py index 85d9fe92a9..94bc84097f 100644 --- a/gradio/outputs.py +++ b/gradio/outputs.py @@ -286,7 +286,7 @@ class Audio(OutputComponent): def postprocess(self, y): if self.type in ["numpy", "file", "auto"]: if self.type == "numpy" or (self.type == "auto" and isinstance(y, tuple)): - file = tempfile.NamedTemporaryFile() + file = tempfile.NamedTemporaryFile(delete=False) scipy.io.wavfile.write(file, y[0], y[1]) y = file.name return processing_utils.encode_file_to_base64(y, type="audio", ext="wav") diff --git a/gradio/processing_utils.py b/gradio/processing_utils.py index 7a6ae0d525..fa083e1208 100644 --- a/gradio/processing_utils.py +++ b/gradio/processing_utils.py @@ -73,7 +73,7 @@ def decode_base64_to_binary(encoding): def decode_base64_to_file(encoding): - file_obj = tempfile.NamedTemporaryFile() + file_obj = tempfile.NamedTemporaryFile(delete=False) file_obj.write(decode_base64_to_binary(encoding)) file_obj.flush() return file_obj