Upload 5 files
Browse files- README (1).md +13 -0
- app (2).py +67 -0
- gitattributes +35 -0
- num_detect%20%281%29.h5 +3 -0
- requirements (1).txt +6 -0
README (1).md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Sketchulator
|
| 3 |
+
emoji: 🐨
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.38.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app (2).py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from keras.models import load_model
|
| 2 |
+
model=load_model('num_detect (1).h5')
|
| 3 |
+
import numpy as np
|
| 4 |
+
import cv2
|
| 5 |
+
from keras.preprocessing import image
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
def mnist_compatible(image_path, target_size=(28, 28)):
|
| 8 |
+
|
| 9 |
+
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
|
| 10 |
+
plt.imshow(img)
|
| 11 |
+
plt.show()
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
img_resized = cv2.resize(img, target_size)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
img_inverted = 255 - img_resized
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
img_normalized = img_inverted.astype('float32') / 255.0
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
img_array = image.img_to_array(img_normalized)
|
| 25 |
+
|
| 26 |
+
img_reshaped = img_array.reshape((*target_size, 1))
|
| 27 |
+
|
| 28 |
+
return img_reshaped
|
| 29 |
+
|
| 30 |
+
def recognize_digit(dict):
|
| 31 |
+
path1 = dict['composite']
|
| 32 |
+
arr = mnist_compatible(path1)
|
| 33 |
+
|
| 34 |
+
arr = np.expand_dims(arr, axis=0)
|
| 35 |
+
prediction = np.argmax(model.predict(arr))
|
| 36 |
+
return prediction
|
| 37 |
+
|
| 38 |
+
def calculator(image1, operation, image2):
|
| 39 |
+
# Recognize the drawn digits
|
| 40 |
+
num1 = recognize_digit(image1)
|
| 41 |
+
num2 = recognize_digit(image2)
|
| 42 |
+
|
| 43 |
+
# Perform the calculator operation
|
| 44 |
+
if operation == "add":
|
| 45 |
+
result = num1 + num2
|
| 46 |
+
elif operation == "subtract":
|
| 47 |
+
result = num1 - num2
|
| 48 |
+
elif operation == "multiply":
|
| 49 |
+
result = num1 * num2
|
| 50 |
+
elif operation == "divide":
|
| 51 |
+
result = num1 / num2
|
| 52 |
+
|
| 53 |
+
return result
|
| 54 |
+
import gradio as gr
|
| 55 |
+
|
| 56 |
+
with gr.Blocks() as demo:
|
| 57 |
+
with gr.Row():
|
| 58 |
+
with gr.Column():
|
| 59 |
+
image1 = gr.Paint(label="Draw First Number", type="filepath", brush=gr.Brush(colors=["#32cc70"]), canvas_size=(301, 301))
|
| 60 |
+
operation = gr.Radio(["add", "subtract", "multiply", "divide"])
|
| 61 |
+
image2 = gr.Paint(label="Draw Second Number", type="filepath", brush=gr.Brush(colors=["#32cc70"]), canvas_size=(301, 301))
|
| 62 |
+
submit_btn = gr.Button(value="Calculate")
|
| 63 |
+
with gr.Column():
|
| 64 |
+
result = gr.Textbox(label="Result")
|
| 65 |
+
|
| 66 |
+
submit_btn.click(calculator, inputs=[image1, operation, image2], outputs=[result])
|
| 67 |
+
demo.launch(share='True')
|
gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
num_detect%20%281%29.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:12e7eeaea412ad6820f6c228b2fe51de97568d3c21a8b7db362dc03c2712b48d
|
| 3 |
+
size 1505832
|
requirements (1).txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
numpy
|
| 3 |
+
opencv-python
|
| 4 |
+
matplotlib
|
| 5 |
+
pillow
|
| 6 |
+
gradio
|