From d4759cfb3c5ca844ac0c435ca856bf777a3d38a3 Mon Sep 17 00:00:00 2001 From: Ali Abid Date: Thu, 24 Mar 2022 23:03:47 -0700 Subject: [PATCH] fix format --- demo/calculator/run.py | 1 + demo/kinematics_blocks/run.py | 21 +++++++------ demo/static_textbox_blocks/run.py | 2 +- demo/write_config.py | 2 +- demo/xray_blocks/run.py | 15 +++++---- gradio/blocks.py | 7 ++--- gradio/components.py | 4 ++- gradio/flagging.py | 31 ++++++++++++------- gradio/interface.py | 1 - .../app/src/components/Column/Column.svelte | 4 +-- .../app/src/components/Dataset/directory.ts | 16 +++++----- .../app/src/components/Label/Label.svelte | 2 +- ui/packages/app/src/components/Row/Row.svelte | 4 +-- 13 files changed, 62 insertions(+), 48 deletions(-) diff --git a/demo/calculator/run.py b/demo/calculator/run.py index 50e97570fe..85330dffcf 100644 --- a/demo/calculator/run.py +++ b/demo/calculator/run.py @@ -1,5 +1,6 @@ import gradio as gr + def calculator(num1, operation, num2): if operation == "add": return num1 + num2 diff --git a/demo/kinematics_blocks/run.py b/demo/kinematics_blocks/run.py index 8ca713d78e..2dbe11bf3a 100644 --- a/demo/kinematics_blocks/run.py +++ b/demo/kinematics_blocks/run.py @@ -5,26 +5,29 @@ import numpy as np def plot(v, a): g = 9.81 - theta = a/180*3.14 + theta = a / 180 * 3.14 tmax = ((2 * v) * np.sin(theta)) / g - timemat = tmax*np.linspace(0,1,40)[:,None] + timemat = tmax * np.linspace(0, 1, 40)[:, None] + + x = (v * timemat) * np.cos(theta) + y = ((v * timemat) * np.sin(theta)) - ((0.5 * g) * (timemat**2)) - x = ((v * timemat) * np.cos(theta)) - y = ((v * timemat) * np.sin(theta)) - ((0.5 * g) * (timemat ** 2)) - fig = plt.figure() - plt.scatter(x=x, y=y, marker='.') + plt.scatter(x=x, y=y, marker=".") plt.xlim(0, 100) plt.ylim(0, 60) return fig + demo = gr.Blocks() with demo: - gr.Markdown("Let's do some kinematics! Choose the speed and angle to see the trajectory.") - + gr.Markdown( + "Let's do some kinematics! Choose the speed and angle to see the trajectory." + ) + with gr.Row(): - speed = gr.Slider(25, min=1, max=30,label="Speed") + speed = gr.Slider(25, min=1, max=30, label="Speed") angle = gr.Slider(45, min=0, max=90, label="Angle") output = gr.Image(type="plot") btn = gr.Button("Run") diff --git a/demo/static_textbox_blocks/run.py b/demo/static_textbox_blocks/run.py index 7fb7c34436..cf05b243a0 100644 --- a/demo/static_textbox_blocks/run.py +++ b/demo/static_textbox_blocks/run.py @@ -7,4 +7,4 @@ with demo: gr.Number(5) if __name__ == "__main__": - demo.launch() \ No newline at end of file + demo.launch() diff --git a/demo/write_config.py b/demo/write_config.py index 4de5973ddc..498c8c7d51 100644 --- a/demo/write_config.py +++ b/demo/write_config.py @@ -28,4 +28,4 @@ run = importlib.import_module(f"{args.demo_name}.run") demo: gr.Blocks = run.iface config = demo.get_config_file() -json.dump(config, open(args.file_path, "w"), indent=2) \ No newline at end of file +json.dump(config, open(args.file_path, "w"), indent=2) diff --git a/demo/xray_blocks/run.py b/demo/xray_blocks/run.py index ca76715bbe..c6c3b68270 100644 --- a/demo/xray_blocks/run.py +++ b/demo/xray_blocks/run.py @@ -17,18 +17,21 @@ with xray_blocks: - ipsum 2 """ ) - disease = gr.components.CheckboxGroup(choices=["Covid", "Malaria", "Lung Cancer"], label="Disease to Scan For") + disease = gr.components.CheckboxGroup( + choices=["Covid", "Malaria", "Lung Cancer"], label="Disease to Scan For" + ) with gr.Tabs(): with gr.TabItem("X-ray"): with gr.Row(): xray_scan = gr.components.Image() xray_results = gr.components.JSON() - xray_run = gr.Button("Run", css={ - "background-color": "red", - "--hover-color": "orange" - }) - xray_run.click(xray_model, inputs=[disease, xray_scan], outputs=xray_results) + xray_run = gr.Button( + "Run", css={"background-color": "red", "--hover-color": "orange"} + ) + xray_run.click( + xray_model, inputs=[disease, xray_scan], outputs=xray_results + ) with gr.TabItem("CT Scan"): with gr.Row(): diff --git a/gradio/blocks.py b/gradio/blocks.py index 154b1e9b94..01eeda4867 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -14,7 +14,7 @@ if TYPE_CHECKING: # Only import for type checking (is False at runtime). class Block: def __init__(self): self.render() - + def render(self): """ Adds self into appropriate BlockContext @@ -77,10 +77,7 @@ class BlockContext(Block): Context.block = self.parent def get_template_context(self): - return { - "css": self.css - } - + return {"css": self.css} class Row(BlockContext): diff --git a/gradio/components.py b/gradio/components.py index 58a7a17ce0..ab212ee6ed 100644 --- a/gradio/components.py +++ b/gradio/components.py @@ -2783,7 +2783,9 @@ class Dataset(Component): def get_template_context(self): return { - "components": [component.__class__.__name__.lower() for component in self.components], + "components": [ + component.__class__.__name__.lower() for component in self.components + ], "headers": self.headers, "samples": self.samples, **super().get_template_context(), diff --git a/gradio/flagging.py b/gradio/flagging.py index cc3cc5928a..f5dabc2119 100644 --- a/gradio/flagging.py +++ b/gradio/flagging.py @@ -16,6 +16,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: from gradio.components import Component + class FlaggingCallback(ABC): """ An abstract class for defining the methods that any FlaggingCallback should have. @@ -102,7 +103,12 @@ class CSVLogger(FlaggingCallback): Logs the input and output data to a CSV file. Supports encryption. """ - def setup(self, components: List[Component], flagging_dir: str, encryption_key: Optional[str] = None): + def setup( + self, + components: List[Component], + flagging_dir: str, + encryption_key: Optional[str] = None, + ): self.components = components self.flagging_dir = flagging_dir self.encryption_key = encryption_key @@ -136,10 +142,11 @@ class CSVLogger(FlaggingCallback): csv_data.append(username if username is not None else "") csv_data.append(str(datetime.datetime.now())) if is_new: - headers = [ - component.label - for component in self.components - ] + ["flag", "username", "timestamp"] + headers = [component.label for component in self.components] + [ + "flag", + "username", + "timestamp", + ] def replace_flag_at_index(file_content): file_content = io.StringIO(file_content) @@ -171,9 +178,7 @@ class CSVLogger(FlaggingCallback): writer.writerow(csv_data) with open(log_fp, "wb") as csvfile: csvfile.write( - encryptor.encrypt( - self.encryption_key, output.getvalue().encode() - ) + encryptor.encrypt(self.encryption_key, output.getvalue().encode()) ) else: if flag_index is None: @@ -313,9 +318,13 @@ class HuggingFaceDatasetSaver(FlaggingCallback): # Generate the row corresponding to the flagged sample csv_data = [] for component, sample in zip(self.components, flag_data): - filepath = component.save_flagged( - self.dataset_dir, component.label, sample, None - ) if sample is not None else "" + filepath = ( + component.save_flagged( + self.dataset_dir, component.label, sample, None + ) + if sample is not None + else "" + ) csv_data.append(filepath) if isinstance(component, tuple(file_preview_types)): csv_data.append( diff --git a/gradio/interface.py b/gradio/interface.py index 3c8303836d..adfa406a27 100644 --- a/gradio/interface.py +++ b/gradio/interface.py @@ -619,7 +619,6 @@ class Interface(Blocks): else: return predictions - def process(self, raw_input: List[Any]) -> Tuple[List[Any], List[float]]: """ First preprocesses the input, then runs prediction using diff --git a/ui/packages/app/src/components/Column/Column.svelte b/ui/packages/app/src/components/Column/Column.svelte index 990bc9dc0f..9ee901204a 100644 --- a/ui/packages/app/src/components/Column/Column.svelte +++ b/ui/packages/app/src/components/Column/Column.svelte @@ -1,6 +1,6 @@ + export let style: string = ""; +
diff --git a/ui/packages/app/src/components/Dataset/directory.ts b/ui/packages/app/src/components/Dataset/directory.ts index aa656b829e..92f0f605cf 100644 --- a/ui/packages/app/src/components/Dataset/directory.ts +++ b/ui/packages/app/src/components/Dataset/directory.ts @@ -1,10 +1,10 @@ -import ExampleNumber from "./ExampleComponents/Number.svelte" -import ExampleDropdown from "./ExampleComponents/Dropdown.svelte" -import ExampleCheckbox from "./ExampleComponents/Checkbox.svelte" -import ExampleCheckboxGroup from "./ExampleComponents/CheckboxGroup.svelte" -import ExampleSlider from "./ExampleComponents/Slider.svelte" -import ExampleRadio from "./ExampleComponents/Radio.svelte" -import ExampleImage from "./ExampleComponents/Image.svelte" +import ExampleNumber from "./ExampleComponents/Number.svelte"; +import ExampleDropdown from "./ExampleComponents/Dropdown.svelte"; +import ExampleCheckbox from "./ExampleComponents/Checkbox.svelte"; +import ExampleCheckboxGroup from "./ExampleComponents/CheckboxGroup.svelte"; +import ExampleSlider from "./ExampleComponents/Slider.svelte"; +import ExampleRadio from "./ExampleComponents/Radio.svelte"; +import ExampleImage from "./ExampleComponents/Image.svelte"; export const component_map = { dropdown: ExampleDropdown, @@ -13,5 +13,5 @@ export const component_map = { number: ExampleNumber, slider: ExampleSlider, radio: ExampleRadio, - image: ExampleImage, + image: ExampleImage }; diff --git a/ui/packages/app/src/components/Label/Label.svelte b/ui/packages/app/src/components/Label/Label.svelte index ae77da4362..fd2ba908da 100644 --- a/ui/packages/app/src/components/Label/Label.svelte +++ b/ui/packages/app/src/components/Label/Label.svelte @@ -16,4 +16,4 @@ {#if value !== undefined}