Ferdinand Tom-Eshemogie commited on
Commit
890bc9f
·
1 Parent(s): 9dae650

I added an Air Jordan classifier

Browse files
Files changed (2) hide show
  1. aj_classifier.pkl +3 -0
  2. app.py +35 -5
aj_classifier.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e21d89dc770349163a0565ab5fa5d5f0d2a30b00b0a08db9c388a1192e1bb0a1
3
+ size 46988022
app.py CHANGED
@@ -1,7 +1,37 @@
1
- import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
1
+ import gradio as gr #Gradio for creating the web interface
2
+ from fastai.vision.all import load_learner, PILImage #FastAI fxns for model loading and image processing
3
 
4
+ # Load the trained model
5
+ learner = load_learner('aj_classifier.pkl')
6
+
7
+ def classify_image(img):
8
+ """
9
+ Function to classify an uploaded image using the trained model.
10
+
11
+ Args:
12
+ - img: The image uploaded by the user, received as a PILImage.
13
+
14
+ Returns:
15
+ - A string with the prediction and the probability of that prediction.
16
+ """
17
+ # Use the model to predict the class of the image
18
+ # 'predict' method returns three values: the predicted class, its index, and the probabilities of all classes.
19
+ pred, pred_idx, probs = learner.predict(img)
20
+
21
+ # Format the prediction and its probability as a string to show to the user
22
+ return f"This is an Air Jordan {pred}; {(probs[pred_idx]* 100):.02f} accurate"
23
+
24
+ # Create a Gradio interface
25
+ # This part sets up the Gradio web interface, specifying the function to call for predictions,
26
+ # the type of input it expects (an image), and the type of output (text).
27
+ iface = gr.Interface(fn=classify_image,
28
+ inputs=gr.Image(type='pil'), # Specifies that the input should be an image, automatically converted to PILImage
29
+ outputs="text", # Specifies that the output is text (the prediction and probability)
30
+ title="Air Jordan Model Classifier", # Title of the web interface
31
+ description="Upload an image of Air Jordan sneakers, and the classifier will predict the model.")
32
+
33
+ # This condition checks if the script is being run as the main program and launches the Gradio interface.
34
+ # It ensures that the Gradio server starts only when this script is executed directly, not when imported as a module.
35
+ if __name__ == "__main__":
36
+ iface.launch(share=True) # Starts the Gradio interface
37