############################################### ## IT Betyar - A.I. Developer tanfolyam ## ## https://itbetyar.hu/mesterseges-intelligencia-fejleszto-tanfolyam/ ## ## Gradio MNIST - Képpel - Mintákkal import gradio as gr import tensorflow as tf import numpy as np model = tf.keras.models.load_model('mnist.keras') # a modell betoltese def preprocess_image(img): # Potenciális RGB 2 gray konverzió if len(img.shape) == 3 and img.shape[-1] == 3: # ha szines img = tf.image.rgb_to_grayscale(img).numpy().squeeze() # hatekony gray conv. > np array lesz belőle img = tf.image.resize(img[None, ..., None], (28, 28)).numpy().squeeze() # resize # dimenziót is váltogatunk, a tf.image.resizenak kell ez if img.mean() > 127: # szin invert img = 255 - img img = img.astype('float32') / 255.0 # Normalizál img = img.reshape(784) # Flatten the image return img def predict_digit(img): # Predict the digit in the image processed_img = preprocess_image(img) processed_img = np.expand_dims(processed_img, axis=0) # Add batch dimension prediction = model.predict(processed_img)[0] return {str(i): float(prediction[i]) for i in range(10)} # Gradio comaptible kiiras ## Fonti a mukodteto funkcio kodok ## Alabb a Gradio interface resz # HTML for the header header_html = """
Header Image

MNIST Digit Recognition

by itbetyar.hu

A.I. Developer tanfolyam minta anyag
Tölts fel egy kézzel írott szám képet (0-9) vagy használd alábbi mintákat!
A modell megállapítja melyik szám az.

""" footer_html = """

Leírás:

Fenti anyagunk az A.I. Developer tanfolyamunk egy minta anyaga. Az MNIST Digit Classifikáció minden A.I. és Machine learining tanfolyam alap modellje, anyaga. Egy remek kezdő projekt.

A lényege -mint azt fent láthatod- hogy 60,000 kézzel írt számkarakter alapján, a diákok feltanítanak egy A.I. modellt. Miután készen van, a modell képes kézzel írt számok felismerésére

""" with open("styles.css", "r") as file: custom_css = file.read() # Read the external CSS file # Gradio interface with header and layout with gr.Blocks(css=custom_css) as ablakom: with gr.Column(elem_id="main-container"): gr.HTML(header_html) # Add the header HTML block with gr.Row(): with gr.Column(scale=1): input_image = gr.Image(type="numpy", label="Tölts fel egy képet...", height=210, width=350, sources=["upload"]) with gr.Row(): clear_btn = gr.Button("Reset") classify_btn = gr.Button("Mehet", elem_classes="custom-button") examples = gr.Examples( examples=["imgs/itbtest1.jpg", "imgs/itbtest3.jpg", "imgs/itbtest4.jpg", "imgs/itbtest5.jpg", "imgs/itbtest6.jpg"], inputs=input_image, label="Minták" ) with gr.Column(scale=1): output = gr.Label(num_top_classes=3, label="A feltöltött számjegy:") with gr.Column(): gr.HTML(footer_html) # Button actions classify_btn.click(predict_digit, inputs=input_image, outputs=output) clear_btn.click(lambda: [None, None], inputs=None, outputs=[input_image, output]) ablakom.launch() # az interface inditasa ## IT Betyar - A.I. Developer tanfolyam ## ## https://itbetyar.hu/mesterseges-intelligencia-fejleszto-tanfolyam/ ## ## Gradio MNIST - Képpel - Mintákkal ########################################################################