Spaces:
Sleeping
Sleeping
Initial commit
Browse files- app.py +23 -0
- model.pkl +3 -0
- requirements.txt +5 -0
- test_image1.jpg +0 -0
- 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() # 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:72b878320ef7decea7c866e92fd6616e77ece3eb865a3166d7fbb1fddfe076bf
|
3 |
+
size 114611602
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastai==2.7.12
|
2 |
+
gradio==3.34.0
|
3 |
+
timm==0.9.2
|
4 |
+
torch==2.0.1
|
5 |
+
torchvision==0.15.2
|
test_image1.jpg
ADDED
test_image2.jpg
ADDED