Skip to content

Commit

Permalink
streamlit app into multi pages
Browse files Browse the repository at this point in the history
  • Loading branch information
metazool committed Aug 6, 2024
1 parent 5e90e00 commit acae68c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
20 changes: 20 additions & 0 deletions cyto_ml/visualisation/pages/02_kmeans.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from sklearn.cluster import KMeans
import streamlit as st
from typing import Optional
from ..visualisation_app import image_embeddings


@st.cache_resource
def kmeans_cluster(n_clusters: Optional[int] = 10):
"""
K-means cluster the embeddings, option for default size
"""
X = image_embeddings()
# Initialize and fit KMeans
kmeans = KMeans(n_clusters=n_clusters, random_state=42)
kmeans.fit(X)
return kmeans


# TODO some visualisation, actual content, etc
16 changes: 0 additions & 16 deletions cyto_ml/visualisation/visualisation_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from PIL import Image
import plotly.express as px
import plotly.graph_objects as go
from sklearn.cluster import KMeans
import streamlit as st
from scivision import load_dataset
from dotenv import load_dotenv
Expand Down Expand Up @@ -75,21 +74,6 @@ def cached_image(url: str) -> Image:
return Image.open(BytesIO(response.content))


@st.cache_resource
def kmeans_cluster(n_clusters: Optional[int] = 10):
"""
K-means cluster the embeddings, option for default size
TODO a silhouette analysis
https://scikit-learn.org/stable/auto_examples/cluster/plot_kmeans_silhouette_analysis.html#sphx-glr-auto-examples-cluster-plot-kmeans-silhouette-analysis-py
"""
X = image_embeddings()
# Initialize and fit KMeans
kmeans = KMeans(n_clusters=n_clusters, random_state=42)
kmeans.fit(X)
return kmeans


def closest_grid(start_url: str, rows: list, size: Optional[int] = 26):
"""
Given an image URL, render a grid of the N nearest images
Expand Down

0 comments on commit acae68c

Please sign in to comment.