Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,17 +77,38 @@ def predict_from_json(payload, x_api_key: str = ""):
|
|
| 77 |
|
| 78 |
return predict_core(payload)
|
| 79 |
|
| 80 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
iface = gr.Interface(
|
| 82 |
fn=predict_from_json,
|
| 83 |
-
inputs=gr.JSON(label="ratios JSON (dict of feature -> value)"),
|
| 84 |
outputs="json",
|
| 85 |
title="Static Fingerprint Model API",
|
| 86 |
description=(
|
| 87 |
-
"
|
|
|
|
| 88 |
"Server normalises using saved means/stds and returns probabilities + state."
|
| 89 |
)
|
| 90 |
)
|
|
|
|
| 91 |
|
| 92 |
if __name__ == "__main__":
|
| 93 |
iface.launch()
|
|
|
|
| 77 |
|
| 78 |
return predict_core(payload)
|
| 79 |
|
| 80 |
+
# ---------- AUTOLOAD DEMO INPUT ----------
|
| 81 |
+
DEMO_PATH = "example_input.json" # <-- name of your uploaded file
|
| 82 |
+
demo_data = {}
|
| 83 |
+
|
| 84 |
+
if os.path.exists(DEMO_PATH):
|
| 85 |
+
try:
|
| 86 |
+
with open(DEMO_PATH, "r") as f:
|
| 87 |
+
demo_data = json.load(f)
|
| 88 |
+
# Unwrap if the file uses {"data":[{...}]} format
|
| 89 |
+
if isinstance(demo_data, dict) and "data" in demo_data and isinstance(demo_data["data"], list):
|
| 90 |
+
demo_data = demo_data["data"][0]
|
| 91 |
+
except Exception as e:
|
| 92 |
+
print("⚠️ Could not load demo input:", e)
|
| 93 |
+
else:
|
| 94 |
+
# Default zeros if file not found
|
| 95 |
+
demo_data = {f: 0.0 for f in FEATURES}
|
| 96 |
+
# -----------------------------------------
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
# ---------- DEFINE GRADIO INTERFACE ----------
|
| 100 |
iface = gr.Interface(
|
| 101 |
fn=predict_from_json,
|
| 102 |
+
inputs=gr.JSON(label="ratios JSON (dict of feature -> value)", value=demo_data),
|
| 103 |
outputs="json",
|
| 104 |
title="Static Fingerprint Model API",
|
| 105 |
description=(
|
| 106 |
+
"Enter or edit the ratios JSON below. "
|
| 107 |
+
"Click Submit to predict, or call this Space via POST /run/predict. "
|
| 108 |
"Server normalises using saved means/stds and returns probabilities + state."
|
| 109 |
)
|
| 110 |
)
|
| 111 |
+
# ---------------------------------------------
|
| 112 |
|
| 113 |
if __name__ == "__main__":
|
| 114 |
iface.launch()
|