busebaser commited on
Commit
95c07de
·
1 Parent(s): 0972752

Deploy Cat-Dog Recognition model

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -1,7 +1,23 @@
 
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import load_learner
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
+ pred, _, probs = model.predict(image)
11
+ return f"Prediction: {pred} (Confidence: {probs.max():.2f})"
12
+
13
+ # Create the Gradio web interface
14
+ interface = gr.Interface(
15
+ fn=predict,
16
+ inputs=gr.inputs.Image(type="pil"),
17
+ outputs="text",
18
+ title="Cat vs Dog Classifier",
19
+ description="Upload an image of a cat or dog and let the model classify it!"
20
+ )
21
+
22
+ # Launch the Gradio app
23
+ interface.launch()