Spaces:
Build error
Build error
Update app.py
Browse files14 unmodified lines15161718192021222387 unmodified lines1111121131141151161179 unmodified lines127128129130131132133134135136137138139140141142143144145146147148149150151152153154207 unmodified lines36236336436536636736814 unmodified linesfrom keras.regularizers import l2, l1from keras.callbacks import Callback# Debug versionsst.write(f"TensorFlow version: {tf.__version__}")st.write(f"Keras version: {tf.keras.__version__}")# Set wide layout and TensorFlow Playground CSSst.set_page_config(layout="wide")87 unmodified lineswith col4:activation = st.selectbox("Activation", ["ReLU", "Sigmoid", "Tanh"], index=2)with col5:batch_size = st.slider("Batch Size", 1, 30, 10)# Row 2col6, col7, col8, col9, col10 = st.columns(5)9 unmodified linesst.button("Reset", key="reset_global", on_click=reset_session)st.markdown('</div>', unsafe_allow_html=True)# Dataset generationdef generate_xor(n_samples):X = np.random.rand(n_samples, 2) * 2 - 1y = np.logical_xor(X[:, 0] > 0, X[:, 1] > 0).astype(int)return X, ydef generate_sine_wave(n_samples, noise):X = np.linspace(-3, 3, n_samples).reshape(-1, 1)y = np.sin(X) + np.random.normal(0, noise / 100, X.shape)return np.hstack([X, X**2]), y.ravel()if problem_type == "Classification":if dataset_type == "Blobs":fv, cv = make_blobs(n_samples=800, centers=2, n_features=2, cluster_std=1.5 + noise_level / 50, random_state=42)elif dataset_type == "Circles":fv, cv = make_circles(n_samples=800, noise=noise_level / 250, factor=0.2)elif dataset_type == "Spirals":fv, cv = make_moons(n_samples=800, noise=noise_level / 250)elif dataset_type == "XOR":fv, cv = generate_xor(800)else:fv, cv = generate_sine_wave(800, noise_level)# Feature preprocessingstd = StandardScaler()207 unmodified linesmodel = create_model(len(selected_features), st.session_state.hidden_layer_neurons)callback = OutputCallback(selected_data, cv)callback.model = model # Explicitly set the model for the callbackmodel.fit(selected_data, cv, epochs=100, # Reduced for Spacesbatch_size=batch_size, validation_split=1-train_ratio,callbacks=[callback], verbose=0)except Exception as e:14 unmodified lines1516171819202122232425262728293031323334353687 unmodified lines1241251261271281291309 unmodified lines140141142143144145146147148149150151152153154155156157158159160161162163164165166167207 unmodified lines37537637737837938038114 unmodified linesfrom keras.regularizers import l2, l1from keras.callbacks import Callback# Check TensorFlow and Keras versions with fallbacktry:tf_version = tf.__version__# Try multiple ways to get Keras version, accounting for TensorFlow integrationkeras_version = Noneif hasattr(tf.keras, '__version__'):keras_version = tf.keras.__version__elif hasattr(tf, 'keras') and hasattr(tf.keras, 'version'):keras_version = tf.keras.version.__version__else:keras_version = "Keras version not available (bundled with TensorFlow)"st.write(f"TensorFlow version: {tf_version}")st.write(f"Keras version: {keras_version}")except AttributeError as e:st.error(f"Error checking versions: {e}")st.write("Falling back to default versions: TensorFlow ~2.15, Keras ~2.15")# Set wide layout and TensorFlow Playground CSSst.set_page_config(layout="wide")87 unmodified lineswith col4:activation = st.selectbox("Activation", ["ReLU", "Sigmoid", "Tanh"], index=2)with col5:batch_size = st.slider("Batch Size", 1, 10, 5) # Reduced max batch size for Spaces# Row 2col6, col7, col8, col9, col10 = st.columns(5)9 unmodified linesst.button("Reset", key="reset_global", on_click=reset_session)st.markdown('</div>', unsafe_allow_html=True)# Dataset generation (reduced sample size for performance)def generate_xor(n_samples=400): # Reduced from 800 for performanceX = np.random.rand(n_samples, 2) * 2 - 1y = np.logical_xor(X[:, 0] > 0, X[:, 1] > 0).astype(int)return X, ydef generate_sine_wave(n_samples=400, noise): # Reduced from 800X = np.linspace(-3, 3, n_samples).reshape(-1, 1)y = np.sin(X) + np.random.normal(0, noise / 100, X.shape)return np.hstack([X, X**2]), y.ravel()if problem_type == "Classification":if dataset_type == "Blobs":fv, cv = make_blobs(n_samples=400, centers=2, n_features=2, cluster_std=1.5 + noise_level / 50, random_state=42)elif dataset_type == "Circles":fv, cv = make_circles(n_samples=400, noise=noise_level / 250, factor=0.2)elif dataset_type == "Spirals":fv, cv = make_moons(n_samples=400, noise=noise_level / 250)elif dataset_type == "XOR":fv, cv = generate_xor(400)else:fv, cv = generate_sine_wave(400, noise_level)# Feature preprocessingstd = StandardScaler()207 unmodified linesmodel = create_model(len(selected_features), st.session_state.hidden_layer_neurons)callback = OutputCallback(selected_data, cv)callback.model = model # Explicitly set the model for the callbackmodel.fit(selected_data, cv, epochs=50, # Further reduced for Spacesbatch_size=batch_size, validation_split=1-train_ratio,callbacks=[callback], verbose=0)except Exception as e:
app.py+26-13