Ichlibitiche's picture
Add sample explorer app
a7766b7 verified
Raw
History Blame Contribute Delete
4.8 kB
import gradio as gr
import pandas as pd
# Load the free sample directly from the public Hugging Face dataset
DATA_URL = "hf://datasets/Ichlibitiche/floradb-houseplants-care-sample/floradb_sample.csv"
df = pd.read_csv(DATA_URL)
DISPLAY_COLS = {
"common_name": "Common Name",
"scientific_name": "Scientific Name",
"family": "Family",
"light_requirement_level": "Light",
"min_lux": "Min Lux",
"max_lux": "Max Lux",
"watering_frequency_days": "Water Every (days)",
"min_temp_celsius": "Min °C",
"max_temp_celsius": "Max °C",
"is_toxic_to_dogs": "Toxic: Dogs",
"is_toxic_to_cats": "Toxic: Cats",
"toxicity_status": "Toxicity Source",
"care_confidence": "Care Confidence",
"gbif_source_url": "GBIF Source",
}
PET_FILTERS = [
"All",
"Verified safe for dogs",
"Verified safe for cats",
"Toxic to dogs or cats",
"Toxicity unknown",
]
def choices(col):
vals = df[col].dropna().astype(str)
return ["All"] + sorted(v for v in vals.unique() if v.strip())
def explore(name_query, family, light, confidence, pet_filter):
d = df
if name_query and name_query.strip():
q = name_query.strip()
hit = (
d["common_name"].fillna("").str.contains(q, case=False, regex=False)
| d["scientific_name"].fillna("").str.contains(q, case=False, regex=False)
)
d = d[hit]
if family != "All":
d = d[d["family"] == family]
if light != "All":
d = d[d["light_requirement_level"] == light]
if confidence != "All":
d = d[d["care_confidence"] == confidence]
# Safety filters are conservative: "safe" requires a determined status, never unknown
if pet_filter == "Verified safe for dogs":
d = d[(d["is_toxic_to_dogs"] == 0) & (d["toxicity_status"] != "unknown")]
elif pet_filter == "Verified safe for cats":
d = d[(d["is_toxic_to_cats"] == 0) & (d["toxicity_status"] != "unknown")]
elif pet_filter == "Toxic to dogs or cats":
d = d[(d["is_toxic_to_dogs"] == 1) | (d["is_toxic_to_cats"] == 1)]
elif pet_filter == "Toxicity unknown":
d = d[d["toxicity_status"] == "unknown"]
summary = (
f"**{len(d)} plants** across **{d['family'].nunique()} families** match — "
f"out of {len(df)} in the free sample. "
f"The full FloraDB has **270 care plants + 891 ASPCA toxicity records + a 20,000+ species GBIF index**."
)
return summary, d[list(DISPLAY_COLS)].rename(columns=DISPLAY_COLS)
with gr.Blocks(title="FloraDB Sample Explorer") as demo:
gr.Markdown("# 🌿 FloraDB: Houseplant Care & Pet-Toxicity Sample Explorer")
gr.Markdown(f"""Explore **{len(df)} houseplants from {df['family'].nunique()} botanical families** — care advice as **quantitative metrics** (Lux, watering days, °C, humidity) with **ASPCA pet toxicity** on GBIF-verified names.
---
### 🌐 This is the free sample. The full FloraDB has 270 care plants, 891 toxicity records & a 20,000+ species index.
* **🔗 Official Portal (full dataset, $99 snapshot):** [floradb](https://houseplants-botanical-floradb.pages.dev)
* **🤗 Free Sample Dataset (Download CSV):** [Ichlibitiche/floradb-houseplants-care-sample](https://huggingface.co/datasets/Ichlibitiche/floradb-houseplants-care-sample)
* **🏆 Kaggle Dataset:** [FloraDB Houseplants Care Sample](https://www.kaggle.com/datasets/ahtiticheamine/floradb-houseplants-care-sample)
* **🔄 Live Self-Serve Lookups:** [Houseplant Care & Pet-Toxicity Lookup on Apify](https://apify.com/dataengineered/houseplant-care-toxicity-lookup)
---""")
with gr.Row():
name_tb = gr.Textbox(label="Plant Search", placeholder="e.g. Monstera, Pothos, Ficus...")
family_dd = gr.Dropdown(choices=choices("family"), value="All", label="Botanical Family")
light_dd = gr.Dropdown(choices=choices("light_requirement_level"), value="All", label="Light Requirement")
with gr.Row():
conf_dd = gr.Dropdown(choices=choices("care_confidence"), value="All", label="Care Confidence")
pet_dd = gr.Dropdown(choices=PET_FILTERS, value="All", label="Pet Safety (ASPCA-based, conservative)")
btn = gr.Button("Explore Plants", variant="primary")
out_text = gr.Markdown()
out_table = gr.Dataframe(label="Matching Plants", wrap=True)
inputs = [name_tb, family_dd, light_dd, conf_dd, pet_dd]
btn.click(fn=explore, inputs=inputs, outputs=[out_text, out_table])
demo.load(fn=explore, inputs=inputs, outputs=[out_text, out_table])
gr.Markdown("""---
*Sample data © FloraDB under CC BY-NC 4.0 — informational, not veterinary advice. Full dataset commercially licensed at [floradb](https://houseplants-botanical-floradb.pages.dev) · contact floradb.hardhat456@simplelogin.com*""")
demo.launch()