tyler cross commited on
Commit
b430868
1 Parent(s): 651c29b

Added corrected pathing

Browse files
__pycache__/app.cpython-311.pyc CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
 
app.py CHANGED
@@ -1,11 +1,23 @@
1
  import gradio as gr
2
  from fastai.vision.all import load_learner
3
  from PIL import Image
 
 
4
  import pathlib
5
- temp = pathlib.PosixPath
6
- pathlib.PosixPath = pathlib.WindowsPath
7
 
8
- model = load_learner('export.pkl')
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  def classify_image(img):
11
  """Classifies an image according to three categories: dung beetle, elephant, or dolphin.
@@ -19,9 +31,9 @@ def classify_image(img):
19
  # Convert the image to a format the model expects
20
  img = Image.fromarray(img.astype('uint8'), 'RGB')
21
  # Make a prediction
22
- probs = model.predict(img)
23
  # Return the result
24
- return {model.dls.vocab[i]: float(probs[i]) for i in range(len(model.dls.vocab))}
25
 
26
  demo = gr.Interface(
27
  title = "A dung beetle / dolphin / elephant image classifier",
 
1
  import gradio as gr
2
  from fastai.vision.all import load_learner
3
  from PIL import Image
4
+
5
+ from contextlib import contextmanager
6
  import pathlib
 
 
7
 
8
+ @contextmanager
9
+ def set_posix_posix():
10
+ windows_backup = pathlib.WindowsPath
11
+ try:
12
+ pathlib.WindowsPath = pathlib.PosixPath
13
+ yield
14
+ finally:
15
+ pathlib.PosixPath = windows_backup
16
+
17
+ EXPORT_PATH = pathlib.Path("export.pkl")
18
+
19
+ with set_posix_posix():
20
+ learn_inf = load_learner(EXPORT_PATH)
21
 
22
  def classify_image(img):
23
  """Classifies an image according to three categories: dung beetle, elephant, or dolphin.
 
31
  # Convert the image to a format the model expects
32
  img = Image.fromarray(img.astype('uint8'), 'RGB')
33
  # Make a prediction
34
+ pred_class, pred_idx, probs = learn_inf.predict(img)
35
  # Return the result
36
+ return {learn_inf.dls.vocab[i]: float(probs[i]) for i in range(len(learn_inf.dls.vocab))}
37
 
38
  demo = gr.Interface(
39
  title = "A dung beetle / dolphin / elephant image classifier",
flagged/Upload an image of a dung beetle a dolphin or an elephant/5593e3689a8a3612b2ac/5195.webp ADDED
flagged/log.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ "Upload an image of a dung beetle, a dolphin, or an elephant!",output,flag,username,timestamp
2
+ "{""path"":""flagged\\Upload an image of a dung beetle a dolphin or an elephant\\5593e3689a8a3612b2ac\\5195.webp"",""url"":""http://127.0.0.1:7860/file=C:\\Users\\tyler\\AppData\\Local\\Temp\\gradio\\ef6af2aa9c44ce9f8a7439c4dfcb710e94e0af62\\5195.webp"",""size"":95736,""orig_name"":""5195.webp"",""mime_type"":""""}","{""label"":null,""confidences"":null}",,,2023-11-25 12:53:53.130800