Update app.py
Browse files
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 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
learn = load_learner('model.pkl') # Replace with the appropriate path if needed
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
def classify_image(img):
|
| 17 |
-
pred,
|
| 18 |
-
return dict(zip(categories,
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|