Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,13 @@
|
|
| 1 |
###############################################
|
| 2 |
-
## IT Betyar - Gradio MNIST - Képpel
|
| 3 |
|
| 4 |
import tensorflow as tf
|
| 5 |
import numpy as np
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
-
|
| 9 |
-
model = tf.keras.models.load_model('mnist.keras')
|
| 10 |
|
| 11 |
-
# Preprocess the input image
|
| 12 |
-
def preprocess_image(img):
|
| 13 |
if len(img.shape) == 3 and img.shape[-1] == 3:
|
| 14 |
img = tf.image.rgb_to_grayscale(img).numpy().squeeze()
|
| 15 |
|
|
@@ -23,19 +21,18 @@ def preprocess_image(img):
|
|
| 23 |
|
| 24 |
return img
|
| 25 |
|
| 26 |
-
# Predict the digit in the image
|
| 27 |
-
def predict_digit(img):
|
| 28 |
processed_img = preprocess_image(img)
|
| 29 |
processed_img = np.expand_dims(processed_img, axis=0) # Add batch dimension
|
| 30 |
prediction = model.predict(processed_img)[0]
|
| 31 |
return {str(i): float(prediction[i]) for i in range(10)}
|
| 32 |
|
| 33 |
-
#
|
|
|
|
| 34 |
|
| 35 |
# Custom CSS for button styles
|
| 36 |
custom_css = """
|
| 37 |
-
|
| 38 |
-
.custom-button {
|
| 39 |
background-color: #57a1a9; /* Green background */
|
| 40 |
color: white; /* White text */
|
| 41 |
padding: 10px 20px; /* Padding */
|
|
@@ -44,12 +41,12 @@ custom_css = """
|
|
| 44 |
font-size: 16px; /* Font size */
|
| 45 |
}
|
| 46 |
|
| 47 |
-
|
| 48 |
-
background-color: #345e63; /* Darker
|
| 49 |
}
|
| 50 |
-
</style>
|
| 51 |
"""
|
| 52 |
|
|
|
|
| 53 |
header_html = """
|
| 54 |
<div style="text-align: center; max-width: 650px; margin: 0 auto;">
|
| 55 |
<img src="https://huggingface.co/spaces/itbetyar/MNISTClassifier/resolve/main/mnist_img.webp" alt="Header Image" style="max-width: 100%; height: auto; margin: 20px 0;">
|
|
@@ -62,7 +59,7 @@ header_html = """
|
|
| 62 |
"""
|
| 63 |
|
| 64 |
# Gradio interface with header and layout
|
| 65 |
-
with gr.Blocks() as ablakom:
|
| 66 |
gr.HTML(header_html) # Add the header HTML block
|
| 67 |
|
| 68 |
with gr.Row():
|
|
@@ -86,7 +83,4 @@ with gr.Blocks() as ablakom:
|
|
| 86 |
classify_btn.click(predict_digit, inputs=input_image, outputs=output)
|
| 87 |
clear_btn.click(lambda: [None, None], inputs=None, outputs=[input_image, output])
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
# Launch the ablakom
|
| 92 |
-
ablakom.launch()
|
|
|
|
| 1 |
###############################################
|
| 2 |
+
## IT Betyar - Gradio MNIST - Képpel - Mintákkal
|
| 3 |
|
| 4 |
import tensorflow as tf
|
| 5 |
import numpy as np
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
+
model = tf.keras.models.load_model('mnist.keras') # a modell betoltese
|
|
|
|
| 9 |
|
| 10 |
+
def preprocess_image(img): # Preprocess the input image
|
|
|
|
| 11 |
if len(img.shape) == 3 and img.shape[-1] == 3:
|
| 12 |
img = tf.image.rgb_to_grayscale(img).numpy().squeeze()
|
| 13 |
|
|
|
|
| 21 |
|
| 22 |
return img
|
| 23 |
|
| 24 |
+
def predict_digit(img): # Predict the digit in the image
|
|
|
|
| 25 |
processed_img = preprocess_image(img)
|
| 26 |
processed_img = np.expand_dims(processed_img, axis=0) # Add batch dimension
|
| 27 |
prediction = model.predict(processed_img)[0]
|
| 28 |
return {str(i): float(prediction[i]) for i in range(10)}
|
| 29 |
|
| 30 |
+
## Fonti a mukodteto funkcio kodok
|
| 31 |
+
## Alabb a Gradio interface resz
|
| 32 |
|
| 33 |
# Custom CSS for button styles
|
| 34 |
custom_css = """
|
| 35 |
+
.custom-button {
|
|
|
|
| 36 |
background-color: #57a1a9; /* Green background */
|
| 37 |
color: white; /* White text */
|
| 38 |
padding: 10px 20px; /* Padding */
|
|
|
|
| 41 |
font-size: 16px; /* Font size */
|
| 42 |
}
|
| 43 |
|
| 44 |
+
.custom-button:hover {
|
| 45 |
+
background-color: #345e63; /* Darker on hover */
|
| 46 |
}
|
|
|
|
| 47 |
"""
|
| 48 |
|
| 49 |
+
# HTML for the header
|
| 50 |
header_html = """
|
| 51 |
<div style="text-align: center; max-width: 650px; margin: 0 auto;">
|
| 52 |
<img src="https://huggingface.co/spaces/itbetyar/MNISTClassifier/resolve/main/mnist_img.webp" alt="Header Image" style="max-width: 100%; height: auto; margin: 20px 0;">
|
|
|
|
| 59 |
"""
|
| 60 |
|
| 61 |
# Gradio interface with header and layout
|
| 62 |
+
with gr.Blocks((css=custom_css)) as ablakom:
|
| 63 |
gr.HTML(header_html) # Add the header HTML block
|
| 64 |
|
| 65 |
with gr.Row():
|
|
|
|
| 83 |
classify_btn.click(predict_digit, inputs=input_image, outputs=output)
|
| 84 |
clear_btn.click(lambda: [None, None], inputs=None, outputs=[input_image, output])
|
| 85 |
|
| 86 |
+
ablakom.launch() # az interface inditasa
|
|
|
|
|
|
|
|
|