busebaser commited on
Commit
46b22e9
·
1 Parent(s): 4a7d132

Fix: Convert image to Fastai PILImage before prediction

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -1,18 +1,27 @@
1
- from fastai.vision.all import load_learner
2
  import gradio as gr
3
  from PIL import Image
4
 
5
- # Define the missing function
6
- def is_cat(x):
7
- return x[0].isupper()
8
-
9
  # Load the trained model
10
  model = load_learner('model.pkl')
11
 
12
  # Define a function to make predictions
13
  def predict(image):
14
- pred, _, probs = model.predict(image)
15
- return f"Prediction: {pred} (Confidence: {probs.max():.2f})"
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  # Create the Gradio web interface
18
  interface = gr.Interface(
 
1
+ from fastai.vision.all import load_learner, PILImage
2
  import gradio as gr
3
  from PIL import Image
4
 
 
 
 
 
5
  # Load the trained model
6
  model = load_learner('model.pkl')
7
 
8
  # Define a function to make predictions
9
  def predict(image):
10
+ try:
11
+ print("📸 Received image for prediction")
12
+
13
+ # Convert to Fastai's expected PILImage format
14
+ image = PILImage.create(image)
15
+
16
+ # Run prediction
17
+ pred, _, probs = model.predict(image)
18
+ print(f"✅ Prediction successful: {pred}, Confidence: {probs.max():.2f}")
19
+
20
+ return f"Prediction: {pred} (Confidence: {probs.max():.2f})"
21
+
22
+ except Exception as e:
23
+ print(f"❌ Error during prediction: {e}")
24
+ return f"Error: {e}"
25
 
26
  # Create the Gradio web interface
27
  interface = gr.Interface(