cisemh commited on
Commit
9a87dce
·
verified ·
1 Parent(s): b304a71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -24
app.py CHANGED
@@ -3,32 +3,28 @@ import gradio as gr
3
  import tensorflow as tf
4
  import numpy as np
5
 
6
- # Başlık ve açıklama
7
- title = "Welcome on your first sketch recognition app!"
8
- description = (
9
- "The robot was trained to classify numbers (from 0 to 9). "
10
- "To test it, write your number in the space provided."
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 yükleme
20
  model = tf.keras.models.load_model("number_recognition_model_colab.keras")
21
 
22
- # Tahmin fonksiyonu
23
  def predict(img):
24
  try:
25
- # Görüntüyü işleme
26
  if not isinstance(img, np.ndarray):
27
  img = np.array(img)
28
 
29
- if img.ndim == 3 and img.shape[-1] == 3:
30
- img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
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
- # Gradio arayüzü
 
 
43
  interface = gr.Interface(
44
  fn=predict,
45
- inputs=gr.inputs.Sketchpad(label="Draw a number"), # Kullanıcının sayı çizebileceği alan
46
- outputs=gr.outputs.Label(num_top_classes=3, label="Predicted Number"), # Tahminlerin gösterileceği alan
47
  title=title,
48
- description=description,
49
- article=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
- # Uygulamayı başlat
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)