Ichlibitiche's picture
Add sample explorer app
21cef37 verified
Raw
History Blame Contribute Delete
4.24 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/suppdb-supplements-sample/suppdb_sample.csv"
df = pd.read_csv(DATA_URL)
DISPLAY_COLS = {
"brand": "Brand",
"product_name": "Product",
"form_type": "Form",
"ingredient": "Ingredient",
"ingredient_form": "Ingredient Form",
"ingredient_category": "Category",
"amount_per_serving_mg": "Dose (mg/serving)",
"is_proprietary_blend": "Hidden in Blend",
"recommended_daily_mg": "NIH RDA (mg)",
"upper_safety_limit_mg": "Upper Limit (mg)",
"molecular_formula": "Formula",
"source_url": "NIH DSLD Label",
}
BLEND_FILTERS = [
"All",
"Disclosed doses only",
"Proprietary-blend (hidden dose) only",
]
def choices(col):
vals = df[col].dropna().astype(str)
return ["All"] + sorted(v for v in vals.unique() if v.strip())
def explore(ingredient_query, brand, category, form, blend_filter):
d = df
if ingredient_query and ingredient_query.strip():
q = ingredient_query.strip()
hit = (
d["ingredient"].fillna("").str.contains(q, case=False, regex=False)
| d["product_name"].fillna("").str.contains(q, case=False, regex=False)
)
d = d[hit]
if brand != "All":
d = d[d["brand"] == brand]
if category != "All":
d = d[d["ingredient_category"] == category]
if form != "All":
d = d[d["form_type"] == form]
if blend_filter == "Disclosed doses only":
d = d[d["is_proprietary_blend"] == 0]
elif blend_filter == "Proprietary-blend (hidden dose) only":
d = d[d["is_proprietary_blend"] == 1]
summary = (
f"**{len(d)} ingredient records** across **{d['product_id'].nunique()} products** "
f"from **{d['brand'].nunique()} brands** match β€” out of {len(df)} records in the free sample. "
f"The full SuppDB has **115,000+ ingredient records across 17,000+ products**."
)
return summary, d[list(DISPLAY_COLS)].rename(columns=DISPLAY_COLS)
with gr.Blocks(title="SuppDB Sample Explorer") as demo:
gr.Markdown("# πŸ’Š SuppDB: Supplements & Nootropics Sample Explorer")
gr.Markdown(f"""Explore **{len(df)} active-ingredient records from {df['product_id'].nunique()} real supplement products ({df['brand'].nunique()} brands)** β€” NIH DSLD labels with **mg-normalized doses**, **proprietary-blend transparency**, and **PubChem chemistry**.
---
### 🌐 This is the free sample. The full SuppDB has 17,000+ products and 115,000+ ingredient records.
* **πŸ”— Official Portal (full dataset, $99 snapshot):** [suppdb.net](https://supplements-nootropics-suppdb.pages.dev)
* **πŸ€— Free Sample Dataset (Download CSV):** [Ichlibitiche/suppdb-supplements-sample](https://huggingface.co/datasets/Ichlibitiche/suppdb-supplements-sample)
* **πŸ† Kaggle Dataset:** [SuppDB Supplements Sample](https://www.kaggle.com/datasets/ahtiticheamine/suppdb-supplements-sample)
---""")
with gr.Row():
query_tb = gr.Textbox(label="Ingredient / Product Search", placeholder="e.g. Magnesium, Ashwagandha, Vitamin D...")
brand_dd = gr.Dropdown(choices=choices("brand"), value="All", label="Brand")
with gr.Row():
category_dd = gr.Dropdown(choices=choices("ingredient_category"), value="All", label="Ingredient Category")
form_dd = gr.Dropdown(choices=choices("form_type"), value="All", label="Product Form")
blend_dd = gr.Dropdown(choices=BLEND_FILTERS, value="All", label="Proprietary-Blend Transparency")
btn = gr.Button("Explore Supplements", variant="primary")
out_text = gr.Markdown()
out_table = gr.Dataframe(label="Matching Ingredient Records", wrap=True)
inputs = [query_tb, brand_dd, category_dd, form_dd, blend_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 Β© SuppDB under CC BY-NC 4.0 β€” factual label data, not medical advice. Full dataset commercially licensed at [suppdb.net](https://supplements-nootropics-suppdb.pages.dev) Β· contact suppdb.doorframe589@simplelogin.com*""")
demo.launch()