Spaces:
Sleeping
Sleeping
UCLV\beel
commited on
Commit
·
5b86ab3
1
Parent(s):
82d1477
revert back to image input field
Browse files
app.py
CHANGED
@@ -6,10 +6,6 @@ import gradio as gr
|
|
6 |
# %% ModelTester.ipynb 3
|
7 |
from fastai.metrics import Metric
|
8 |
|
9 |
-
from PIL import Image
|
10 |
-
import io
|
11 |
-
import base64
|
12 |
-
|
13 |
class OrdinalRegressionMetric(Metric):
|
14 |
def __init__(self):
|
15 |
super().__init__()
|
@@ -56,22 +52,11 @@ learn = load_learner("textfile3-2.pk1")
|
|
56 |
# %% ModelTester.ipynb 6
|
57 |
categories = ("1","1-2","2","2-3","3","3-4","4","4-5","5")
|
58 |
|
59 |
-
def classify_image(
|
60 |
-
# Check if the input is a NamedString object (file uploaded through Gradio)
|
61 |
-
if isinstance(file, gr.inputs.NamedString):
|
62 |
-
# Decode the base64 string to get the image data
|
63 |
-
img_data = base64.b64decode(file)
|
64 |
-
else:
|
65 |
-
# The input is a bytes-like object (image sent via API)
|
66 |
-
img_data = file
|
67 |
-
|
68 |
-
# Convert the bytes-like object to an Image object
|
69 |
-
img = Image.open(io.BytesIO(img_data))
|
70 |
-
|
71 |
pred, idx, probs = learn.predict(img)
|
72 |
return dict(zip(categories, map(float, probs)))
|
73 |
|
74 |
-
|
75 |
-
intf.launch(inline=False)
|
76 |
-
|
77 |
|
|
|
|
|
|
6 |
# %% ModelTester.ipynb 3
|
7 |
from fastai.metrics import Metric
|
8 |
|
|
|
|
|
|
|
|
|
9 |
class OrdinalRegressionMetric(Metric):
|
10 |
def __init__(self):
|
11 |
super().__init__()
|
|
|
52 |
# %% ModelTester.ipynb 6
|
53 |
categories = ("1","1-2","2","2-3","3","3-4","4","4-5","5")
|
54 |
|
55 |
+
def classify_image(img):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
pred, idx, probs = learn.predict(img)
|
57 |
return dict(zip(categories, map(float, probs)))
|
58 |
|
59 |
+
# %% ModelTester.ipynb 8
|
|
|
|
|
60 |
|
61 |
+
intf = gr.Interface(fn=classify_image, inputs='image', outputs='label')
|
62 |
+
intf.launch(inline=False)
|