Spaces:
Build error
Build error
Mohammed Adil commited on
Commit ·
cbad3f8
1
Parent(s): e478dc2
Refactor app.py to streamline model loading and update Gradio interface; remove old model files and add new model files.
Browse files- app.py +16 -33
- models/archclassifier_v2.pkl +3 -0
- model.pkl → models/model.pkl +0 -0
app.py
CHANGED
|
@@ -1,48 +1,31 @@
|
|
| 1 |
-
|
| 2 |
-
import gradio as gr
|
| 3 |
-
|
| 4 |
-
# Load trained model
|
| 5 |
-
learn = load_learner('model.pkl')
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
import numpy as np
|
| 10 |
-
from fastai.vision.all import PILImage
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
elif not isinstance(img, Image.Image):
|
| 17 |
-
raise ValueError("Input is not a valid image")
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
probs = probs.cpu().numpy()
|
| 25 |
-
return dict(zip(learn.dls.vocab, probs))
|
| 26 |
|
| 27 |
-
# Gradio interface
|
| 28 |
intf = gr.Interface(
|
| 29 |
fn=classify_image,
|
| 30 |
-
inputs=gr.Image(
|
| 31 |
-
outputs=gr.Label(num_top_classes=3),
|
| 32 |
-
title="Architectural Style Classifier 🏛️",
|
| 33 |
-
description=(
|
| 34 |
-
"Upload an image to classify its architectural style. "
|
| 35 |
-
"Categories: Baroque, Brutalist, Futuristic, Gothic, Islamic, Modern, "
|
| 36 |
-
"Neoclassical, Renaissance, Traditional Japanese, Vernacular."
|
| 37 |
-
),
|
| 38 |
examples=[
|
| 39 |
'examples/1.jpg',
|
| 40 |
'examples/2.jpg',
|
| 41 |
'examples/3.jpg',
|
| 42 |
'examples/4.jpg',
|
| 43 |
]
|
| 44 |
-
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
-
|
| 48 |
-
intf.launch(share=True)
|
|
|
|
| 1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: load.ipynb.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# %% auto 0
|
| 4 |
+
__all__ = ['learn', 'intf']
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# %% load.ipynb 1
|
| 7 |
+
import pickle # or import joblib
|
| 8 |
+
from fastai.vision.all import *
|
| 9 |
+
import gradio as gr
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# %% load.ipynb 3
|
| 12 |
+
learn = load_learner('models/archclassifier_v2.pkl')
|
| 13 |
|
| 14 |
+
# %% load.ipynb 8
|
| 15 |
+
# examples = ['sunny.jpg','rainy.jpg']
|
|
|
|
|
|
|
| 16 |
|
|
|
|
| 17 |
intf = gr.Interface(
|
| 18 |
fn=classify_image,
|
| 19 |
+
inputs=gr.Image(),
|
| 20 |
+
outputs=gr.Label(num_top_classes=3), # show top 3 predictions visually
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
examples=[
|
| 22 |
'examples/1.jpg',
|
| 23 |
'examples/2.jpg',
|
| 24 |
'examples/3.jpg',
|
| 25 |
'examples/4.jpg',
|
| 26 |
]
|
| 27 |
+
title="Arch Style Classifier 🌦️",
|
| 28 |
+
description="Upload or choose an image to classify the Arch Style."
|
| 29 |
)
|
| 30 |
|
| 31 |
+
intf.launch()
|
|
|
models/archclassifier_v2.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cf2b92338cece826190008b00d10831361a935a3157b8f8ec5095877fb189d52
|
| 3 |
+
size 88274683
|
model.pkl → models/model.pkl
RENAMED
|
File without changes
|