Pranav4datasc commited on
Commit
80cd758
·
verified ·
1 Parent(s): b7d4482

Upload 5 files

Browse files
Files changed (4) hide show
  1. app.py +26 -0
  2. model.h5 +3 -0
  3. modelgen.py +27 -0
  4. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+
4
+ model = tf.keras.models.load_model('model.h5')
5
+
6
+ def recognize_digit(image):
7
+ if image is not None:
8
+ image = image.reshape((1, 28, 28, 1)).astype('float32')/255
9
+
10
+ prediction = model.predict(image)
11
+
12
+ return {str(i):float(prediction[0][i]) for i in range(10)}
13
+ else:
14
+ return ''
15
+
16
+ iface = gr.Interface(
17
+ fn = recognize_digit,
18
+ inputs=gr.Image(shape=(28, 28),image_mode='L',invert_colors=True,source='canvas'),
19
+ outputs=gr.Label(num_top_classes=3),
20
+ live=True
21
+ )
22
+ iface.launch()
23
+
24
+
25
+ # ref : https://www.youtube.com/watch?v=3DGLznJorT8
26
+
model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f16fa06c2945927a6f6579d2829f900518e9c944cdee40303a599d3999ccf8e
3
+ size 1172728
modelgen.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ from tensorflow.keras import layers,models
3
+ (train_images,train_labels),(test_images,test_labels) = tf.keras.datasets.mnist.load_data()
4
+
5
+ train_images = train_images.reshape((60000, 28, 28, 1)).astype('float32')/255
6
+ test_images = test_images.reshape((10000, 28, 28, 1)).astype('float32')/255
7
+
8
+ train_labels = tf.keras.utils.to_categorical(train_labels)
9
+ print('train_labels')
10
+ test_labels = tf.keras.utils.to_categorical(test_labels)
11
+
12
+ model = models.Sequential()
13
+ model.add(layers.Conv2D(32,(3,3),activation='relu',input_shape=(28,28,1)))
14
+ model.add(layers.MaxPooling2D(2,2))
15
+ model.add(layers.Conv2D(64,(3,3),activation='relu'))
16
+ model.add(layers.MaxPooling2D(2,2))
17
+ model.add(layers.Conv2D(64,(3,3),activation='relu'))
18
+ model.add(layers.Flatten())
19
+ model.add(layers.Dense(64,activation='relu'))
20
+ model.add(layers.Dense(10,activation='softmax'))
21
+
22
+ model.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'])
23
+ model.fit(train_images,train_labels,epochs=5,batch_size=64,validation_split=0.1)
24
+
25
+ model.save('model.h5')
26
+
27
+ print('Here am I')
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ tensorflow==2.10.1
2
+ gradio==3.50.2