Aljnk
commited on
Commit
·
593ed83
1
Parent(s):
6e5d634
Minor updates
Browse files- app.py +9 -20
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -3,31 +3,20 @@ import platform
|
|
| 3 |
if platform.system()=='Linux':
|
| 4 |
pathlib.WindowsPath=pathlib.PosixPath
|
| 5 |
|
| 6 |
-
|
| 7 |
import gradio as gr
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
learn=load_learner('model_dill.pkl')
|
| 15 |
-
labels=learn.dls.vocab
|
| 16 |
-
logging.info(f"Model loaded. Classes: {labels}")
|
| 17 |
-
except Exception as e:
|
| 18 |
-
logging.error(f"Model loading failed: {e}")
|
| 19 |
-
raise
|
| 20 |
|
| 21 |
def predict(img):
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
logging.info(f"Prediction: {pred}, Probs: {probs}")
|
| 27 |
-
return result
|
| 28 |
-
except Exception as e:
|
| 29 |
-
logging.error(f"Prediction failed: {e}")
|
| 30 |
-
return {"Error":"Prediction failed"}
|
| 31 |
|
| 32 |
gr.Interface(
|
| 33 |
fn=predict,
|
|
|
|
| 3 |
if platform.system()=='Linux':
|
| 4 |
pathlib.WindowsPath=pathlib.PosixPath
|
| 5 |
|
| 6 |
+
import dill
|
| 7 |
import gradio as gr
|
| 8 |
|
| 9 |
+
# Load with dill instead of load_learner
|
| 10 |
+
with open('model_dill.pkl','rb') as f:
|
| 11 |
+
learn=dill.load(f)
|
| 12 |
|
| 13 |
+
labels=learn.dls.vocab
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def predict(img):
|
| 16 |
+
from fastai.vision.all import PILImage
|
| 17 |
+
img=PILImage.create(img)
|
| 18 |
+
pred,pred_idx,probs=learn.predict(img)
|
| 19 |
+
return {labels[i]:float(probs[i]) for i in range(len(labels))}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
gr.Interface(
|
| 22 |
fn=predict,
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
fastai<2.8.0
|
| 2 |
-
fasttransform
|
|
|
|
|
|
| 1 |
fastai<2.8.0
|
| 2 |
+
fasttransform
|
| 3 |
+
dill
|