Sabse commited on
Commit
1592902
·
1 Parent(s): 43f0fd5

Add application file

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -1,29 +1,27 @@
 
1
  import gradio as gr
2
- import subprocess
 
3
 
4
  # Install fastai
5
  subprocess.run(["pip", "install", "fastai"])
6
 
7
-
8
- from fastai.vision.all import *
9
-
10
- im =PILImage.create('Sphynx.jpg')
11
- im.thumbnail((192,192))
12
- im
13
- # Construct the absolute path to the file
14
  # Get the absolute path to the current script's directory
15
- from fastai.learner import load_learner
16
-
17
- file_path = os.path.join('/Users', 'scaspary', 'Desktop', 'fastai', 'large', 'sphynx.pkl')
18
- learn= load_learner(file_path)
19
 
 
 
20
 
21
  categories = ('cat', 'sphinx cat')
 
22
  def classify_image(im):
23
- pred,idx, probs = learn.predict(im)
24
- return dict(zip(categories, map(float,probs)))
25
 
26
- # Define the input component
27
  image = "image"
28
 
29
  # Define the output component
@@ -31,4 +29,4 @@ label_output = "label"
31
 
32
  # Create the Gradio interface
33
  intf = gr.Interface(fn=classify_image, inputs=image, outputs=label_output, examples=["Sphynx.jpg", "cat.jpg"])
34
- intf.launch(share=False)
 
1
+ import os
2
  import gradio as gr
3
+ from fastai.learner import load_learner
4
+ from fastai.vision.all import *
5
 
6
  # Install fastai
7
  subprocess.run(["pip", "install", "fastai"])
8
 
9
+ # Construct the absolute path to the large data file
 
 
 
 
 
 
10
  # Get the absolute path to the current script's directory
11
+ current_directory = os.path.abspath(os.path.dirname(__file__))
12
+ parent_directory = os.path.abspath(os.path.join(current_directory, os.pardir))
13
+ file_path = os.path.join(parent_directory, 'large', 'sphynx.pkl')
 
14
 
15
+ # Load the learner using the absolute file path
16
+ learn = load_learner(file_path)
17
 
18
  categories = ('cat', 'sphinx cat')
19
+
20
  def classify_image(im):
21
+ pred, idx, probs = learn.predict(im)
22
+ return dict(zip(categories, map(float, probs)))
23
 
24
+ # Define the input component
25
  image = "image"
26
 
27
  # Define the output component
 
29
 
30
  # Create the Gradio interface
31
  intf = gr.Interface(fn=classify_image, inputs=image, outputs=label_output, examples=["Sphynx.jpg", "cat.jpg"])
32
+ intf.launch(share=False)