abhi0987 commited on
Commit
cde47a4
·
1 Parent(s): 8dc268a

initial commit

Browse files
Files changed (2) hide show
  1. num_detect.py +59 -0
  2. requirement.txt +5 -0
num_detect.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """num_detect.ipynb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1GcHZ0KGkpSs8vsjRbjMHBRVZ6M86nqYj
8
+ """
9
+
10
+ from keras.models import load_model
11
+ model=load_model(r"C:\Users\Abhijeet Tripathi\Downloads\num_detect (1).keras")
12
+
13
+
14
+ import numpy as np
15
+ import cv2
16
+ from keras.preprocessing import image
17
+ import matplotlib.pyplot as plt
18
+ def mnist_compatible(image_path, target_size=(28, 28)):
19
+
20
+ img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
21
+ plt.imshow(img)
22
+ plt.show()
23
+
24
+
25
+
26
+ img_resized = cv2.resize(img, target_size)
27
+
28
+
29
+ img_inverted = 255 - img_resized
30
+
31
+
32
+ img_normalized = img_inverted.astype('float32') / 255.0
33
+
34
+
35
+ img_array = image.img_to_array(img_normalized)
36
+
37
+ img_reshaped = img_array.reshape((*target_size, 1))
38
+
39
+ return img_reshaped
40
+
41
+ def predict(dict):
42
+ print(dict)
43
+ path = dict['composite']
44
+ arr = mnist_compatible(path)
45
+ arr = np.expand_dims(arr, axis=0)
46
+ return str(np.argmax(model.predict(arr)))
47
+
48
+ import gradio as gr
49
+
50
+ # Import the Brush class
51
+ from gradio import Brush
52
+
53
+ iface = gr.Interface(
54
+ fn=predict,
55
+ inputs=gr.Paint(label="Input Image Component",type="filepath",brush=Brush(colors=["#32cc70"]),canvas_size=(301,601)),
56
+ outputs="text"
57
+ )
58
+
59
+ iface.launch(share='True')
requirement.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ tensorflow
2
+ numpy
3
+ opencv-python
4
+ matplotlib
5
+ gradio