alperugurcan's picture
Update app.py
0737f7f verified
raw
history blame
1.03 kB
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
# Load your model
model = tf.keras.models.load_model("ElYazisiRakamlariTahmin.h5")
def preprocess_image(image):
# Implement your image preprocessing here
# This is just a placeholder example
image = image.convert("L") # Convert to grayscale
image = image.resize((28, 28)) # Resize to match your model's input size
image = np.array(image) / 255.0 # Normalize
return image.reshape(1, 28, 28, 1) # Reshape for model input
def predict_digit(image):
preprocessed = preprocess_image(image)
prediction = model.predict(preprocessed)
digit = np.argmax(prediction)
confidence = np.max(prediction)
return f"Predicted Digit: {digit}, Confidence: {confidence:.2f}"
iface = gr.Interface(
fn=predict_digit,
inputs=gr.Image(type="pil"),
outputs="text",
title="Handwritten Digit Recognition",
description="Upload an image of a handwritten digit (0-9) to get a prediction."
)
iface.launch()