Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,31 +41,27 @@ PREDICTOR = autogluon.tabular.TabularPredictor.load(
|
|
| 41 |
|
| 42 |
|
| 43 |
def do_predict(height, width, depth, page_count):
|
| 44 |
-
row = {
|
| 45 |
-
"Height": float(height),
|
| 46 |
-
"Width": float(width),
|
| 47 |
-
"Depth": float(depth),
|
| 48 |
-
"Page Count": int(page_count),
|
| 49 |
-
}
|
| 50 |
-
X = pandas.DataFrame([row], columns=FEATURE_COLS)
|
| 51 |
-
|
| 52 |
-
pred_series = PREDICTOR.predict(X)
|
| 53 |
-
raw_pred = pred_series.iloc[0]
|
| 54 |
-
|
| 55 |
try:
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
-
if proba is not None:
|
| 64 |
row0 = proba.iloc[0]
|
| 65 |
-
tmp = {str(cls): float(val) for cls, val in row0.items()}
|
| 66 |
-
proba_dict = dict(sorted(tmp.items(), key=lambda kv: kv[1], reverse=True))
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
|
| 71 |
EXAMPLES = [
|
|
@@ -79,7 +75,7 @@ with gradio.Blocks() as demo:
|
|
| 79 |
gradio.Markdown("Enter book dimensions and page count to predict the genre.")
|
| 80 |
|
| 81 |
with gradio.Row():
|
| 82 |
-
height = gradio.Slider(10, 30, step=0.5, value=20.0, label="Height (cm)")
|
| 83 |
width = gradio.Slider(8, 25, step=0.5, value=13.0, label="Width (cm)")
|
| 84 |
with gradio.Row():
|
| 85 |
depth = gradio.Slider(1, 10, step=0.1, value=3.0, label="Depth (cm)")
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
def do_predict(height, width, depth, page_count):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
try:
|
| 45 |
+
row = {
|
| 46 |
+
"Height": float(height),
|
| 47 |
+
"Width": float(width),
|
| 48 |
+
"Depth": float(depth),
|
| 49 |
+
"Page Count": int(page_count),
|
| 50 |
+
}
|
| 51 |
+
X = pandas.DataFrame([row], columns=FEATURE_COLS)
|
| 52 |
|
| 53 |
+
proba = PREDICTOR.predict_proba(X)
|
|
|
|
| 54 |
row0 = proba.iloc[0]
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
return dict(
|
| 57 |
+
sorted(
|
| 58 |
+
{str(cls): float(val) for cls, val in row0.items()}.items(),
|
| 59 |
+
key=lambda kv: kv[1],
|
| 60 |
+
reverse=True,
|
| 61 |
+
)
|
| 62 |
+
)
|
| 63 |
+
except Exception as e:
|
| 64 |
+
return {"Error": f"Invalid input: {e}"}
|
| 65 |
|
| 66 |
|
| 67 |
EXAMPLES = [
|
|
|
|
| 75 |
gradio.Markdown("Enter book dimensions and page count to predict the genre.")
|
| 76 |
|
| 77 |
with gradio.Row():
|
| 78 |
+
height = gradio.Slider(10, 30, step=0.5, value=20.0, label="Height (cm)", info="Book height in centimeters")
|
| 79 |
width = gradio.Slider(8, 25, step=0.5, value=13.0, label="Width (cm)")
|
| 80 |
with gradio.Row():
|
| 81 |
depth = gradio.Slider(1, 10, step=0.1, value=3.0, label="Depth (cm)")
|