Spaces:
Sleeping
Sleeping
File size: 7,000 Bytes
06a79da 04fd4a6 06a79da 56b4129 |
1 2 3 4 5 6 7 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
import gradio as gr
from kids_main import optimize_schedule_for_pool, Duty
import pandas as pd
import PIL
import cv2
import gradio as gr
title = "CareBuds"
def load_image(path: str):
init_image = cv2.imread(path)
init_image = cv2.cvtColor(init_image, cv2.COLOR_BGR2RGB)
init_image = PIL.Image.fromarray(init_image).resize((512, 512))
return init_image
def find_pod(path: str):
init_image = load_image(path)
return [init_image, gr.Image(visible=bool(1)), gr.Textbox(visible=bool(1))]
def find_matches_based_on_schedule(
mon: bool, tue: bool, wed: bool, thu: bool, fri: bool
):
"""Basic compatibility means removing family without any availibility on the days you need them"""
from database import offer
cols = []
for col, v in zip(
["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
[mon, tue, wed, thu, fri],
):
if v is True:
cols.append(col)
is_compatible = offer[cols].any(axis=1)
return offer.loc[is_compatible, "family"]
def create_df(
name: str, mon: bool, tue: bool, wed: bool, thu: bool, fri: bool
) -> pd.DataFrame:
df = pd.DataFrame(
[
(
name,
1 if mon is True else 0,
1 if tue is True else 0,
1 if wed is True else 0,
1 if thu is True else 0,
1 if fri is True else 0,
)
],
columns=[
"Family",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
],
# dtype=[str, int, int, int, int, int],
)
return df
def gr_optimize_schedule_for_pool(
name: str, mon: bool, tue: bool, wed: bool, thu: bool, fri: bool
):
df = create_df(name, mon, tue, wed, thu, fri)
calendar = optimize_schedule_for_pool(df) # .set_index("Family")
styler = calendar.style.map(
lambda v: "color:lightgreen" if v == Duty.OnDuty else "color:red",
subset=pd.IndexSlice[:, calendar.columns[1:]],
)
return [styler, gr.Image(visible=bool(1))]
# Styline themes:
with gr.Blocks(
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="cyan"), title=title
) as demo:
with gr.Tab("Find care buds"):
with gr.Row():
gr.Markdown(
"""
# Welcome to CareBuds!
Let's find care buds for you! Please fill the form below to get started.
"""
)
with gr.Row():
gr_textbox_family = gr.Textbox(label="Family name")
gr_textbox_homeaddress = gr.Textbox(label="Home address")
gr_textbox_schoolname = gr.Textbox(label="School name")
gr_textbox_kid = gr.Textbox(label="Child name")
with gr.Row():
gr.Markdown(
"""
# Submit your schedule
Tick the days you CAN be on-duty:
"""
)
with gr.Row():
gr_textbox_user = gr.Textbox(value="Skywalker", visible=False)
gr_checkbox_mon = gr.Checkbox(label="Monday")
gr_checkbox_tue = gr.Checkbox(label="Tuesday")
gr_checkbox_wed = gr.Checkbox(label="Wednesday")
gr_checkbox_thu = gr.Checkbox(label="Thursday")
gr_checkbox_fri = gr.Checkbox(label="Friday")
gr_button_find_pod = gr.Button("Find care buds")
with gr.Row():
gr_image_stark = gr.Image(
value=None, type="pil", show_label=False, visible=False, scale=0.3
)
gr_image_potter = gr.Image(
value=None, type="pil", show_label=False, visible=False, scale=0.3
)
with gr.Row():
gr_button_contactfamily1 = gr.Button(
"Contact this family", visible=False, scale=0.3
)
gr_button_contactfamily2 = gr.Button(
"Contact this family", visible=False, scale=0.3
)
gr_button_find_pod.click(
find_pod,
inputs=[gr.Textbox(value="Stark.png", visible=False)],
outputs=[gr_image_stark, gr_image_stark, gr_button_contactfamily1],
)
gr_button_find_pod.click(
find_pod,
inputs=[gr.Textbox(value="Potter.png", visible=False)],
outputs=[gr_image_potter, gr_image_potter, gr_button_contactfamily2],
)
with gr.Tab("Get your schedule"):
with gr.Row():
gr.Markdown(
"""
Care buds
"""
)
with gr.Row():
image_skywalker = load_image("Skywalker.png")
image_stark = load_image("Stark.png")
image_potter = load_image("Potter.png")
gr_image_pod_sky = gr.Image(
value=image_skywalker, type="pil", label="Skywalker", container=True
)
gr_image_pod_stark = gr.Image(value=image_stark, type="pil", label="Stark")
gr_image_pod_potter = gr.Image(
value=image_potter, type="pil", label="Potter"
)
with gr.Row():
gr.Markdown(
"""
# Submit your schedule
Tick the days you CAN be on-duty:
"""
)
with gr.Row():
gr_textbox_user = gr.Textbox(value="Skywalker", visible=False)
gr_checkbox_mon = gr.Checkbox(label="Monday")
gr_checkbox_tue = gr.Checkbox(label="Tuesday")
gr_checkbox_wed = gr.Checkbox(label="Wednesday")
gr_checkbox_thu = gr.Checkbox(label="Thursday")
gr_checkbox_fri = gr.Checkbox(label="Friday")
gr_solve_event = gr.Button("Get schedule", scale=0.2)
gr_df_offer = gr.DataFrame(visible=False)
with gr.Row():
gr.Markdown(
"""
# Get the care buds schedule
"""
)
# Could skip the button and use .change or .input on gr_df
with gr.Row():
gr_sol = gr.DataFrame(
headers=[
"Family",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
],
datatype=["str", "number", "number", "number", "number", "number"],
col_count=(6, "fixed"),
row_count=(3, "fixed"),
visible=False,
)
gr_solve_event.click(
gr_optimize_schedule_for_pool,
inputs=[
gr_textbox_user,
gr_checkbox_mon,
gr_checkbox_tue,
gr_checkbox_wed,
gr_checkbox_thu,
gr_checkbox_fri,
],
outputs=[gr_sol, gr_sol],
)
demo.launch(auth=("foryc", "letsgo"))
|