import json import requests import pandas as pd # Create a tiny mock dataframe matching your query's feature layout # Ensure the columns precisely match the ones your model trained on! mock_batch = pd.DataFrame([{ 'person_id': 'usr_123456', 'session_id': 'sess_normal_001', 'session_start': '2026-06-08 19:18:42', 'session_start_sin': -0.9659, 'session_start_cos': 0.2588, 'session_end': '2026-06-08 19:29:58', 'session_end_sin': -0.8746, 'session_end_cos': 0.4848, 'event_count': 26, 'unique_event_types': 9, 'screens_visited': 11, 'duration_seconds': 676, 'events_per_minute': 5.15, 'inter_event_time_mean_seconds': 11.7, 'inter_event_time_median_seconds': 8.4, 'inter_event_time_std_seconds': 10.6, 'max_inter_event_gap_seconds': 74.2, 'session_start_hour': 19, 'session_day_of_week': 0, 'session_day_of_week_sin': 0.0, 'session_day_of_week_cos': 1.0, 'distinct_hours_active': 1 }]) # Format into MLflow's split layout payload = {"dataframe_split": mock_batch.to_dict(orient="split")} # Hit the local model server response = requests.post( "http://127.0.0.1:5001/invocations", data=json.dumps(payload), headers={"Content-Type": "application/json"} ) print("Server Response Status:", response.status_code) print("Predictions (1=Clean, -1=Anomaly):", response.json())