utkmst commited on
Commit
9dc1be5
·
1 Parent(s): 098cb8a

Add initial application files and model

Browse files
Files changed (6) hide show
  1. app.py +24 -0
  2. example1.jpeg +0 -0
  3. example2.jpeg +0 -0
  4. example3.jpeg +0 -0
  5. human_race_model.pkl +3 -0
  6. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ___all___ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
2
+
3
+ from fastai.vision.all import *
4
+ import gradio as gr
5
+
6
+ # Load the trained model
7
+ learn = load_learner('human_race_model.pkl')
8
+
9
+ # Define the categories based on your model's output
10
+ categories = learn.dls.vocab
11
+
12
+ # Define the function to classify images
13
+ def classify_image(img):
14
+ pred, idx, probs = learn.predict(img)
15
+ return dict(zip(categories, map(float, probs)))
16
+
17
+ # Define the Gradio components
18
+ image = gr.Image(type='pil', label='Input Image')
19
+ label = gr.Label()
20
+ examples = ['example1.jpeg', 'example2.jpeg', 'example3.jpeg'] # Replace with your example images
21
+
22
+ # Create and launch the Gradio interface
23
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, title="Image Classifier", examples=examples)
24
+ intf.launch(inline=False)
example1.jpeg ADDED
example2.jpeg ADDED
example3.jpeg ADDED
human_race_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:515f3f10533d6b5510db7126eb5dd81936ced0ecedf535f036f35a84958da0b4
3
+ size 47110142
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastai
2
+ fastapi
3
+ uvicorn
4
+ aiofiles