PCA-combo-maker / app.py
baharan's picture
Rename app_stream.py to app.py
806e85a verified
Raw History Blame Contribute Delete
985 Bytes
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
from scipy.ndimage import gaussian_filter
from sklearn.decomposition import PCA
# Dummy PCA Data - Replace with actual PCA-transformed data
h, w, d = 100, 100, 4 # Example shape
pc_data = np.random.rand(h, w, d)
# Streamlit UI
st.title("Interactive PCA Visualization")
# Sliders for PC Weights
pc1_weight = st.slider("PC1 Weight", -1.0, 1.0, 0.0, 0.02)
pc2_weight = st.slider("PC2 Weight", -1.0, 1.0, 0.0, 0.02)
pc3_weight = st.slider("PC3 Weight", -1.0, 1.0, 0.0, 0.02)
pc4_weight = st.slider("PC4 Weight", -1.0, 1.0, 0.0, 0.02)
# Generate Image
composite_image = (
pc1_weight * pc_data[:, :, 0] +
pc2_weight * pc_data[:, :, 1] +
pc3_weight * pc_data[:, :, 2] +
pc4_weight * pc_data[:, :, 3]
)
composite_image = gaussian_filter(composite_image, sigma=1)
# Display Image
fig, ax = plt.subplots()
ax.imshow(composite_image, cmap="gray")
st.pyplot(fig)