initial commit
Browse files- README.md +3 -1
- app.py +87 -147
- requirements.txt +0 -6
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 🖼
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: red
|
|
@@ -7,6 +7,8 @@ sdk: gradio
|
|
| 7 |
sdk_version: 5.0.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Bar Plot
|
| 3 |
emoji: 🖼
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: red
|
|
|
|
| 7 |
sdk_version: 5.0.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
short_description: ' Event Parameters table '
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -1,154 +1,94 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import numpy as np
|
| 3 |
-
import random
|
| 4 |
|
| 5 |
-
# import spaces #[uncomment to use ZeroGPU]
|
| 6 |
-
from diffusers import DiffusionPipeline
|
| 7 |
-
import torch
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
height=height,
|
| 48 |
-
generator=generator,
|
| 49 |
-
).images[0]
|
| 50 |
-
|
| 51 |
-
return image, seed
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
examples = [
|
| 55 |
-
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
| 56 |
-
"An astronaut riding a green horse",
|
| 57 |
-
"A delicious ceviche cheesecake slice",
|
| 58 |
-
]
|
| 59 |
-
|
| 60 |
-
css = """
|
| 61 |
-
#col-container {
|
| 62 |
-
margin: 0 auto;
|
| 63 |
-
max-width: 640px;
|
| 64 |
-
}
|
| 65 |
-
"""
|
| 66 |
-
|
| 67 |
-
with gr.Blocks(css=css) as demo:
|
| 68 |
-
with gr.Column(elem_id="col-container"):
|
| 69 |
-
gr.Markdown(" # Text-to-Image Gradio Template")
|
| 70 |
-
|
| 71 |
-
with gr.Row():
|
| 72 |
-
prompt = gr.Text(
|
| 73 |
-
label="Prompt",
|
| 74 |
-
show_label=False,
|
| 75 |
-
max_lines=1,
|
| 76 |
-
placeholder="Enter your prompt",
|
| 77 |
-
container=False,
|
| 78 |
-
)
|
| 79 |
-
|
| 80 |
-
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 81 |
-
|
| 82 |
-
result = gr.Image(label="Result", show_label=False)
|
| 83 |
-
|
| 84 |
-
with gr.Accordion("Advanced Settings", open=False):
|
| 85 |
-
negative_prompt = gr.Text(
|
| 86 |
-
label="Negative prompt",
|
| 87 |
-
max_lines=1,
|
| 88 |
-
placeholder="Enter a negative prompt",
|
| 89 |
-
visible=False,
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
-
seed = gr.Slider(
|
| 93 |
-
label="Seed",
|
| 94 |
-
minimum=0,
|
| 95 |
-
maximum=MAX_SEED,
|
| 96 |
-
step=1,
|
| 97 |
-
value=0,
|
| 98 |
-
)
|
| 99 |
-
|
| 100 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 101 |
-
|
| 102 |
-
with gr.Row():
|
| 103 |
-
width = gr.Slider(
|
| 104 |
-
label="Width",
|
| 105 |
-
minimum=256,
|
| 106 |
-
maximum=MAX_IMAGE_SIZE,
|
| 107 |
-
step=32,
|
| 108 |
-
value=1024, # Replace with defaults that work for your model
|
| 109 |
-
)
|
| 110 |
-
|
| 111 |
-
height = gr.Slider(
|
| 112 |
-
label="Height",
|
| 113 |
-
minimum=256,
|
| 114 |
-
maximum=MAX_IMAGE_SIZE,
|
| 115 |
-
step=32,
|
| 116 |
-
value=1024, # Replace with defaults that work for your model
|
| 117 |
-
)
|
| 118 |
-
|
| 119 |
-
with gr.Row():
|
| 120 |
-
guidance_scale = gr.Slider(
|
| 121 |
-
label="Guidance scale",
|
| 122 |
-
minimum=0.0,
|
| 123 |
-
maximum=10.0,
|
| 124 |
-
step=0.1,
|
| 125 |
-
value=0.0, # Replace with defaults that work for your model
|
| 126 |
-
)
|
| 127 |
-
|
| 128 |
-
num_inference_steps = gr.Slider(
|
| 129 |
-
label="Number of inference steps",
|
| 130 |
-
minimum=1,
|
| 131 |
-
maximum=50,
|
| 132 |
-
step=1,
|
| 133 |
-
value=2, # Replace with defaults that work for your model
|
| 134 |
-
)
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
height,
|
| 147 |
-
guidance_scale,
|
| 148 |
-
num_inference_steps,
|
| 149 |
-
],
|
| 150 |
-
outputs=[result, seed],
|
| 151 |
)
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
if __name__ == "__main__":
|
| 154 |
-
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from random import randint, random
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
temp_sensor_data = pd.DataFrame(
|
| 7 |
+
{
|
| 8 |
+
"time": pd.date_range("2021-01-01", end="2021-01-05", periods=200),
|
| 9 |
+
"temperature": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)],
|
| 10 |
+
"humidity": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)],
|
| 11 |
+
"location": ["indoor", "outdoor"] * 100,
|
| 12 |
+
}
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
food_rating_data = pd.DataFrame(
|
| 16 |
+
{
|
| 17 |
+
"cuisine": [["Italian", "Mexican", "Chinese"][i % 3] for i in range(100)],
|
| 18 |
+
"rating": [random() * 4 + 0.5 * (i % 3) for i in range(100)],
|
| 19 |
+
"price": [randint(10, 50) + 4 * (i % 3) for i in range(100)],
|
| 20 |
+
"wait": [random() for i in range(100)],
|
| 21 |
+
}
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
with gr.Blocks() as bar_plots:
|
| 25 |
+
with gr.Row():
|
| 26 |
+
start = gr.DateTime("2021-01-01 00:00:00", label="Start")
|
| 27 |
+
end = gr.DateTime("2021-01-05 00:00:00", label="End")
|
| 28 |
+
apply_btn = gr.Button("Apply", scale=0)
|
| 29 |
+
with gr.Row():
|
| 30 |
+
group_by = gr.Radio(["None", "30m", "1h", "4h", "1d"], value="None", label="Group by")
|
| 31 |
+
aggregate = gr.Radio(["sum", "mean", "median", "min", "max"], value="sum", label="Aggregation")
|
| 32 |
+
|
| 33 |
+
temp_by_time = gr.BarPlot(
|
| 34 |
+
temp_sensor_data,
|
| 35 |
+
x="time",
|
| 36 |
+
y="temperature",
|
| 37 |
+
)
|
| 38 |
+
temp_by_time_location = gr.BarPlot(
|
| 39 |
+
temp_sensor_data,
|
| 40 |
+
x="time",
|
| 41 |
+
y="temperature",
|
| 42 |
+
color="location",
|
| 43 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
time_graphs = [temp_by_time, temp_by_time_location]
|
| 46 |
+
group_by.change(
|
| 47 |
+
lambda group: [gr.BarPlot(x_bin=None if group == "None" else group)] * len(time_graphs),
|
| 48 |
+
group_by,
|
| 49 |
+
time_graphs
|
| 50 |
+
)
|
| 51 |
+
aggregate.change(
|
| 52 |
+
lambda aggregate: [gr.BarPlot(y_aggregate=aggregate)] * len(time_graphs),
|
| 53 |
+
aggregate,
|
| 54 |
+
time_graphs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
)
|
| 56 |
|
| 57 |
+
def rescale(select: gr.SelectData):
|
| 58 |
+
return select.index
|
| 59 |
+
rescale_evt = gr.on([plot.select for plot in time_graphs], rescale, None, [start, end])
|
| 60 |
+
|
| 61 |
+
for trigger in [apply_btn.click, rescale_evt.then]:
|
| 62 |
+
trigger(
|
| 63 |
+
lambda start, end: [gr.BarPlot(x_lim=[start, end])] * len(time_graphs), [start, end], time_graphs
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
with gr.Row():
|
| 67 |
+
price_by_cuisine = gr.BarPlot(
|
| 68 |
+
food_rating_data,
|
| 69 |
+
x="cuisine",
|
| 70 |
+
y="price",
|
| 71 |
+
)
|
| 72 |
+
with gr.Column(scale=0):
|
| 73 |
+
gr.Button("Sort $ > $$$").click(lambda: gr.BarPlot(sort="y"), None, price_by_cuisine)
|
| 74 |
+
gr.Button("Sort $$$ > $").click(lambda: gr.BarPlot(sort="-y"), None, price_by_cuisine)
|
| 75 |
+
gr.Button("Sort A > Z").click(lambda: gr.BarPlot(sort=["Chinese", "Italian", "Mexican"]), None, price_by_cuisine)
|
| 76 |
+
|
| 77 |
+
with gr.Row():
|
| 78 |
+
price_by_rating = gr.BarPlot(
|
| 79 |
+
food_rating_data,
|
| 80 |
+
x="rating",
|
| 81 |
+
y="price",
|
| 82 |
+
x_bin=1,
|
| 83 |
+
)
|
| 84 |
+
price_by_rating_color = gr.BarPlot(
|
| 85 |
+
food_rating_data,
|
| 86 |
+
x="rating",
|
| 87 |
+
y="price",
|
| 88 |
+
color="cuisine",
|
| 89 |
+
x_bin=1,
|
| 90 |
+
color_map={"Italian": "red", "Mexican": "green", "Chinese": "blue"},
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
if __name__ == "__main__":
|
| 94 |
+
bar_plots.launch()
|
requirements.txt
CHANGED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
accelerate
|
| 2 |
-
diffusers
|
| 3 |
-
invisible_watermark
|
| 4 |
-
torch
|
| 5 |
-
transformers
|
| 6 |
-
xformers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|