grover101 commited on
Commit
8622689
·
verified ·
1 Parent(s): ed171e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -34
app.py CHANGED
@@ -1,42 +1,27 @@
1
- from fastai.vision.all import *
2
- import gradio as gr
3
-
4
  import pathlib
5
  plt = platform.system()
6
  if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
7
 
8
- def old_or_not(x):
9
- return x[0].isupper()
 
10
 
11
- # Assuming 'model.pkl' is in the same directory as this script
12
- learn = load_learner('model.pkl') # Replace with the appropriate path if needed
13
 
14
- categories = ['New_car', 'Old_car']
 
 
 
 
15
 
16
  def classify_image(img):
17
- pred, idx, probs = learn.predict(img)
18
- return dict(zip(categories, map(float, probs)))
19
-
20
- # Use Image component with correct shape argument
21
- image = gr.inputs.Image(shape=(192, 192))
22
- label = gr.outputs.Label()
23
-
24
- examples = [
25
- 'new_car_2.jpg',
26
- 'new_car_4.jpg',
27
- 'old_car_7.jpg',
28
- 'old_car_12.jpg',
29
- ]
30
-
31
- # Improved interface creation for clarity
32
- interface = gr.Interface(
33
- fn=classify_image,
34
- inputs=image,
35
- outputs=label,
36
- examples=examples,
37
- title="Image Classification", # Optional title for the interface
38
- description="Classify an image as 'New_car' or 'Old_car'", # Optional description
39
- )
40
-
41
- # Launch the interface
42
- interface.launch(inline=False)
 
 
 
 
1
  import pathlib
2
  plt = platform.system()
3
  if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
4
 
5
+ from fastai.vision.all import*
6
+ import gradio as gr
7
+ from gradio import Label
8
 
9
+ def oldornot(x): return x[0].isupper()
 
10
 
11
+ #/export
12
+ learn = load_learner('model.pkl')
13
+
14
+ #/export
15
+ categories = ['Old_Car','New_car']
16
 
17
  def classify_image(img):
18
+ pred,idx,probs = learn.predict(img)
19
+ return dict(zip(categories,map(float,probs)))
20
+
21
+ examples = ['new_car_2.jpg','new_car_4.jpg','old_car_7.jpg','old_car_12.jpg']
22
+
23
+
24
+ intf = gr.Interface(fn=classify_image, inputs=gr.Image(), outputs=Label(), examples=examples)
25
+
26
+
27
+ intf.launch(inline=False)