Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,26 +42,34 @@ PREDICTOR = autogluon.tabular.TabularPredictor.load(
|
|
| 42 |
|
| 43 |
def do_predict(height, width, depth, page_count):
|
| 44 |
try:
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
proba = PREDICTOR.predict_proba(X)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
row0 = proba.iloc[0]
|
| 55 |
-
|
| 56 |
-
|
| 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 |
-
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
EXAMPLES = [
|
|
|
|
| 42 |
|
| 43 |
def do_predict(height, width, depth, page_count):
|
| 44 |
try:
|
| 45 |
+
# Validate inputs
|
| 46 |
+
inputs = validate_and_scale_inputs(height, width, depth, page_count)
|
| 47 |
+
|
| 48 |
+
X = pandas.DataFrame([inputs], columns=FEATURE_COLS)
|
| 49 |
+
|
| 50 |
+
# Get both prediction and probabilities
|
| 51 |
+
prediction = PREDICTOR.predict(X)
|
|
|
|
| 52 |
proba = PREDICTOR.predict_proba(X)
|
| 53 |
+
|
| 54 |
+
print(f"Prediction: {prediction.iloc[0]}")
|
| 55 |
+
print(f"Probabilities: {proba.iloc[0].to_dict()}")
|
| 56 |
+
|
| 57 |
row0 = proba.iloc[0]
|
| 58 |
+
|
| 59 |
+
result = dict(
|
| 60 |
sorted(
|
| 61 |
{str(cls): float(val) for cls, val in row0.items()}.items(),
|
| 62 |
key=lambda kv: kv[1],
|
| 63 |
reverse=True,
|
| 64 |
)
|
| 65 |
)
|
| 66 |
+
|
| 67 |
+
print(f"Final result: {result}")
|
| 68 |
+
return result
|
| 69 |
+
|
| 70 |
except Exception as e:
|
| 71 |
+
print(f"Prediction error: {e}")
|
| 72 |
+
return {"Error": f"Prediction failed: {str(e)}"}
|
| 73 |
|
| 74 |
|
| 75 |
EXAMPLES = [
|