alperugurcan commited on
Commit
0737f7f
·
verified ·
1 Parent(s): 14fd41b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Load your model
7
+ model = tf.keras.models.load_model("ElYazisiRakamlariTahmin.h5")
8
+
9
+ def preprocess_image(image):
10
+ # Implement your image preprocessing here
11
+ # This is just a placeholder example
12
+ image = image.convert("L") # Convert to grayscale
13
+ image = image.resize((28, 28)) # Resize to match your model's input size
14
+ image = np.array(image) / 255.0 # Normalize
15
+ return image.reshape(1, 28, 28, 1) # Reshape for model input
16
+
17
+ def predict_digit(image):
18
+ preprocessed = preprocess_image(image)
19
+ prediction = model.predict(preprocessed)
20
+ digit = np.argmax(prediction)
21
+ confidence = np.max(prediction)
22
+ return f"Predicted Digit: {digit}, Confidence: {confidence:.2f}"
23
+
24
+ iface = gr.Interface(
25
+ fn=predict_digit,
26
+ inputs=gr.Image(type="pil"),
27
+ outputs="text",
28
+ title="Handwritten Digit Recognition",
29
+ description="Upload an image of a handwritten digit (0-9) to get a prediction."
30
+ )
31
+
32
+ iface.launch()