Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +65 -0
- burmese_digits_recognition.ipynb +0 -0
- last_burmese_Digit_recognizer_model.h5 +3 -0
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
from tensorflow.keras.models import load_model
|
5 |
+
from streamlit_drawable_canvas import st_canvas
|
6 |
+
|
7 |
+
# Function to preprocess the image
|
8 |
+
def preprocess_image(image, target_size):
|
9 |
+
if image.mode != "RGB":
|
10 |
+
image = image.convert("RGB")
|
11 |
+
image = image.resize(target_size)
|
12 |
+
image = np.expand_dims(image, axis=0)
|
13 |
+
return image
|
14 |
+
|
15 |
+
# Function to predict the digit
|
16 |
+
def predict_digit(model, image):
|
17 |
+
processed_image = preprocess_image(image, (200, 200)) # Match your model's input size
|
18 |
+
prediction = model.predict(processed_image)
|
19 |
+
return np.argmax(prediction), np.max(prediction)
|
20 |
+
|
21 |
+
# Load your trained model
|
22 |
+
model = load_model("last_burmese_Digit_recognizer_model.h5")
|
23 |
+
|
24 |
+
# Streamlit app
|
25 |
+
st.title("Burmese Digit Recognizer")
|
26 |
+
|
27 |
+
# Upload image file or draw
|
28 |
+
st.markdown("## Upload an Image or Draw")
|
29 |
+
col1, col2 = st.columns(2)
|
30 |
+
|
31 |
+
with col1:
|
32 |
+
file = st.file_uploader("Upload Here", type=['png', 'jpg', 'jpeg'])
|
33 |
+
|
34 |
+
with col2:
|
35 |
+
# Drawable canvas
|
36 |
+
canvas_result = st_canvas(
|
37 |
+
fill_color="rgba(255, 165, 0, 0.3)", # Drawing parameters
|
38 |
+
stroke_width=3,
|
39 |
+
stroke_color="#ffffff",
|
40 |
+
background_color="#000000",
|
41 |
+
background_image=None if file else st.session_state.get("background", None),
|
42 |
+
update_streamlit=True,
|
43 |
+
width=400,
|
44 |
+
height=400,
|
45 |
+
drawing_mode="freedraw",
|
46 |
+
key="canvas",
|
47 |
+
)
|
48 |
+
|
49 |
+
image = None # Initialize image variable
|
50 |
+
|
51 |
+
# Process uploaded image or drawing
|
52 |
+
if file is not None:
|
53 |
+
image = Image.open(file) # Read image with PIL
|
54 |
+
elif canvas_result.image_data is not None:
|
55 |
+
image = Image.fromarray(np.array(canvas_result.image_data, dtype=np.uint8)).convert('RGB')
|
56 |
+
|
57 |
+
if image is not None:
|
58 |
+
st.image(image, caption='Uploaded Image') # Display the uploaded/drawn image
|
59 |
+
|
60 |
+
# Predict the digit
|
61 |
+
digit, confidence = predict_digit(model, image)
|
62 |
+
st.write(f"Predicted Digit: {digit} with confidence {confidence:.2f}")
|
63 |
+
else:
|
64 |
+
st.write("Please upload an image or use the canvas to draw.")
|
65 |
+
|
burmese_digits_recognition.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
last_burmese_Digit_recognizer_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f7b9e142811cab1845e66e162bf1dcfa6caf203ab391168ae7e117bf63fc421c
|
3 |
+
size 100447544
|