Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -121,9 +121,55 @@ def save_report_as_pdf(role, supervisor_name, project_id, checklist, suggestions
|
|
121 |
shutil.copy(file_path, temp_pdf_path)
|
122 |
return temp_pdf_path, filename
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
# Gradio interface
|
125 |
def create_interface():
|
126 |
-
roles =
|
127 |
with gr.Blocks(theme="soft", css=".footer { display: none; }") as demo:
|
128 |
gr.Markdown("## 🧠 AI-Powered Supervisor Assistant")
|
129 |
|
|
|
121 |
shutil.copy(file_path, temp_pdf_path)
|
122 |
return temp_pdf_path, filename
|
123 |
|
124 |
+
# Function to get roles from Salesforce
|
125 |
+
def get_roles_from_salesforce():
|
126 |
+
try:
|
127 |
+
sf = Salesforce(
|
128 |
+
username=os.getenv('SF_USERNAME'),
|
129 |
+
password=os.getenv('SF_PASSWORD'),
|
130 |
+
security_token=os.getenv('SF_SECURITY_TOKEN'),
|
131 |
+
domain=os.getenv('SF_DOMAIN', 'login')
|
132 |
+
)
|
133 |
+
result = sf.query("SELECT Role__c FROM Supervisor__c WHERE Role__c != NULL")
|
134 |
+
return list(set(record['Role__c'] for record in result['records']))
|
135 |
+
except Exception as e:
|
136 |
+
return []
|
137 |
+
|
138 |
+
# Function to get supervisor names based on role
|
139 |
+
def get_supervisor_name_by_role(role):
|
140 |
+
try:
|
141 |
+
sf = Salesforce(
|
142 |
+
username=os.getenv('SF_USERNAME'),
|
143 |
+
password=os.getenv('SF_PASSWORD'),
|
144 |
+
security_token=os.getenv('SF_SECURITY_TOKEN'),
|
145 |
+
domain=os.getenv('SF_DOMAIN', 'login')
|
146 |
+
)
|
147 |
+
result = sf.query(f"SELECT Name FROM Supervisor__c WHERE Role__c = '{role}'")
|
148 |
+
return [record['Name'] for record in result['records']]
|
149 |
+
except Exception as e:
|
150 |
+
return []
|
151 |
+
|
152 |
+
# Function to get the project name for a supervisor
|
153 |
+
def get_projects_for_supervisor(supervisor_name):
|
154 |
+
try:
|
155 |
+
sf = Salesforce(
|
156 |
+
username=os.getenv('SF_USERNAME'),
|
157 |
+
password=os.getenv('SF_PASSWORD'),
|
158 |
+
security_token=os.getenv('SF_SECURITY_TOKEN'),
|
159 |
+
domain=os.getenv('SF_DOMAIN', 'login')
|
160 |
+
)
|
161 |
+
result = sf.query(f"SELECT Id FROM Supervisor__c WHERE Name = '{supervisor_name}' LIMIT 1")
|
162 |
+
if result['totalSize'] == 0:
|
163 |
+
return ""
|
164 |
+
supervisor_id = result['records'][0]['Id']
|
165 |
+
project_result = sf.query(f"SELECT Name FROM Project__c WHERE Supervisor_ID__c = '{supervisor_id}' LIMIT 1")
|
166 |
+
return project_result['records'][0]['Name'] if project_result['totalSize'] > 0 else ""
|
167 |
+
except Exception as e:
|
168 |
+
return ""
|
169 |
+
|
170 |
# Gradio interface
|
171 |
def create_interface():
|
172 |
+
roles = get_roles_from_salesforce() # Get roles from Salesforce dynamically
|
173 |
with gr.Blocks(theme="soft", css=".footer { display: none; }") as demo:
|
174 |
gr.Markdown("## 🧠 AI-Powered Supervisor Assistant")
|
175 |
|