kotlarska2 commited on
Commit
b9a0ee7
·
verified ·
1 Parent(s): 270ad8a

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +23 -0
  2. model.pkl +3 -0
  3. requirements.txt +9 -0
  4. test_image1.jpg +0 -0
  5. test_image2.jpg +0 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import * # Importing the necessary fastai modules
2
+ import gradio as gr # Importing Gradio for creating the web interface
3
+ import timm # Importing timm for model management
4
+
5
+ # Load the pre-trained model
6
+ learn = load_learner('model.pkl')
7
+
8
+ # Extract categories (class labels) from the DataLoader
9
+ categories = learn.dls.vocab
10
+
11
+ # Function to classify an image
12
+ def classify_image(img):
13
+ _, _, probs = learn.predict(img)
14
+ return dict(zip(categories, map(float, probs))) # Map categories to their probabilities
15
+
16
+ # Define Gradio input and output components
17
+ image = gr.Image(width=224, height=224) # Image input
18
+ label = gr.Label() # Output label to display classification
19
+ examples = ['test_image1.jpg', 'test_image2.jpg'] # Example images for demonstration
20
+
21
+ # Create and launch the Gradio interface
22
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
23
+ intf.launch()
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b1dc6a8b22855e77b9e7a27d5efcd702682cc3cd368eaa852e2b5047104cbe39
3
+ size 46976690
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ numpy==1.26.4
2
+ scipy==1.11.4
3
+ scikit-learn==1.3.2
4
+ fastai==2.7.17
5
+ gradio==4.44.1
6
+ timm==1.0.9
7
+ torch==2.2.1
8
+ torchvision==0.17.1
9
+ setuptools
test_image1.jpg ADDED
test_image2.jpg ADDED