cisemh commited on
Commit
2d99dd4
·
verified ·
1 Parent(s): 21f1f08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -20,19 +20,15 @@ img_size = 28
20
 
21
  labels = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
22
 
23
- # Tahmin fonksiyonu
24
  def predict(img):
25
  try:
26
- # If the input is a dictionary (Gradio sketchpad), extract the image
27
- if isinstance(img, dict):
28
- img = img.get('image', None) # Get the image from the dictionary
29
-
30
- if img is None:
31
- raise ValueError("No image data found")
32
 
33
- # Convert the input image to a NumPy array if needed
34
  if not isinstance(img, np.ndarray):
35
- img = np.array(img)
36
 
37
  # Print shape and type of the input image
38
  print(f"Initial image type: {type(img)}, shape: {img.shape}")
@@ -69,6 +65,8 @@ def predict(img):
69
  print(f"Error during prediction: {e}")
70
  return {"Error": str(e)}
71
 
 
 
72
  # Set up the Gradio interface with the input as a sketchpad and output as labels
73
  label = gr.Label(num_top_classes=3)
74
 
@@ -81,4 +79,4 @@ interface = gr.Interface(
81
  description="Draw a number (0-9) and see the model's top predictions."
82
  )
83
 
84
- interface.launch(debug=True)
 
20
 
21
  labels = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
22
 
 
23
  def predict(img):
24
  try:
25
+ # Check if the image is a PIL object and convert it to NumPy array
26
+ if isinstance(img, Image.Image):
27
+ img = np.array(img)
 
 
 
28
 
29
+ # If the input is still not a NumPy array, return an error
30
  if not isinstance(img, np.ndarray):
31
+ raise ValueError("Input is not a valid image")
32
 
33
  # Print shape and type of the input image
34
  print(f"Initial image type: {type(img)}, shape: {img.shape}")
 
65
  print(f"Error during prediction: {e}")
66
  return {"Error": str(e)}
67
 
68
+
69
+
70
  # Set up the Gradio interface with the input as a sketchpad and output as labels
71
  label = gr.Label(num_top_classes=3)
72
 
 
79
  description="Draw a number (0-9) and see the model's top predictions."
80
  )
81
 
82
+ interface.launch(debug=True, share=True)