Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,32 +3,28 @@ import gradio as gr
|
|
3 |
import tensorflow as tf
|
4 |
import numpy as np
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
"The robot was trained to classify numbers (from 0 to 9). "
|
10 |
-
"
|
11 |
)
|
|
|
12 |
|
13 |
-
article = "Find the whole code [here](https://github.com/ovh/ai-training-examples/tree/main/apps/gradio/sketch-recognition)."
|
14 |
-
|
15 |
-
# Model parametreleri
|
16 |
img_size = 28
|
17 |
labels = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
18 |
|
19 |
-
# Model
|
20 |
model = tf.keras.models.load_model("number_recognition_model_colab.keras")
|
21 |
|
22 |
-
# Tahmin fonksiyonu
|
23 |
def predict(img):
|
24 |
try:
|
25 |
-
#
|
26 |
if not isinstance(img, np.ndarray):
|
27 |
img = np.array(img)
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
img = cv2.resize(img, (img_size, img_size))
|
33 |
img = img.astype('float32') / 255.0
|
34 |
img = img.reshape(1, img_size, img_size, 1)
|
@@ -39,18 +35,16 @@ def predict(img):
|
|
39 |
except Exception as e:
|
40 |
return {"Error": str(e)}
|
41 |
|
42 |
-
|
|
|
|
|
43 |
interface = gr.Interface(
|
44 |
fn=predict,
|
45 |
-
inputs=gr.
|
46 |
-
outputs=
|
47 |
title=title,
|
48 |
-
description=
|
49 |
-
article=
|
50 |
-
allow_flagging="manual", # Flagging'i etkinleştir
|
51 |
-
flagging_options=["Incorrect Prediction", "Other Issues"], # Kullanıcıların seçebileceği flag nedenleri
|
52 |
-
flagging_dir="flagged_results" # Flag sonuçlarını kaydedeceği klasör
|
53 |
)
|
54 |
|
55 |
-
|
56 |
-
interface.launch()
|
|
|
3 |
import tensorflow as tf
|
4 |
import numpy as np
|
5 |
|
6 |
+
title = "Welcome to your first sketch recognition app!"
|
7 |
+
head = (
|
8 |
+
"<center>"
|
9 |
+
"The robot was trained to classify numbers (from 0 to 9). To test it, write your number in the space provided."
|
10 |
+
"</center>"
|
11 |
)
|
12 |
+
ref = "Find the whole code [here](https://github.com/ovh/ai-training-examples/tree/main/apps/gradio/sketch-recognition)."
|
13 |
|
|
|
|
|
|
|
14 |
img_size = 28
|
15 |
labels = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
16 |
|
17 |
+
# Model yükleniyor
|
18 |
model = tf.keras.models.load_model("number_recognition_model_colab.keras")
|
19 |
|
|
|
20 |
def predict(img):
|
21 |
try:
|
22 |
+
# Girdi görselini NumPy array'e çevir
|
23 |
if not isinstance(img, np.ndarray):
|
24 |
img = np.array(img)
|
25 |
|
26 |
+
# Görüntüyü gri tonlamaya çevir ve yeniden boyutlandır
|
27 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) if img.ndim == 3 else img
|
|
|
28 |
img = cv2.resize(img, (img_size, img_size))
|
29 |
img = img.astype('float32') / 255.0
|
30 |
img = img.reshape(1, img_size, img_size, 1)
|
|
|
35 |
except Exception as e:
|
36 |
return {"Error": str(e)}
|
37 |
|
38 |
+
label = gr.Label(num_top_classes=3)
|
39 |
+
|
40 |
+
# Yeni Gradio bileşenleriyle uyumlu hale getirildi
|
41 |
interface = gr.Interface(
|
42 |
fn=predict,
|
43 |
+
inputs=gr.Sketchpad(label="Draw a number"), # Sketchpad kullanımı
|
44 |
+
outputs=label,
|
45 |
title=title,
|
46 |
+
description=head,
|
47 |
+
article=ref
|
|
|
|
|
|
|
48 |
)
|
49 |
|
50 |
+
interface.launch(debug=True)
|
|