Sanjayraju30 commited on
Commit
38339ed
Β·
verified Β·
1 Parent(s): b72564a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -69
app.py CHANGED
@@ -1,88 +1,36 @@
1
  # app.py
2
 
3
  import streamlit as st
4
- import pandas as pd
5
- import requests
6
- from simple_salesforce import Salesforce
7
 
8
- # ----------------------
9
- # CONFIG: Salesforce + Hugging Face
10
- # ----------------------
11
  SF_USERNAME = "[email protected]"
12
  SF_PASSWORD = "Vedavathi@04"
13
  SF_SECURITY_TOKEN = "jqe4His8AcuFJucZz5NBHfGU"
14
- SF_DOMAIN = "login" # or "test" for sandbox
15
-
16
- HF_API_URL = "https://api-inference.huggingface.co/models/your-username/your-model"
17
  HF_API_TOKEN = "hf_your_token"
18
 
19
- # ----------------------
20
- # Connect to Salesforce
21
- # ----------------------
22
- @st.cache_resource
23
- def connect_salesforce():
24
- sf = Salesforce(username=SF_USERNAME, password=SF_PASSWORD, security_token=SF_SECURITY_TOKEN, domain=SF_DOMAIN)
25
- return sf
26
-
27
- # ----------------------
28
- # Get Pole Data from Salesforce
29
- # ----------------------
30
- def fetch_pole_data(sf):
31
- query = """
32
- SELECT Name, Solar_Gen__c, Wind_Gen__c, Tilt__c, Vibration__c, Camera_Status__c
33
- FROM Smart_Pole__c
34
- LIMIT 50
35
- """
36
- records = sf.query_all(query)['records']
37
- df = pd.DataFrame(records).drop(columns=['attributes'])
38
- return df
39
-
40
- # ----------------------
41
- # Send Data to Hugging Face Model
42
- # ----------------------
43
- def get_hf_predictions(df):
44
- headers = {"Authorization": f"Bearer {HF_API_TOKEN}"}
45
- preds = []
46
-
47
- for _, row in df.iterrows():
48
- input_data = {
49
- "solar": row["Solar_Gen__c"],
50
- "wind": row["Wind_Gen__c"],
51
- "tilt": row["Tilt__c"],
52
- "vibration": row["Vibration__c"],
53
- "camera": row["Camera_Status__c"]
54
- }
55
- response = requests.post(HF_API_URL, headers=headers, json={"inputs": input_data})
56
- if response.status_code == 200:
57
- result = response.json()
58
- preds.append(result[0]['label'] if isinstance(result, list) else result.get("label", "Unknown"))
59
- else:
60
- preds.append("Error")
61
-
62
- df["Alert_Prediction"] = preds
63
- return df
64
-
65
- # ----------------------
66
- # Streamlit App
67
- # ----------------------
68
  def main():
69
- st.title("πŸ”Œ Salesforce ↔ Hugging Face Smart Pole Integration")
70
 
71
- sf = connect_salesforce()
72
  df = fetch_pole_data(sf)
73
 
74
  if not df.empty:
75
- st.subheader("πŸ“₯ Raw Pole Data from Salesforce")
76
- st.dataframe(df)
77
-
78
- st.subheader("πŸ€– Running Hugging Face AI Predictions...")
79
- df = get_hf_predictions(df)
80
-
81
- st.success("βœ… Predictions Complete")
82
- st.subheader("πŸ“Š Results with Predictions")
83
- st.dataframe(df)
84
  else:
85
  st.warning("No data fetched from Salesforce.")
86
 
 
 
 
 
 
87
 
88
 
 
1
  # app.py
2
 
3
  import streamlit as st
4
+ from modules.salesforce_connector import connect_salesforce, fetch_pole_data
5
+ from modules.huggingface_inference import predict_alerts
6
+ from modules.data_view import show_raw_data, show_predictions, show_status
7
 
8
+ # ---------------------- CONFIG ----------------------
 
 
9
  SF_USERNAME = "[email protected]"
10
  SF_PASSWORD = "Vedavathi@04"
11
  SF_SECURITY_TOKEN = "jqe4His8AcuFJucZz5NBHfGU"
12
+ HF_API_URL = "https://api-inference.huggingface.co/models/your-model"
 
 
13
  HF_API_TOKEN = "hf_your_token"
14
 
15
+ # ---------------------- MAIN ----------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def main():
17
+ st.title("πŸ“‘ Hugging Face + Salesforce Smart Pole Monitor")
18
 
19
+ sf = connect_salesforce(SF_USERNAME, SF_PASSWORD, SF_SECURITY_TOKEN)
20
  df = fetch_pole_data(sf)
21
 
22
  if not df.empty:
23
+ show_raw_data(df)
24
+ df = predict_alerts(df, HF_API_URL, HF_API_TOKEN)
25
+ show_status()
26
+ show_predictions(df)
 
 
 
 
 
27
  else:
28
  st.warning("No data fetched from Salesforce.")
29
 
30
+ if __name__ == "__main__":
31
+ main()
32
+
33
+
34
+
35
 
36