itbetyar commited on
Commit
f3b9283
·
verified ·
1 Parent(s): 25ab9e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -31
app.py CHANGED
@@ -1,5 +1,9 @@
1
  ###############################################
2
- ## IT Betyar - Gradio MNIST - Képpel - Mintákkal
 
 
 
 
3
 
4
  import tensorflow as tf
5
  import numpy as np
@@ -21,7 +25,7 @@ def preprocess_image(img): # Preprocess the input image
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]
@@ -30,43 +34,48 @@ def predict_digit(img): # Predict the digit in the image
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 */
39
- border: none; /* No border */
40
- cursor: pointer; /* Pointer cursor */
41
- font-size: 16px; /* Font size */
42
- }
43
-
44
- .custom-button:hover {
45
- background-color: #345e63;
46
- }
47
-
48
- #main-container {
49
- max-width: 900px;
50
- margin: 0 auto;
51
- }
52
- """
53
-
54
  # HTML for the header
55
  header_html = """
56
- <div style="text-align: center; max-width: 650px; margin: 0 auto;">
57
- <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;">
58
- <h1 style="color: #8397aa; font-size: 2.5em;">MNIST Digit Recognition | by itbetyar.hu</h1>
59
- <p style="color: #FFFFFF; font-size: 1.2em;">
60
- Tölts fel egy kézzel írott szám képet (0-9) vagy használd alábbi mintákat!<br>
61
- A modell megállapítja melyik szám az.
62
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  </div>
64
  """
65
 
 
 
 
66
  # Gradio interface with header and layout
67
  with gr.Blocks(css=custom_css) as ablakom:
68
  with gr.Column(elem_id="main-container"):
69
  gr.HTML(header_html) # Add the header HTML block
 
70
 
71
  with gr.Row():
72
  with gr.Column(scale=1):
@@ -85,8 +94,19 @@ with gr.Blocks(css=custom_css) as ablakom:
85
  with gr.Column(scale=1):
86
  output = gr.Label(num_top_classes=3, label="A feltöltött számjegy:")
87
 
 
 
 
88
  # Button actions
89
  classify_btn.click(predict_digit, inputs=input_image, outputs=output)
90
  clear_btn.click(lambda: [None, None], inputs=None, outputs=[input_image, output])
91
 
92
- ablakom.launch() # az interface inditasa
 
 
 
 
 
 
 
 
 
1
  ###############################################
2
+ ## IT Betyar - A.I. Developer tanfolyam
3
+ ##
4
+ ## https://itbetyar.hu/mesterseges-intelligencia-fejleszto-tanfolyam/
5
+ ##
6
+ ## Gradio MNIST - Képpel - Mintákkal
7
 
8
  import tensorflow as tf
9
  import numpy as np
 
25
 
26
  return img
27
 
28
+ def predict_digit(img): # Predict the digit in the image
29
  processed_img = preprocess_image(img)
30
  processed_img = np.expand_dims(processed_img, axis=0) # Add batch dimension
31
  prediction = model.predict(processed_img)[0]
 
34
  ## Fonti a mukodteto funkcio kodok
35
  ## Alabb a Gradio interface resz
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  # HTML for the header
38
  header_html = """
39
+ <div style="max-width: 900px; margin: 0 auto; text-align: center;">
40
+ <div style="display: flex; justify-content: center; align-items: center;">
41
+ <div style="flex: 1; text-align: center;">
42
+ <img src="https://huggingface.co/spaces/itbetyar/MNISTClassifier/resolve/main/mnist_img.webp" alt="Header Image" style="max-width: 100%; height: auto; margin: 20px;">
43
+ </div>
44
+ <div style="flex: 1; padding-left: 30px; text-align: left;">
45
+ <h1 style="color: #8397aa; font-size: 3em;">MNIST Digit Recognition</h1>
46
+ <h3 style="color: #7CE0E1; font-size: 1.8em;">by itbetyar.hu</h3>
47
+ </div>
48
+ </div>
49
+ <div style="text-align: center; background-color: #1b2428; border-radius: 10px;">
50
+ <p style="color: #FFFFFF; padding: 5px; font-size: 1.2em; margin-top: 0px;">
51
+ <a href="https://itbetyar.hu/mesterseges-intelligencia-fejleszto-tanfolyam/">A.I. Developer tanfolyam minta anyag</a><br>
52
+ Tölts fel egy kézzel írott szám képet (0-9) vagy használd alábbi mintákat!<br>
53
+ A modell megállapítja melyik szám az.
54
+ </p>
55
+ </div>
56
+ </div>
57
+ """
58
+
59
+ footer_html = """
60
+ <div style="max-width: 900px; margin: 0 auto; text-align: center;">
61
+ <h3 style="color: #7CE0E1; font-size: 1.8em;">Leírás:</h3>
62
+ <p style="font-size: 1.3em;">
63
+ Fenti anyagunk az <a href="https://itbetyar.hu/mesterseges-intelligencia-fejleszto-tanfolyam/">A.I. Developer tanfolyamunk</a> egy minta anyaga. Az MNIST Digit Classifikáció minden A.I. és Machine learining tanfolyam alap modellje, anyaga. Egy remek kezdő projekt.
64
+ </p>
65
+ <p style="padding: 5px; font-size: 1.3em; margin-top: 0px;">
66
+ A lényege -mint azt fent láthatod- hogy <b>60,000 kézzel írt számkarakter</b> 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
67
+ </p>
68
  </div>
69
  """
70
 
71
+ with open("styles.css", "r") as file:
72
+ custom_css = file.read() # Read the external CSS file
73
+
74
  # Gradio interface with header and layout
75
  with gr.Blocks(css=custom_css) as ablakom:
76
  with gr.Column(elem_id="main-container"):
77
  gr.HTML(header_html) # Add the header HTML block
78
+
79
 
80
  with gr.Row():
81
  with gr.Column(scale=1):
 
94
  with gr.Column(scale=1):
95
  output = gr.Label(num_top_classes=3, label="A feltöltött számjegy:")
96
 
97
+ with gr.Column():
98
+ gr.HTML(footer_html)
99
+
100
  # Button actions
101
  classify_btn.click(predict_digit, inputs=input_image, outputs=output)
102
  clear_btn.click(lambda: [None, None], inputs=None, outputs=[input_image, output])
103
 
104
+ ablakom.launch() # az interface inditasa
105
+
106
+
107
+ ## IT Betyar - A.I. Developer tanfolyam
108
+ ##
109
+ ## https://itbetyar.hu/mesterseges-intelligencia-fejleszto-tanfolyam/
110
+ ##
111
+ ## Gradio MNIST - Képpel - Mintákkal
112
+ ########################################################################