mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-31 12:20:26 +08:00
updated PyPi version
This commit is contained in:
parent
2440411a27
commit
693e8cf4a7
@ -7,7 +7,7 @@ def reverse_audio(audio):
|
||||
return (sr, np.flipud(data))
|
||||
|
||||
|
||||
iface = gr.Interface(reverse_audio, "microphone", "audio")
|
||||
iface = gr.Interface(reverse_audio, "audio", "audio")
|
||||
|
||||
iface.test_launch()
|
||||
if __name__ == "__main__":
|
||||
|
@ -1,11 +1,10 @@
|
||||
import gradio as gr
|
||||
|
||||
|
||||
def video_flip(video):
|
||||
return video
|
||||
|
||||
|
||||
iface = gr.Interface(video_flip, gr.inputs.Video(type=None), "video")
|
||||
iface = gr.Interface(
|
||||
video_flip, "video", "playable_video", theme="huggingface")
|
||||
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -10,7 +10,7 @@ class AudioInput extends BaseComponent {
|
||||
this.state = {
|
||||
recording: false
|
||||
};
|
||||
this.src = null;
|
||||
this.src = {};
|
||||
this.key = 0; // needed to prevent audio caching
|
||||
|
||||
this.uploader = React.createRef();
|
||||
@ -37,7 +37,10 @@ class AudioInput extends BaseComponent {
|
||||
this.recorder.stop().then(({ blob, buffer }) => {
|
||||
let reader = new FileReader();
|
||||
reader.onload = function (e) {
|
||||
this.props.handleChange(e.target.result);
|
||||
this.props.handleChange({
|
||||
"name": "sample.wav",
|
||||
"data": e.target.result
|
||||
});
|
||||
}.bind(this);
|
||||
reader.readAsDataURL(blob);
|
||||
})
|
||||
@ -50,14 +53,18 @@ class AudioInput extends BaseComponent {
|
||||
};
|
||||
render() {
|
||||
if (this.props.value !== null) {
|
||||
if (this.props.value !== this.src) {
|
||||
if (this.props.value["name"] != this.src["name"] ||
|
||||
this.props.value["data"] !== this.src["data"]) {
|
||||
this.key += 1;
|
||||
this.src = this.props.value;
|
||||
this.src = {
|
||||
"name": this.props.value["name"],
|
||||
"data": this.props.value["data"]
|
||||
};
|
||||
}
|
||||
return (
|
||||
<div className="input_audio">
|
||||
<audio controls key={this.key}>
|
||||
<source src={this.props.value}></source>
|
||||
<source src={this.props.value["data"]}></source>
|
||||
</audio>
|
||||
{this.props.interpretation === null ? (
|
||||
false
|
||||
@ -137,9 +144,10 @@ class AudioInput extends BaseComponent {
|
||||
}
|
||||
var component = this;
|
||||
var ReaderObj = new FileReader();
|
||||
ReaderObj.readAsDataURL(files[0]);
|
||||
let file = files[0];
|
||||
ReaderObj.readAsDataURL(file);
|
||||
ReaderObj.onloadend = function () {
|
||||
component.props.handleChange(this.result);
|
||||
component.props.handleChange({ "name": file.name, "data": this.result });
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import React from "react";
|
||||
import BaseComponent from "../base_component";
|
||||
import ComponentExample from "../component_example";
|
||||
import { isPlayable } from "../../utils";
|
||||
|
||||
class VideoInput extends BaseComponent {
|
||||
constructor(props) {
|
||||
@ -24,17 +25,26 @@ class VideoInput extends BaseComponent {
|
||||
evt.stopPropagation();
|
||||
};
|
||||
if (this.props.value != null) {
|
||||
return (
|
||||
<div className="input_video">
|
||||
<div className="video_preview_holder">
|
||||
<video
|
||||
className="video_preview"
|
||||
controls
|
||||
src={this.props.value}
|
||||
></video>
|
||||
if (isPlayable("video", this.props.value["data"].substring(
|
||||
5, this.props.value["data"].indexOf(";")))) {
|
||||
return (
|
||||
<div className="input_video">
|
||||
<div className="video_preview_holder">
|
||||
<video
|
||||
className="video_preview"
|
||||
controls
|
||||
src={this.props.value["data"]}
|
||||
></video>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return <div className="input_video">
|
||||
<div className="video_file_holder">
|
||||
{this.props.value["name"]}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return (
|
||||
<div
|
||||
@ -80,9 +90,10 @@ class VideoInput extends BaseComponent {
|
||||
}
|
||||
var component = this;
|
||||
var ReaderObj = new FileReader();
|
||||
ReaderObj.readAsDataURL(files[0]);
|
||||
let file = files[0];
|
||||
ReaderObj.readAsDataURL(file);
|
||||
ReaderObj.onloadend = function () {
|
||||
component.props.handleChange(this.result);
|
||||
component.props.handleChange({ "name": file.name, "data": this.result });
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,30 @@
|
||||
import React from "react";
|
||||
import BaseComponent from "../base_component";
|
||||
import ComponentExample from "../component_example";
|
||||
import { isPlayable } from "../../utils";
|
||||
|
||||
class VideoOutput extends BaseComponent {
|
||||
render() {
|
||||
return this.props.value ? (
|
||||
<div className="output_video">
|
||||
<video controls src={this.props.value}></video>
|
||||
</div>
|
||||
) : (
|
||||
false
|
||||
);
|
||||
if (this.props.value) {
|
||||
if (isPlayable("video", this.props.value["data"].substring(
|
||||
5, this.props.value["data"].indexOf(";")))) {
|
||||
return <div className="output_video">
|
||||
<video controls src={this.props.value["data"]}></video>
|
||||
</div>
|
||||
} else {
|
||||
return <div className="output_video">
|
||||
<a
|
||||
href={this.props.value["data"]}
|
||||
download={this.props.value["name"]}
|
||||
className="video_file_holder"
|
||||
>
|
||||
{this.props.value["name"]}
|
||||
</a>
|
||||
</div>
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,6 +421,9 @@
|
||||
.video_preview_holder {
|
||||
@apply w-full h-full flex justify-center items-center bg-gray-200;
|
||||
}
|
||||
.video_file_holder {
|
||||
@apply w-full h-full flex justify-center items-center text-6xl p-6 break-all;
|
||||
}
|
||||
.video_preview {
|
||||
@apply w-full h-full object-contain;
|
||||
}
|
||||
@ -434,7 +437,7 @@
|
||||
@apply w-full h-full flex flex-col justify-center items-center relative inline-block;
|
||||
}
|
||||
.file_name {
|
||||
@apply text-6xl p-6;
|
||||
@apply text-6xl p-6 break-all;
|
||||
}
|
||||
.file_size {
|
||||
@apply text-2xl p-2;
|
||||
@ -521,14 +524,17 @@
|
||||
video {
|
||||
@apply h-full;
|
||||
}
|
||||
.video_file_holder {
|
||||
@apply w-full h-full flex justify-center items-center text-6xl p-6 break-all;
|
||||
}
|
||||
}
|
||||
.output_file {
|
||||
@apply w-full h-80 dark:text-gray-50;
|
||||
.file_display {
|
||||
@apply w-full h-full flex flex-col justify-center items-center relative inline-block;
|
||||
@apply w-full h-full flex flex-col justify-center items-center relative;
|
||||
}
|
||||
.file_name {
|
||||
@apply text-6xl p-6;
|
||||
@apply text-6xl p-6 break-all;
|
||||
}
|
||||
.file_size {
|
||||
@apply text-2xl p-2;
|
||||
|
@ -373,6 +373,9 @@ html {
|
||||
.video_preview_holder {
|
||||
@apply w-full h-full flex justify-center items-center bg-gray-200;
|
||||
}
|
||||
.video_file_holder {
|
||||
@apply dark:text-gray-50 w-full h-full flex justify-center items-center text-6xl p-6 break-all;
|
||||
}
|
||||
.video_preview {
|
||||
@apply w-full h-full object-contain;
|
||||
}
|
||||
@ -386,7 +389,7 @@ html {
|
||||
@apply w-full h-full flex flex-col justify-center items-center relative inline-block;
|
||||
}
|
||||
.file_name {
|
||||
@apply text-6xl p-6;
|
||||
@apply text-6xl p-6 break-all;
|
||||
}
|
||||
.file_size {
|
||||
@apply text-2xl p-1.5;
|
||||
@ -472,6 +475,9 @@ html {
|
||||
video {
|
||||
@apply h-full;
|
||||
}
|
||||
.video_file_holder {
|
||||
@apply dark:text-gray-50 w-full h-full flex justify-center items-center text-6xl p-6 break-all;
|
||||
}
|
||||
}
|
||||
.output_file {
|
||||
@apply bg-gray-200 hover:bg-gray-100 text-gray-600 transition inline-block;
|
||||
|
@ -363,6 +363,9 @@
|
||||
.video_preview_holder {
|
||||
@apply w-full h-full flex justify-center items-center bg-gray-200;
|
||||
}
|
||||
.video_file_holder {
|
||||
@apply dark:text-gray-50 w-full h-full flex justify-center items-center text-6xl p-6 break-all;
|
||||
}
|
||||
.video_preview {
|
||||
@apply w-full h-full object-contain;
|
||||
}
|
||||
@ -376,7 +379,7 @@
|
||||
@apply w-full h-full flex flex-col justify-center items-center relative inline-block;
|
||||
}
|
||||
.file_name {
|
||||
@apply text-6xl p-6 dark:text-gray-50;
|
||||
@apply text-6xl p-6 dark:text-gray-50 break-all;
|
||||
}
|
||||
.file_size {
|
||||
@apply text-2xl p-2 dark:text-gray-50;
|
||||
@ -466,14 +469,17 @@
|
||||
video {
|
||||
@apply h-full;
|
||||
}
|
||||
.video_file_holder {
|
||||
@apply dark:text-gray-50 w-full h-full flex justify-center items-center text-6xl p-6 break-all;
|
||||
}
|
||||
}
|
||||
.output_file {
|
||||
@apply w-full h-80 dark:text-gray-50;
|
||||
.file_display {
|
||||
@apply w-full h-full flex flex-col justify-center items-center relative inline-block;
|
||||
@apply w-full h-full flex flex-col justify-center items-center relative;
|
||||
}
|
||||
.file_name {
|
||||
@apply text-6xl p-6;
|
||||
@apply text-6xl p-6 break-all;
|
||||
}
|
||||
.file_size {
|
||||
@apply text-2xl p-2;
|
||||
|
@ -376,6 +376,9 @@
|
||||
.video_preview_holder {
|
||||
@apply w-full h-full flex justify-center items-center bg-gray-200;
|
||||
}
|
||||
.video_file_holder {
|
||||
@apply dark:text-gray-50 text-red-400 w-full h-full flex justify-center items-center text-6xl p-6 break-all;
|
||||
}
|
||||
.video_preview {
|
||||
@apply w-full h-full object-contain;
|
||||
}
|
||||
@ -389,7 +392,7 @@
|
||||
@apply w-full h-full flex flex-col justify-center items-center relative inline-block;
|
||||
}
|
||||
.file_name {
|
||||
@apply text-6xl p-6;
|
||||
@apply text-6xl p-6 break-all;
|
||||
}
|
||||
.file_size {
|
||||
@apply text-2xl p-2;
|
||||
@ -476,14 +479,17 @@
|
||||
video {
|
||||
@apply h-full;
|
||||
}
|
||||
.video_file_holder {
|
||||
@apply dark:text-gray-50 text-red-400 w-full h-full flex justify-center items-center text-6xl p-6 break-all;
|
||||
}
|
||||
}
|
||||
.output_file {
|
||||
@apply w-full h-80 dark:text-gray-50;
|
||||
.file_display {
|
||||
@apply w-full h-full flex flex-col justify-center items-center relative inline-block;
|
||||
@apply w-full h-full flex flex-col justify-center items-center relative;
|
||||
}
|
||||
.file_name {
|
||||
@apply text-6xl p-6;
|
||||
@apply text-6xl p-6 break-all;
|
||||
}
|
||||
.file_size {
|
||||
@apply text-2xl p-2;
|
||||
|
@ -161,3 +161,13 @@ export function CSVToArray(strData, strDelimiter) {
|
||||
}
|
||||
return arrData;
|
||||
}
|
||||
|
||||
export function isPlayable(data_type, mime_type) {
|
||||
if (data_type == "audio") {
|
||||
let audio_element = new Audio();
|
||||
return audio_element.canPlayType(mime_type) != "";
|
||||
} else {
|
||||
let video_element = document.createElement("video");
|
||||
return video_element.canPlayType(mime_type) != "";
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
Metadata-Version: 1.0
|
||||
Name: gradio
|
||||
Version: 2.3.6
|
||||
Version: 2.3.7b0
|
||||
Summary: Python library for easily interacting with trained machine learning models
|
||||
Home-page: https://github.com/gradio-app/gradio-UI
|
||||
Author: Abubakar Abid
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"files": {
|
||||
"main.css": "/static/css/main.b12b2171.css",
|
||||
"main.css": "/static/css/main.61fa3417.css",
|
||||
"main.js": "/static/bundle.js",
|
||||
"index.html": "/index.html",
|
||||
"static/bundle.js.LICENSE.txt": "/static/bundle.js.LICENSE.txt",
|
||||
@ -11,7 +11,7 @@
|
||||
},
|
||||
"entrypoints": [
|
||||
"static/bundle.css",
|
||||
"static/css/main.b12b2171.css",
|
||||
"static/css/main.61fa3417.css",
|
||||
"static/bundle.js"
|
||||
]
|
||||
}
|
@ -8,4 +8,4 @@
|
||||
window.config = {{ config|tojson }};
|
||||
} catch (e) {
|
||||
window.config = {};
|
||||
}</script><script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js"></script><title>Gradio</title><link href="static/bundle.css" rel="stylesheet"><link href="static/css/main.b12b2171.css" rel="stylesheet"></head><body style="height:100%"><div id="root" style="height:100%"></div><script src="static/bundle.js"></script></body></html>
|
||||
}</script><script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js"></script><title>Gradio</title><link href="static/bundle.css" rel="stylesheet"><link href="static/css/main.61fa3417.css" rel="stylesheet"></head><body style="height:100%"><div id="root" style="height:100%"></div><script src="static/bundle.js"></script></body></html>
|
323
gradio/inputs.py
323
gradio/inputs.py
File diff suppressed because one or more lines are too long
@ -4,11 +4,11 @@ This module defines various classes that can serve as the `output` to an interfa
|
||||
automatically added to a registry, which allows them to be easily referenced in other parts of the code.
|
||||
"""
|
||||
|
||||
from posixpath import basename
|
||||
from gradio.component import Component
|
||||
import numpy as np
|
||||
import json
|
||||
from gradio import processing_utils
|
||||
import datetime
|
||||
import operator
|
||||
from numbers import Number
|
||||
import warnings
|
||||
@ -18,6 +18,7 @@ import os
|
||||
import pandas as pd
|
||||
import PIL
|
||||
from types import ModuleType
|
||||
from ffmpy import FFmpeg
|
||||
|
||||
class OutputComponent(Component):
|
||||
"""
|
||||
@ -31,7 +32,6 @@ class OutputComponent(Component):
|
||||
return y
|
||||
|
||||
|
||||
|
||||
class Textbox(OutputComponent):
|
||||
'''
|
||||
Component creates a textbox to render output text or number.
|
||||
@ -67,7 +67,8 @@ class Textbox(OutputComponent):
|
||||
elif self.type == "number":
|
||||
return y
|
||||
else:
|
||||
raise ValueError("Unknown type: " + self.type + ". Please choose from: 'str', 'number'")
|
||||
raise ValueError("Unknown type: " + self.type +
|
||||
". Please choose from: 'str', 'number'")
|
||||
|
||||
|
||||
class Label(OutputComponent):
|
||||
@ -128,7 +129,7 @@ class Label(OutputComponent):
|
||||
return json.dumps({example["label"]: example["confidence"] for example in data["confidences"]})
|
||||
else:
|
||||
return data["label"]
|
||||
|
||||
|
||||
def restore_flagged(self, data):
|
||||
try:
|
||||
data = json.loads(data)
|
||||
@ -136,6 +137,7 @@ class Label(OutputComponent):
|
||||
except:
|
||||
return data
|
||||
|
||||
|
||||
class Image(OutputComponent):
|
||||
'''
|
||||
Component displays an output image.
|
||||
@ -153,7 +155,8 @@ class Image(OutputComponent):
|
||||
'''
|
||||
self.labeled_segments = labeled_segments
|
||||
if plot:
|
||||
warnings.warn("The 'plot' parameter has been deprecated. Set parameter 'type' to 'plot' instead.", DeprecationWarning)
|
||||
warnings.warn(
|
||||
"The 'plot' parameter has been deprecated. Set parameter 'type' to 'plot' instead.", DeprecationWarning)
|
||||
self.type = "plot"
|
||||
else:
|
||||
self.type = type
|
||||
@ -183,7 +186,8 @@ class Image(OutputComponent):
|
||||
elif isinstance(y, ModuleType):
|
||||
dtype = "plot"
|
||||
else:
|
||||
raise ValueError("Unknown type. Please choose from: 'numpy', 'pil', 'file', 'plot'.")
|
||||
raise ValueError(
|
||||
"Unknown type. Please choose from: 'numpy', 'pil', 'file', 'plot'.")
|
||||
else:
|
||||
dtype = self.type
|
||||
if dtype in ["numpy", "pil"]:
|
||||
@ -195,7 +199,8 @@ class Image(OutputComponent):
|
||||
elif dtype == "plot":
|
||||
out_y = processing_utils.encode_plot_to_base64(y)
|
||||
else:
|
||||
raise ValueError("Unknown type: " + dtype + ". Please choose from: 'numpy', 'pil', 'file', 'plot'.")
|
||||
raise ValueError("Unknown type: " + dtype +
|
||||
". Please choose from: 'numpy', 'pil', 'file', 'plot'.")
|
||||
return out_y, coordinates
|
||||
|
||||
def save_flagged(self, dir, label, data, encryption_key):
|
||||
@ -212,21 +217,37 @@ class Video(OutputComponent):
|
||||
Demos: video_flip.py
|
||||
'''
|
||||
|
||||
def __init__(self, label=None):
|
||||
def __init__(self, type=None, label=None):
|
||||
'''
|
||||
Parameters:
|
||||
type (str): Type of video format to be passed to component, such as 'avi' or 'mp4'. Use 'mp4' to ensure browser playability. If set to None, video will keep returned format.
|
||||
label (str): component name in interface.
|
||||
'''
|
||||
self.type = type
|
||||
super().__init__(label)
|
||||
|
||||
@classmethod
|
||||
def get_shortcut_implementations(cls):
|
||||
return {
|
||||
"video": {},
|
||||
"playable_video": {"type": "mp4"}
|
||||
}
|
||||
|
||||
def postprocess(self, y):
|
||||
return processing_utils.encode_file_to_base64(y, type="video")
|
||||
returned_format = y.split(".")[-1].lower()
|
||||
if self.type is not None and returned_format != self.type:
|
||||
output_file_name = y[0: y.rindex(
|
||||
".") + 1] + self.type
|
||||
ff = FFmpeg(
|
||||
inputs={y: None},
|
||||
outputs={output_file_name: None}
|
||||
)
|
||||
ff.run()
|
||||
y = output_file_name
|
||||
return {
|
||||
"name": os.path.basename(y),
|
||||
"data": processing_utils.encode_file_to_base64(y, type="video")
|
||||
}
|
||||
|
||||
def save_flagged(self, dir, label, data, encryption_key):
|
||||
"""
|
||||
@ -263,7 +284,7 @@ class KeyValues(OutputComponent):
|
||||
return {
|
||||
"key_values": {},
|
||||
}
|
||||
|
||||
|
||||
def save_flagged(self, dir, label, data, encryption_key):
|
||||
return json.dumps(data)
|
||||
|
||||
@ -341,11 +362,12 @@ class Audio(OutputComponent):
|
||||
if self.type in ["numpy", "file", "auto"]:
|
||||
if self.type == "numpy" or (self.type == "auto" and isinstance(y, tuple)):
|
||||
file = tempfile.NamedTemporaryFile(delete=False)
|
||||
scipy.io.wavfile.write(file, y[0], y[1])
|
||||
scipy.io.wavfile.write(file, y[0], y[1])
|
||||
y = file.name
|
||||
return processing_utils.encode_file_to_base64(y, type="audio", ext="wav")
|
||||
else:
|
||||
raise ValueError("Unknown type: " + self.type + ". Please choose from: 'numpy', 'file'.")
|
||||
raise ValueError("Unknown type: " + self.type +
|
||||
". Please choose from: 'numpy', 'file'.")
|
||||
|
||||
def save_flagged(self, dir, label, data, encryption_key):
|
||||
"""
|
||||
@ -374,7 +396,6 @@ class JSON(OutputComponent):
|
||||
else:
|
||||
return y
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_shortcut_implementations(cls):
|
||||
return {
|
||||
@ -402,7 +423,6 @@ class HTML(OutputComponent):
|
||||
'''
|
||||
super().__init__(label)
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_shortcut_implementations(cls):
|
||||
return {
|
||||
@ -424,7 +444,6 @@ class File(OutputComponent):
|
||||
'''
|
||||
super().__init__(label)
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_shortcut_implementations(cls):
|
||||
return {
|
||||
@ -434,7 +453,7 @@ class File(OutputComponent):
|
||||
def postprocess(self, y):
|
||||
return {
|
||||
"name": os.path.basename(y),
|
||||
"size": os.path.getsize(y),
|
||||
"size": os.path.getsize(y),
|
||||
"data": processing_utils.encode_file_to_base64(y, header=False)
|
||||
}
|
||||
|
||||
@ -469,7 +488,6 @@ class Dataframe(OutputComponent):
|
||||
self.type = type
|
||||
super().__init__(label)
|
||||
|
||||
|
||||
def get_template_context(self):
|
||||
return {
|
||||
"headers": self.headers,
|
||||
@ -505,9 +523,10 @@ class Dataframe(OutputComponent):
|
||||
y = y.tolist()
|
||||
if len(y) == 0 or not isinstance(y[0], list):
|
||||
y = [y]
|
||||
return {"data": y}
|
||||
return {"data": y}
|
||||
else:
|
||||
raise ValueError("Unknown type: " + self.type + ". Please choose from: 'pandas', 'numpy', 'array'.")
|
||||
raise ValueError("Unknown type: " + self.type +
|
||||
". Please choose from: 'pandas', 'numpy', 'array'.")
|
||||
|
||||
def save_flagged(self, dir, label, data, encryption_key):
|
||||
"""
|
||||
@ -534,10 +553,10 @@ class Carousel(OutputComponent):
|
||||
'''
|
||||
if not isinstance(components, list):
|
||||
components = [components]
|
||||
self.components = [get_output_instance(component) for component in components]
|
||||
self.components = [get_output_instance(
|
||||
component) for component in components]
|
||||
super().__init__(label)
|
||||
|
||||
|
||||
def get_template_context(self):
|
||||
return {
|
||||
"components": [component.get_template_context() for component in self.components],
|
||||
@ -556,17 +575,18 @@ class Carousel(OutputComponent):
|
||||
output.append(output_row)
|
||||
return output
|
||||
else:
|
||||
raise ValueError("Unknown type. Please provide a list for the Carousel.")
|
||||
raise ValueError(
|
||||
"Unknown type. Please provide a list for the Carousel.")
|
||||
|
||||
def save_flagged(self, dir, label, data, encryption_key):
|
||||
return json.dumps([
|
||||
[
|
||||
component.save_flagged(dir, f"{label}_{j}", data[i][j], encryption_key)
|
||||
component.save_flagged(
|
||||
dir, f"{label}_{j}", data[i][j], encryption_key)
|
||||
for j, component in enumerate(self.components)
|
||||
] for i, sample in enumerate(data)])
|
||||
|
||||
|
||||
|
||||
def get_output_instance(iface):
|
||||
if isinstance(iface, str):
|
||||
shortcut = OutputComponent.get_all_shortcut_implementations()[iface]
|
||||
@ -579,6 +599,7 @@ def get_output_instance(iface):
|
||||
"`OutputComponent`"
|
||||
)
|
||||
|
||||
|
||||
class Timeseries(OutputComponent):
|
||||
"""
|
||||
Component accepts pandas.DataFrame.
|
||||
@ -619,7 +640,6 @@ class Timeseries(OutputComponent):
|
||||
|
||||
}
|
||||
|
||||
|
||||
def save_flagged(self, dir, label, data, encryption_key):
|
||||
"""
|
||||
Returns: (List[List[Union[str, float]]]) 2D array
|
||||
@ -628,4 +648,3 @@ class Timeseries(OutputComponent):
|
||||
|
||||
def restore_flagged(self, data):
|
||||
return json.loads(data)
|
||||
|
||||
|
@ -79,15 +79,20 @@ def decode_base64_to_binary(encoding):
|
||||
data = encoding
|
||||
return base64.b64decode(data), extension
|
||||
|
||||
def decode_base64_to_file(encoding, encryption_key=None, filename_prefix=""):
|
||||
data, extension = decode_base64_to_binary(encoding)
|
||||
def decode_base64_to_file(encoding, encryption_key=None, filename=None):
|
||||
data, mime_extension = decode_base64_to_binary(encoding)
|
||||
prefix, extension = None, None
|
||||
if filename is not None and "." in filename:
|
||||
prefix = filename[0: filename.index(".")]
|
||||
extension = filename[filename.index(".") + 1:]
|
||||
if extension is None:
|
||||
file_obj = tempfile.NamedTemporaryFile(delete=False, prefix=filename_prefix)
|
||||
extension = mime_extension
|
||||
if extension is None:
|
||||
file_obj = tempfile.NamedTemporaryFile(delete=False, prefix=prefix)
|
||||
else:
|
||||
file_obj = tempfile.NamedTemporaryFile(delete=False, prefix=filename_prefix, suffix="."+extension)
|
||||
file_obj = tempfile.NamedTemporaryFile(delete=False, prefix=prefix, suffix="."+extension)
|
||||
if encryption_key is not None:
|
||||
data = encryptor.encrypt(encryption_key, data)
|
||||
#print("saving to ", file_obj.name)
|
||||
file_obj.write(data)
|
||||
file_obj.flush()
|
||||
return file_obj
|
||||
|
@ -1 +1 @@
|
||||
2.3.6
|
||||
2.3.7b
|
||||
|
Loading…
x
Reference in New Issue
Block a user