fix format

This commit is contained in:
Ali Abid 2022-03-24 23:03:47 -07:00
parent 48c42da3d4
commit d4759cfb3c
13 changed files with 62 additions and 48 deletions

View File

@ -1,5 +1,6 @@
import gradio as gr
def calculator(num1, operation, num2):
if operation == "add":
return num1 + num2

View File

@ -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")

View File

@ -7,4 +7,4 @@ with demo:
gr.Number(5)
if __name__ == "__main__":
demo.launch()
demo.launch()

View File

@ -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)
json.dump(config, open(args.file_path, "w"), indent=2)

View File

@ -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():

View File

@ -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):

View File

@ -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(),

View File

@ -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(

View File

@ -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

View File

@ -1,6 +1,6 @@
<script lang="ts">
export let style:string = "";
</script>
export let style: string = "";
</script>
<div {style} class="flex flex-1 flex-col gap-4">
<slot />

View File

@ -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
};

View File

@ -16,4 +16,4 @@
{#if value !== undefined}
<Label {theme} {style} {value} />
{/if}
{/if}

View File

@ -1,6 +1,6 @@
<script lang="ts">
export let style:string = "";
</script>
export let style: string = "";
</script>
<div {style} class="flex flex-row gap-4">
<slot />