ysakhale commited on
Commit
5f2dffb
·
verified ·
1 Parent(s): 48a16b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
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
- 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 = [
 
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 = [