Add sample explorer app
Browse files- README.md +13 -7
- app.py +91 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,13 +1,19 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version: '3.13'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: SuppDB Supplements Sample Explorer
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.9.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: cc-by-nc-4.0
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# π SuppDB β Supplements & Nootropics Sample Explorer
|
| 14 |
+
|
| 15 |
+
Interactively explore the free sample of [SuppDB](https://supplements-nootropics-suppdb.pages.dev): real supplement labels from the NIH DSLD, one row per active ingredient, with mg-normalized doses, proprietary-blend flags, and PubChem chemistry.
|
| 16 |
+
|
| 17 |
+
Data: [free sample dataset](https://huggingface.co/datasets/Ichlibitiche/suppdb-supplements-sample) (2,249 ingredient records, 300 products, 218 brands). The full dataset (17,000+ products, 115,000+ ingredient records) is available at [suppdb.net](https://supplements-nootropics-suppdb.pages.dev).
|
| 18 |
+
|
| 19 |
+
Sample data Β© SuppDB, CC BY-NC 4.0. Not medical advice.
|
app.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
# Load the free sample directly from the public Hugging Face dataset
|
| 5 |
+
DATA_URL = "hf://datasets/Ichlibitiche/suppdb-supplements-sample/suppdb_sample.csv"
|
| 6 |
+
df = pd.read_csv(DATA_URL)
|
| 7 |
+
|
| 8 |
+
DISPLAY_COLS = {
|
| 9 |
+
"brand": "Brand",
|
| 10 |
+
"product_name": "Product",
|
| 11 |
+
"form_type": "Form",
|
| 12 |
+
"ingredient": "Ingredient",
|
| 13 |
+
"ingredient_form": "Ingredient Form",
|
| 14 |
+
"ingredient_category": "Category",
|
| 15 |
+
"amount_per_serving_mg": "Dose (mg/serving)",
|
| 16 |
+
"is_proprietary_blend": "Hidden in Blend",
|
| 17 |
+
"recommended_daily_mg": "NIH RDA (mg)",
|
| 18 |
+
"upper_safety_limit_mg": "Upper Limit (mg)",
|
| 19 |
+
"molecular_formula": "Formula",
|
| 20 |
+
"source_url": "NIH DSLD Label",
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
BLEND_FILTERS = [
|
| 24 |
+
"All",
|
| 25 |
+
"Disclosed doses only",
|
| 26 |
+
"Proprietary-blend (hidden dose) only",
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
def choices(col):
|
| 30 |
+
vals = df[col].dropna().astype(str)
|
| 31 |
+
return ["All"] + sorted(v for v in vals.unique() if v.strip())
|
| 32 |
+
|
| 33 |
+
def explore(ingredient_query, brand, category, form, blend_filter):
|
| 34 |
+
d = df
|
| 35 |
+
if ingredient_query and ingredient_query.strip():
|
| 36 |
+
q = ingredient_query.strip()
|
| 37 |
+
hit = (
|
| 38 |
+
d["ingredient"].fillna("").str.contains(q, case=False, regex=False)
|
| 39 |
+
| d["product_name"].fillna("").str.contains(q, case=False, regex=False)
|
| 40 |
+
)
|
| 41 |
+
d = d[hit]
|
| 42 |
+
if brand != "All":
|
| 43 |
+
d = d[d["brand"] == brand]
|
| 44 |
+
if category != "All":
|
| 45 |
+
d = d[d["ingredient_category"] == category]
|
| 46 |
+
if form != "All":
|
| 47 |
+
d = d[d["form_type"] == form]
|
| 48 |
+
if blend_filter == "Disclosed doses only":
|
| 49 |
+
d = d[d["is_proprietary_blend"] == 0]
|
| 50 |
+
elif blend_filter == "Proprietary-blend (hidden dose) only":
|
| 51 |
+
d = d[d["is_proprietary_blend"] == 1]
|
| 52 |
+
|
| 53 |
+
summary = (
|
| 54 |
+
f"**{len(d)} ingredient records** across **{d['product_id'].nunique()} products** "
|
| 55 |
+
f"from **{d['brand'].nunique()} brands** match β out of {len(df)} records in the free sample. "
|
| 56 |
+
f"The full SuppDB has **115,000+ ingredient records across 17,000+ products**."
|
| 57 |
+
)
|
| 58 |
+
return summary, d[list(DISPLAY_COLS)].rename(columns=DISPLAY_COLS)
|
| 59 |
+
|
| 60 |
+
with gr.Blocks(title="SuppDB Sample Explorer") as demo:
|
| 61 |
+
gr.Markdown("# π SuppDB: Supplements & Nootropics Sample Explorer")
|
| 62 |
+
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**.
|
| 63 |
+
|
| 64 |
+
---
|
| 65 |
+
### π This is the free sample. The full SuppDB has 17,000+ products and 115,000+ ingredient records.
|
| 66 |
+
* **π Official Portal (full dataset, $99 snapshot):** [suppdb.net](https://supplements-nootropics-suppdb.pages.dev)
|
| 67 |
+
* **π€ Free Sample Dataset (Download CSV):** [Ichlibitiche/suppdb-supplements-sample](https://huggingface.co/datasets/Ichlibitiche/suppdb-supplements-sample)
|
| 68 |
+
* **π Kaggle Dataset:** [SuppDB Supplements Sample](https://www.kaggle.com/datasets/ahtiticheamine/suppdb-supplements-sample)
|
| 69 |
+
---""")
|
| 70 |
+
|
| 71 |
+
with gr.Row():
|
| 72 |
+
query_tb = gr.Textbox(label="Ingredient / Product Search", placeholder="e.g. Magnesium, Ashwagandha, Vitamin D...")
|
| 73 |
+
brand_dd = gr.Dropdown(choices=choices("brand"), value="All", label="Brand")
|
| 74 |
+
with gr.Row():
|
| 75 |
+
category_dd = gr.Dropdown(choices=choices("ingredient_category"), value="All", label="Ingredient Category")
|
| 76 |
+
form_dd = gr.Dropdown(choices=choices("form_type"), value="All", label="Product Form")
|
| 77 |
+
blend_dd = gr.Dropdown(choices=BLEND_FILTERS, value="All", label="Proprietary-Blend Transparency")
|
| 78 |
+
|
| 79 |
+
btn = gr.Button("Explore Supplements", variant="primary")
|
| 80 |
+
|
| 81 |
+
out_text = gr.Markdown()
|
| 82 |
+
out_table = gr.Dataframe(label="Matching Ingredient Records", wrap=True)
|
| 83 |
+
|
| 84 |
+
inputs = [query_tb, brand_dd, category_dd, form_dd, blend_dd]
|
| 85 |
+
btn.click(fn=explore, inputs=inputs, outputs=[out_text, out_table])
|
| 86 |
+
demo.load(fn=explore, inputs=inputs, outputs=[out_text, out_table])
|
| 87 |
+
|
| 88 |
+
gr.Markdown("""---
|
| 89 |
+
*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*""")
|
| 90 |
+
|
| 91 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas
|
| 2 |
+
huggingface_hub
|