Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import cv2
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
PCA_MODEL_PATH = "pca_texture_model.npy"
|
|
|
|
| 6 |
|
| 7 |
# Load PCA model
|
| 8 |
pca = np.load(PCA_MODEL_PATH, allow_pickle=True).item()
|
|
@@ -16,6 +17,15 @@ TEXTURE_SIZE = int(np.sqrt(mean_texture.shape[0] // 3))
|
|
| 16 |
# Calculate slider ranges
|
| 17 |
slider_ranges = [3 * np.sqrt(var) for var in explained_variance]
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def generate_texture(*component_values):
|
| 20 |
component_values = np.array(component_values)
|
| 21 |
new_texture = mean_texture + np.dot(component_values, components)
|
|
@@ -52,7 +62,7 @@ with gr.Blocks() as demo:
|
|
| 52 |
maximum=range_limit,
|
| 53 |
step=10,
|
| 54 |
value=0,
|
| 55 |
-
label=
|
| 56 |
)
|
| 57 |
sliders.append(slider)
|
| 58 |
random_button = gr.Button("Randomize Texture")
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
PCA_MODEL_PATH = "pca_texture_model.npy"
|
| 6 |
+
COMPONENT_NAMES_PATH = "component_names.txt"
|
| 7 |
|
| 8 |
# Load PCA model
|
| 9 |
pca = np.load(PCA_MODEL_PATH, allow_pickle=True).item()
|
|
|
|
| 17 |
# Calculate slider ranges
|
| 18 |
slider_ranges = [3 * np.sqrt(var) for var in explained_variance]
|
| 19 |
|
| 20 |
+
# Load component names if available
|
| 21 |
+
try:
|
| 22 |
+
with open(COMPONENT_NAMES_PATH, "r") as f:
|
| 23 |
+
component_names = [f"Component {i+1} ({line.strip()})" if line.strip() else f"Component {i+1}" for line in f.readlines()]
|
| 24 |
+
if len(component_names) < n_components:
|
| 25 |
+
component_names += [f"Component {i+1}" for i in range(len(component_names), n_components)]
|
| 26 |
+
except FileNotFoundError:
|
| 27 |
+
component_names = [f"Component {i+1}" for i in range(n_components)]
|
| 28 |
+
|
| 29 |
def generate_texture(*component_values):
|
| 30 |
component_values = np.array(component_values)
|
| 31 |
new_texture = mean_texture + np.dot(component_values, components)
|
|
|
|
| 62 |
maximum=range_limit,
|
| 63 |
step=10,
|
| 64 |
value=0,
|
| 65 |
+
label=component_names[i]
|
| 66 |
)
|
| 67 |
sliders.append(slider)
|
| 68 |
random_button = gr.Button("Randomize Texture")
|