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 208,414 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('''
''', 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') st.markdown('Disclaimer') st.caption('Please be advised that this function has been developed in compliance with the Twitter policy of data usage and sharing. It is important to note that the results obtained from this function are not intended to constitute medical advice or replace consultation with a qualified medical professional. The use of this function is solely at your own risk and should be consistent with applicable laws, regulations, and ethical considerations. We do not warrant or guarantee the accuracy, completeness, suitability, or usefulness of this function for any particular purpose, and we hereby disclaim any liability arising from any reliance placed on this function or any results obtained from its use. If you wish to review the original Twitter post, you should access the source page directly on Twitter.') st.markdown('Privacy statement') st.caption('In accordance with the privacy and control policy of Twitter, we hereby declared that the data redistributed by us shall only comprise of Tweet IDs. The Tweet IDs will be employed to establish a linkage with the original Twitter post, as long as the original post is still accessible. The hyperlink will cease to function if the user deletes the original post. It is important to note that all tweets displayed on our service have already been classified as non-sensitive by Twitter. It is strictly prohibited to redistribute any content apart from the Tweet IDs. Any distribution carried out must adhere to the laws and regulations applicable in your jurisdiction, including export control laws and embargoes.')