healthsea-demo /
philipvollet's picture
history blame contribute delete
No virus
5.63 kB
import streamlit as st
from pathlib import Path
import json
from support_functions import HealthseaSearch
# Header
with open("style.css") as f:
st.markdown("<style>" + + "</style>", unsafe_allow_html=True)
# Intro
st.title("Welcome to Healthsea 🪐")
intro, jellyfish = st.columns(2)
intro.subheader("Create easier access to health✨")
"""Healthsea is an end-to-end spaCy v3 pipeline for analyzing user reviews to supplementary products and extracting their potential effects on health."""
"""The code for Healthsea is provided in this [github repository]( Visit our [blog post]( or more about the Healthsea project.
"""This app visualizes the results of Healthsea on a dataset of up to 1 million reviews to 10.000 products. You can use the app to search for any health aspect, whether it's a disease (e.g. joint pain) or a positive state of health (e.g. energy), the app returns a list of products and substances.
You can visit the [Healthsea Pipeline app]( for exploring the pipeline itself.
st.warning("""Healthsea is an experimental project and the results should not be used as a foundation for solving health problems. Nor do we want to give the impression that supplements are the answer to anyone's health issues.""")
# Configuration
health_aspect_path = Path("data/health_aspects.json")
product_path = Path("data/products.json")
condition_path = Path("data/condition_vectors.json")
benefit_path = Path("data/benefit_vectors.json")
# Load data
def load_data(
_health_aspect_path: Path,
_product_path: Path,
_condition_path: Path,
_benefit_path: Path,
with open(_health_aspect_path) as reader:
health_aspects = json.load(reader)
with open(_product_path) as reader:
products = json.load(reader)
with open(_condition_path) as reader:
conditions = json.load(reader)
with open(_benefit_path) as reader:
benefits = json.load(reader)
return health_aspects, products, conditions, benefits
# Functions
def kpi(n, text):
html = f"""
<div class='kpi'>
<h1 class='kpi_header'>{n}</h1>
return html
def central_text(text):
html = f"""<h2 class='central_text'>{text}</h2>"""
return html
# Loading data
health_aspects, products, conditions, benefits = load_data(
health_aspect_path, product_path, condition_path, benefit_path
search_engine = HealthseaSearch(health_aspects, products, conditions, benefits)
st.markdown(central_text("🎀 Dataset"), unsafe_allow_html=True)
kpi_products, kpi_reviews, kpi_condition, kpi_benefit = st.columns(4)
def round_to_k(value):
return str(round(value/1000,1))+"k"
kpi_products.markdown(kpi(round_to_k(len(products)), "Products"), unsafe_allow_html=True)
kpi_reviews.markdown(kpi(round_to_k(int(933240)), "Reviews"), unsafe_allow_html=True)
kpi_condition.markdown(kpi(round_to_k(len(conditions)), "Conditions"), unsafe_allow_html=True)
kpi_benefit.markdown(kpi(round_to_k(len(benefits)), "Benefits"), unsafe_allow_html=True)
# Expander
show_conditions, show_benefits = st.columns(2)
with show_conditions.expander("Top mentioned Conditions"):
with show_benefits.expander("Top mentioned Benefits"):
# Search
search = st.text_input(label="Search for an health aspect", value="joint pain")
n = st.slider("Show top n results", min_value=10, max_value=1000, value=25)
st.markdown(central_text("🧃 Products"), unsafe_allow_html=True)"""The product score is based on the results of Healthsea. Variables used for the score are: health effect prediction, product rating, helpful count and whether the review is considered a 'fake review'. """)
# DataFrame
st.write(search_engine.get_products_df(search, n))
# KPI & Alias
aspect_alias = search_engine.get_aspect(search)["alias"]
kpi_product_mentions, kpi_alias = st.columns(2)
kpi_product_mentions.markdown(kpi(len(search_engine.get_aspect(search)["products"]), "Products"), unsafe_allow_html=True)
kpi(len(aspect_alias), "Similar health aspects"),
depth = st.slider("Depth", min_value=0, max_value=5, value=2)
recursive_alias, recursive_edges = search_engine.get_recursive_alias(search,0,{},[],depth)
vectors = []
main_aspect = search_engine.get_aspect_meta(search)
vectors.append((main_aspect["name"], main_aspect["vector"]))
for aspect in aspect_alias:
current_aspect = search_engine.get_aspect_meta(aspect)
vectors.append((current_aspect["name"], current_aspect["vector"]))
st.markdown("\n")"""Health aspects with a high similarity (>=90%) are clustered together.""")
# Substances
st.markdown(central_text("🍯 Substances"), unsafe_allow_html=True)"""Substance scores are based on product scores""")
# DataFrame
st.write(search_engine.get_substances_df(search, n))
kpi_substances, empty = st.columns(2)
kpi(len(search_engine.get_aspect(search)["substance"]), "Substances"),