Spaces:
Runtime error
Runtime error
Commit ·
7f27f74
1
Parent(s): 2e5c9ff
Update app.py
Browse files1234567891011121314151617181920212223242526272829import streamlit as stimport tensorflow as tf# Streamlit appdef main():st.title("GPU Utilization Example")# Check if GPU is availableif tf.config.experimental.list_physical_devices('GPU'):st.write("GPU is available.")# Create a simple model and train it (this will utilize the GPU)model = tf.keras.Sequential([tf.keras.layers.Dense(128, input_shape=(784,), activation='relu'),tf.keras.layers.Dense(10, activation='softmax')])model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])# Generate random data for training (MNIST dataset)(x_train, y_train), _ = tf.keras.datasets.mnist.load_data()x_train = x_train.reshape(-1, 784) / 255.0# Train the model for a few epochsmodel.fit(x_train, y_train, epochs=5)st.write("Training complete.")else:st.write("No GPU available.")if __name__ == "__main__":main()12345678910111213141516171819202122232425262728import streamlit as stimport numpy as npimport time# Streamlit appdef main():st.title("GPU Utilization Example")# Check if GPU is availabletry:import cupy as cpst.write("GPU is available.")st.write("Performing GPU-intensive operation...")# Generate large random matrices and perform matrix multiplication on the GPUsize = 1000 # Increase the size for higher GPU utilizationa = cp.random.rand(size, size)b = cp.random.rand(size, size)start_time = time.time()c = cp.dot(a, b)end_time = time.time()st.write("Operation completed in {:.2f} seconds.".format(end_time - start_time))except ImportError:st.write("No GPU available or CuPy library not installed.")if __name__ == "__main__":main()
app.py+17-18