Spaces:
Build error
Build error
Download app.py from baharan/PCA-combo-maker: direct link, hf CLI and curl.
- Browser
- Download file 985 Bytes
-
https://huggingface.co/spaces/baharan/PCA-combo-maker/resolve/main/app.py
- Command line
-
hf download hf://spaces/baharan/PCA-combo-maker/app.py
-
curl -L -o app.py https://huggingface.co/spaces/baharan/PCA-combo-maker/resolve/main/app.py
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) | |