Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -146,9 +146,11 @@ def get_roles_from_salesforce():
|
|
146 |
security_token=os.getenv('SF_SECURITY_TOKEN'),
|
147 |
domain=os.getenv('SF_DOMAIN', 'login')
|
148 |
)
|
149 |
-
result = sf.query("SELECT Role__c FROM Supervisor__c WHERE Role__c != NULL")
|
150 |
-
|
|
|
151 |
except Exception as e:
|
|
|
152 |
return []
|
153 |
|
154 |
def get_supervisor_name_by_role(role):
|
@@ -162,6 +164,7 @@ def get_supervisor_name_by_role(role):
|
|
162 |
result = sf.query(f"SELECT Name FROM Supervisor__c WHERE Role__c = '{role}'")
|
163 |
return [record['Name'] for record in result['records']]
|
164 |
except Exception as e:
|
|
|
165 |
return []
|
166 |
|
167 |
def get_projects_for_supervisor(supervisor_name):
|
@@ -179,6 +182,7 @@ def get_projects_for_supervisor(supervisor_name):
|
|
179 |
project_result = sf.query(f"SELECT Name FROM Project__c WHERE Supervisor_ID__c = '{supervisor_id}' LIMIT 1")
|
180 |
return project_result['records'][0]['Name'] if project_result['totalSize'] > 0 else ""
|
181 |
except Exception as e:
|
|
|
182 |
return ""
|
183 |
|
184 |
def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
|
@@ -284,11 +288,12 @@ def show_dashboard_html(sup_name, proj_id):
|
|
284 |
|
285 |
# Supervisor Dashboard Tab
|
286 |
def create_interface():
|
|
|
287 |
with gr.Blocks(theme="soft", css=".footer { display: none; }") as demo:
|
288 |
gr.Markdown("## 🧠 AI-Powered Supervisor Assistant")
|
289 |
|
290 |
with gr.Row():
|
291 |
-
role = gr.Dropdown(choices=
|
292 |
supervisor_name = gr.Dropdown(choices=[], label="Supervisor Name")
|
293 |
project_id = gr.Textbox(label="Project ID", interactive=False)
|
294 |
|
@@ -322,15 +327,6 @@ def create_interface():
|
|
322 |
|
323 |
refresh.click(fn=lambda: gr.update(choices=get_roles_from_salesforce()), outputs=role)
|
324 |
|
325 |
-
# Supervisor Dashboard Tab
|
326 |
-
with gr.Tab("📊 Supervisor Dashboard"):
|
327 |
-
dash_supervisor = gr.Textbox(label="Supervisor Name", placeholder="e.g., SUP-056")
|
328 |
-
dash_project = gr.Textbox(label="Project ID", placeholder="e.g., PROJ-078")
|
329 |
-
load_dash = gr.Button("📥 Load Dashboard")
|
330 |
-
dash_output = gr.HTML()
|
331 |
-
|
332 |
-
load_dash.click(fn=show_dashboard_html, inputs=[dash_supervisor, dash_project], outputs=dash_output)
|
333 |
-
|
334 |
return demo
|
335 |
|
336 |
if __name__ == "__main__":
|
|
|
146 |
security_token=os.getenv('SF_SECURITY_TOKEN'),
|
147 |
domain=os.getenv('SF_DOMAIN', 'login')
|
148 |
)
|
149 |
+
result = sf.query("SELECT DISTINCT Role__c FROM Supervisor__c WHERE Role__c != NULL")
|
150 |
+
roles = [record['Role__c'] for record in result['records']]
|
151 |
+
return roles
|
152 |
except Exception as e:
|
153 |
+
print(f"Error fetching roles: {e}")
|
154 |
return []
|
155 |
|
156 |
def get_supervisor_name_by_role(role):
|
|
|
164 |
result = sf.query(f"SELECT Name FROM Supervisor__c WHERE Role__c = '{role}'")
|
165 |
return [record['Name'] for record in result['records']]
|
166 |
except Exception as e:
|
167 |
+
print(f"Error fetching supervisor names: {e}")
|
168 |
return []
|
169 |
|
170 |
def get_projects_for_supervisor(supervisor_name):
|
|
|
182 |
project_result = sf.query(f"SELECT Name FROM Project__c WHERE Supervisor_ID__c = '{supervisor_id}' LIMIT 1")
|
183 |
return project_result['records'][0]['Name'] if project_result['totalSize'] > 0 else ""
|
184 |
except Exception as e:
|
185 |
+
print(f"Error fetching projects: {e}")
|
186 |
return ""
|
187 |
|
188 |
def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
|
|
|
288 |
|
289 |
# Supervisor Dashboard Tab
|
290 |
def create_interface():
|
291 |
+
roles = get_roles_from_salesforce() # Fetch roles from Salesforce
|
292 |
with gr.Blocks(theme="soft", css=".footer { display: none; }") as demo:
|
293 |
gr.Markdown("## 🧠 AI-Powered Supervisor Assistant")
|
294 |
|
295 |
with gr.Row():
|
296 |
+
role = gr.Dropdown(choices=roles, label="Role")
|
297 |
supervisor_name = gr.Dropdown(choices=[], label="Supervisor Name")
|
298 |
project_id = gr.Textbox(label="Project ID", interactive=False)
|
299 |
|
|
|
327 |
|
328 |
refresh.click(fn=lambda: gr.update(choices=get_roles_from_salesforce()), outputs=role)
|
329 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
return demo
|
331 |
|
332 |
if __name__ == "__main__":
|