Spaces:
Sleeping
Sleeping
File size: 827 Bytes
0c6fc36 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import requests
def predict_alerts(df, hf_url, hf_token):
headers = {"Authorization": f"Bearer {hf_token}"}
preds = []
for _, row in df.iterrows():
input_payload = {
"inputs": {
"solar": row["Solar_Gen__c"],
"wind": row["Wind_Gen__c"],
"tilt": row["Tilt__c"],
"vibration": row["Vibration__c"],
"camera": row["Camera_Status__c"]
}
}
response = requests.post(hf_url, headers=headers, json=input_payload)
if response.status_code == 200:
result = response.json()
preds.append(result[0]['label'] if isinstance(result, list) else result.get("label", "Unknown"))
else:
preds.append("Error")
df["Alert_Prediction"] = preds
return df
|