Aljnk commited on
Commit
36f6e50
·
1 Parent(s): d22624c

Minor updates

Browse files
Files changed (1) hide show
  1. app.py +2 -28
app.py CHANGED
@@ -1,44 +1,18 @@
1
  import pathlib
2
  import platform
3
  if platform.system()=='Linux': pathlib.WindowsPath=pathlib.PosixPath
 
4
  import dill
5
  import gradio as gr
6
 
7
  with open('model_dill.pkl','rb') as f: learn=dill.load(f)
8
 
9
- # Try to find classes in different places
10
- print("=== SEARCHING FOR CLASSES ===")
11
- try:
12
- labels=learn.dls.train.dataset.items
13
- print(f"Found in train.dataset.items: {labels}")
14
- except Exception as e:
15
- print(f"train.dataset.items failed: {e}")
16
- try:
17
- labels=learn.dls.dataset.items
18
- print(f"Found in dataset.items: {labels}")
19
- except Exception as e:
20
- print(f"dataset.items failed: {e}")
21
- # Try prediction to see what class names it returns
22
- from fastai.vision.all import PILImage
23
- try:
24
- # Create dummy image to test prediction
25
- dummy_img=PILImage.create('cat.jpg') # if file exists
26
- pred,pred_idx,probs=learn.predict(dummy_img)
27
- print(f"Prediction result - pred: {pred}, type: {type(pred)}")
28
- print(f"pred_idx: {pred_idx}, probs: {probs}")
29
- # Extract class name from prediction
30
- labels=[str(pred),'Other'] # temporary
31
- except Exception as e2:
32
- print(f"Test prediction failed: {e2}")
33
- labels=['Dog','Cat']
34
-
35
- print(f"Final labels: {labels}")
36
 
37
  def predict(img):
38
  from fastai.vision.all import PILImage
39
  img=PILImage.create(img)
40
  pred,pred_idx,probs=learn.predict(img)
41
- print(f"Prediction: {pred}, Probabilities: {probs}")
42
  return {labels[i]:float(probs[i]) for i in range(len(labels))}
43
 
44
  gr.Interface(
 
1
  import pathlib
2
  import platform
3
  if platform.system()=='Linux': pathlib.WindowsPath=pathlib.PosixPath
4
+
5
  import dill
6
  import gradio as gr
7
 
8
  with open('model_dill.pkl','rb') as f: learn=dill.load(f)
9
 
10
+ labels=['Dog','Cat']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  def predict(img):
13
  from fastai.vision.all import PILImage
14
  img=PILImage.create(img)
15
  pred,pred_idx,probs=learn.predict(img)
 
16
  return {labels[i]:float(probs[i]) for i in range(len(labels))}
17
 
18
  gr.Interface(