Spaces:
Runtime error
Runtime error
from pathlib import Path | |
import streamlit as st | |
import streamlit.components.v1 as components | |
from PIL import Image | |
import base64 | |
def read_markdown_file(markdown_file): | |
return Path(markdown_file).read_text() | |
def render_svg(svg_filename): | |
with open(svg_filename,"r") as f: | |
lines = f.readlines() | |
svg=''.join(lines) | |
"""Renders the given svg string.""" | |
b64 = base64.b64encode(svg.encode('utf-8')).decode("utf-8") | |
html = r'<img src="data:image/svg+xml;base64,%s"/>' % b64 | |
st.write(html, unsafe_allow_html=True) | |
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([4, 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) | |
render_svg("resources/SVG/Asset 49.svg") | |
with col2: | |
st.markdown('<b>Watch our success image-to-image retrieval via PLIP:</b>', unsafe_allow_html=True) | |
components.html(''' | |
<blockquote class="twitter-tweet"> | |
<a href="https://twitter.com/ZhiHuangPhD/status/1641899092195565569"></a> | |
</blockquote> | |
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"> | |
</script> | |
''', | |
height=900) | |
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: | |
render_svg("resources/SVG/Asset 50.svg") | |
render_svg("resources/SVG/Asset 51.svg") | |
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: | |
render_svg("resources/SVG/Asset 53.svg") | |