danyanderson commited on
Commit
89ef1f0
·
verified ·
1 Parent(s): 9642a53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -19
app.py CHANGED
@@ -111,26 +111,18 @@ def predict_image(image):
111
  print("[ERROR] No image provided")
112
  return None, "No image provided", "N/A"
113
 
114
- # Si l'image est un chemin (string), la charger
115
- if isinstance(image, str):
116
- print(f"[DEBUG] Image is a path/string: {image[:50]}...")
 
117
  from PIL import Image as PILImage
118
- import base64
119
- import io
120
-
121
- # Si c'est un data URL base64
122
- if image.startswith('data:image'):
123
- print("[DEBUG] Decoding base64 image...")
124
- header, encoded = image.split(',', 1)
125
- image_data = base64.b64decode(encoded)
126
- image = PILImage.open(io.BytesIO(image_data))
127
- print(f"[DEBUG] Decoded image size: {image.size}")
128
  else:
129
- # C'est un chemin de fichier
130
- print(f"[DEBUG] Loading image from path...")
131
- image = PILImage.open(image)
132
 
133
- print(f"[DEBUG] Image type before classification: {type(image)}")
134
  annotated_img, label, conf = classify_image(image)
135
  print(f"[DEBUG] Classification successful: {label} ({conf})")
136
  return annotated_img, label, conf
@@ -197,7 +189,7 @@ with gr.Blocks(title="SerraSafe - Détection de Pestes") as demo:
197
  with gr.Tab("📷 Télécharger Image"):
198
  with gr.Row():
199
  with gr.Column():
200
- image_input = gr.Image(type="numpy", label="Télécharger une image")
201
  image_button = gr.Button("Analyser l'image", variant="primary")
202
  with gr.Column():
203
  image_output = gr.Image(label="Résultat")
@@ -228,7 +220,7 @@ with gr.Blocks(title="SerraSafe - Détection de Pestes") as demo:
228
  gr.Markdown("### Capturez une image avec votre webcam pour l'analyser")
229
  with gr.Row():
230
  with gr.Column():
231
- webcam_input = gr.Image(sources=["webcam"], type="numpy", label="Webcam", streaming=False)
232
  webcam_button = gr.Button("Analyser", variant="primary")
233
  with gr.Column():
234
  webcam_output = gr.Image(label="Résultat")
 
111
  print("[ERROR] No image provided")
112
  return None, "No image provided", "N/A"
113
 
114
+ # Avec type="pil", Gradio nous donne directement une PIL Image
115
+ # On vérifie quand même au cas où
116
+ if not isinstance(image, Image.Image):
117
+ print(f"[DEBUG] Converting {type(image)} to PIL Image...")
118
  from PIL import Image as PILImage
119
+ if isinstance(image, np.ndarray):
120
+ image = PILImage.fromarray(image)
 
 
 
 
 
 
 
 
121
  else:
122
+ print(f"[ERROR] Unexpected image type: {type(image)}")
123
+ return None, f"Unexpected type: {type(image)}", "N/A"
 
124
 
125
+ print(f"[DEBUG] Image size: {image.size}, mode: {image.mode}")
126
  annotated_img, label, conf = classify_image(image)
127
  print(f"[DEBUG] Classification successful: {label} ({conf})")
128
  return annotated_img, label, conf
 
189
  with gr.Tab("📷 Télécharger Image"):
190
  with gr.Row():
191
  with gr.Column():
192
+ image_input = gr.Image(type="pil", label="Télécharger une image")
193
  image_button = gr.Button("Analyser l'image", variant="primary")
194
  with gr.Column():
195
  image_output = gr.Image(label="Résultat")
 
220
  gr.Markdown("### Capturez une image avec votre webcam pour l'analyser")
221
  with gr.Row():
222
  with gr.Column():
223
+ webcam_input = gr.Image(sources=["webcam"], type="pil", label="Webcam", streaming=False)
224
  webcam_button = gr.Button("Analyser", variant="primary")
225
  with gr.Column():
226
  webcam_output = gr.Image(label="Résultat")