webplip / home.py
vinid's picture
new features added (#7)
7ee7b26
raw
history blame
4.77 kB
from pathlib import Path
import streamlit as st
import streamlit.components.v1 as components
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
from PIL import Image
def read_markdown_file(markdown_file):
return Path(markdown_file).read_text()
def app():
#intro_markdown = read_markdown_file("introduction.md")
#st.markdown(intro_markdown, unsafe_allow_html=True)
st.markdown("# Leveraging medical Twitter to build a visual-language foundation model for pathology")
col1, col2 = st.columns([2, 1])
with col1:
st.markdown("The lack of annotated publicly available medical images is a major barrier for innovations. At the same time, many de-identified images and much knowledge are shared by clinicians on public forums such as medical Twitter. Here we harness these crowd platforms to curate OpenPath, a large dataset of <b>208,414</b> pathology images paired with natural language descriptions. This is the largest public dataset for pathology images annotated with natural text. We demonstrate the value of this resource by developing PLIP, a multimodal AI with both image and text understanding, which is trained on OpenPath. PLIP achieves state-of-the-art zero-shot and few-short performance for classifying new pathology images across diverse tasks. Moreover, PLIP enables users to retrieve similar cases by either image or natural language search, greatly facilitating knowledge sharing. Our approach demonstrates that publicly shared medical data is a tremendous opportunity that can be harnessed to advance biomedical AI.", unsafe_allow_html=True)
fig1ab = Image.open('resources/4x/Fig1ab.png')
st.image(fig1ab, caption='OpenPath Dataset', output_format='png')
with col2:
st.caption('An example of tweet')
components.html('''
<blockquote class="twitter-tweet">
<a href="https://twitter.com/xxx/status/1580753362059788288"></a>
</blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8">
</script>
''',
height=500)
st.markdown("#### PLIP is trained on the largest public vision–language pathology dataset: OpenPath")
col1, col2 = st.columns([1, 1])
with col1:
st.markdown("Following the usage policy and guidelines from Twitter and other entities, we established so far the largest public vision–language pathology dataset. To ensure the quality of the data, OpenPath followed rigorous protocols for cohort inclusion and exclusion, including the removal of retweets, sensitive tweets, and non-pathology images, as well as text cleaning.", unsafe_allow_html=True)
st.markdown("The final OpenPath dataset consists of:", unsafe_allow_html=True)
st.markdown("- Tweets: 116,504 image–text pairs from Twitter posts (tweets) during Mar. 21, 2006 – Nov. 15, 2022 across 32 pathology subspecialty-specific hashtags;", unsafe_allow_html=True)
st.markdown("- Replies: 59,869 image–text pairs from the associated replies that received the highest number of likes in the tweet, if applicable;", unsafe_allow_html=True)
st.markdown("- PathLAION: 32,041 additional image–text pairs from the Internet which are outside from the Twitter community extracted from the LAION dataset.", unsafe_allow_html=True)
st.markdown("Leveraging the largest publicly available pathology dataset which contains image–text pairs across 32 different pathology subspecialty-specific hashtags, where each image has detailed text descriptions, we fine-tuned a pre-trained CLIP model and proposed a multimodal deep learning model for pathology, PLIP.", unsafe_allow_html=True)
with col2:
fig1c = Image.open('resources/4x/Fig1c.png')
st.image(fig1c, caption='Pathology hashtags in Twitter', output_format='png')
fig1d = Image.open('resources/4x/Fig1d.png')
st.image(fig1d, caption='Number of words in sentence', output_format='png')
st.markdown("#### PLIP is trained with connecting the image and text via contrastive learning")
col1, col2 = st.columns([3, 1])
with col1:
st.markdown("The proposed PLIP model generates two embedding vectors from both the text and image encoders. These vectors were then forced to be similar for each of the paired image and text vectors and dissimilar for non-paired image and text pairs via contrastive learning.", unsafe_allow_html=True)
fig1e = Image.open('resources/4x/Fig1e.png')
st.image(fig1e, caption='PLIP training', output_format='png')
with col2:
fig1f = Image.open('resources/4x/Fig1f.png')
st.image(fig1f, caption='Training illustration', output_format='png')