Upload 3 files
Browse files- Dockerfile +23 -0
- app.py +37 -0
- requirements.txt +4 -0
Dockerfile
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.8-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
# Install system dependencies
|
| 6 |
+
RUN apt-get update && apt-get install -y \
|
| 7 |
+
libglib2.0-0 \
|
| 8 |
+
libsm6 \
|
| 9 |
+
libxrender-dev \
|
| 10 |
+
libxext6 \
|
| 11 |
+
ffmpeg
|
| 12 |
+
|
| 13 |
+
# Install Python dependencies
|
| 14 |
+
COPY requirements.txt requirements.txt
|
| 15 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 16 |
+
|
| 17 |
+
# Copy application files
|
| 18 |
+
COPY . .
|
| 19 |
+
|
| 20 |
+
# Expose port
|
| 21 |
+
EXPOSE 7860
|
| 22 |
+
|
| 23 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from sklearn.neural_network import MLPClassifier
|
| 3 |
+
import torchvision.datasets as datasets
|
| 4 |
+
import seaborn as sns
|
| 5 |
+
|
| 6 |
+
# Dark mode seaborn
|
| 7 |
+
sns.set_style("darkgrid")
|
| 8 |
+
|
| 9 |
+
# Load MNIST data
|
| 10 |
+
mnist_trainset = datasets.MNIST(root='./data', train=True, download=True, transform=None)
|
| 11 |
+
mnist_testset = datasets.MNIST(root='./data', train=False, download=True, transform=None)
|
| 12 |
+
|
| 13 |
+
X_train = mnist_trainset.data.numpy()
|
| 14 |
+
X_test = mnist_testset.data.numpy()
|
| 15 |
+
y_train = mnist_trainset.targets.numpy()
|
| 16 |
+
y_test = mnist_testset.targets.numpy()
|
| 17 |
+
|
| 18 |
+
# Reshape and normalize data
|
| 19 |
+
X_train = X_train.reshape(60000, 784) / 255.0
|
| 20 |
+
X_test = X_test.reshape(10000, 784) / 255.0
|
| 21 |
+
|
| 22 |
+
# Train the model
|
| 23 |
+
mlp = MLPClassifier(hidden_layer_sizes=(32, 32))
|
| 24 |
+
mlp.fit(X_train, y_train)
|
| 25 |
+
|
| 26 |
+
# Print the accuracies
|
| 27 |
+
print("Training Accuracy: ", mlp.score(X_train, y_train))
|
| 28 |
+
print("Testing Accuracy: ", mlp.score(X_test, y_test))
|
| 29 |
+
|
| 30 |
+
# Define prediction function
|
| 31 |
+
def predict(img):
|
| 32 |
+
img = img.reshape(1, 784) / 255.0
|
| 33 |
+
prediction = mlp.predict(img)[0]
|
| 34 |
+
return int(prediction)
|
| 35 |
+
|
| 36 |
+
# Launch Gradio interface
|
| 37 |
+
gr.Interface(fn=predict, inputs="sketchpad", outputs="label").launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
scikit-learn
|
| 3 |
+
torchvision
|
| 4 |
+
seaborn
|