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