|
import gradio as gr |
|
import tensorflow as tf |
|
import numpy as np |
|
from PIL import Image |
|
|
|
|
|
model = tf.keras.models.load_model("ElYazisiRakamlariTahmin.h5") |
|
|
|
def preprocess_image(image): |
|
|
|
|
|
image = image.convert("L") |
|
image = image.resize((28, 28)) |
|
image = np.array(image) / 255.0 |
|
return image.reshape(1, 28, 28, 1) |
|
|
|
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() |