Spaces:
Sleeping
Sleeping
Update app.py (#1)
Browse files- Update app.py (1d582c9619f293eb2f5871136392b0756404e0bd)
Co-authored-by: K Neeraj Kalyan <[email protected]>
app.py
CHANGED
@@ -88,7 +88,7 @@ def save_report_as_pdf(role, supervisor_name, project_id, checklist, suggestions
|
|
88 |
|
89 |
temp_pdf_path = "/tmp/" + os.path.basename(file_path)
|
90 |
shutil.copy(file_path, temp_pdf_path)
|
91 |
-
return temp_pdf_path,filename
|
92 |
|
93 |
def upload_pdf_to_salesforce_and_update_link(supervisor_name, project_id, pdf_path, pdf_name, checklist, suggestions):
|
94 |
try:
|
@@ -99,51 +99,34 @@ def upload_pdf_to_salesforce_and_update_link(supervisor_name, project_id, pdf_pa
|
|
99 |
domain=os.getenv('SF_DOMAIN', 'login')
|
100 |
)
|
101 |
|
102 |
-
# Read and encode the file as base64
|
103 |
with open(pdf_path, "rb") as f:
|
104 |
encoded = base64.b64encode(f.read()).decode()
|
105 |
|
106 |
-
# Create ContentVersion record to upload the PDF to Salesforce
|
107 |
content = sf.ContentVersion.create({
|
108 |
'Title': pdf_name,
|
109 |
'PathOnClient': pdf_name,
|
110 |
'VersionData': encoded
|
111 |
})
|
112 |
|
113 |
-
# Get the ContentDocumentId for the uploaded PDF
|
114 |
content_id = content['id']
|
115 |
download_url = f"https://{sf.sf_instance}/sfc/servlet.shepherd/version/download/{content_id}"
|
116 |
|
117 |
-
|
118 |
-
query = sf.query(f"""
|
119 |
-
SELECT Id FROM Supervisor__c
|
120 |
-
WHERE Name = '{supervisor_name}'
|
121 |
-
LIMIT 1
|
122 |
-
""")
|
123 |
-
|
124 |
-
# Ensure that the Supervisor is found
|
125 |
if query['totalSize'] == 0:
|
126 |
print("⚠️ Supervisor not found!")
|
127 |
return ""
|
128 |
|
129 |
supervisor_id = query['records'][0]['Id']
|
130 |
|
131 |
-
|
132 |
-
project_query = sf.query(f"""
|
133 |
-
SELECT Id FROM Project__c WHERE Name = '{project_id}'
|
134 |
-
LIMIT 1
|
135 |
-
""")
|
136 |
-
|
137 |
-
# Ensure that the Project ID is found
|
138 |
if project_query['totalSize'] == 0:
|
139 |
print(f"⚠️ Project '{project_id}' not found in Salesforce!")
|
140 |
return ""
|
141 |
|
142 |
project_id_sf = project_query['records'][0]['Id']
|
143 |
|
144 |
-
# Create a new Supervisor_AI_Coaching__c record
|
145 |
sf.Supervisor_AI_Coaching__c.create({
|
146 |
-
'Project_ID__c': project_id_sf,
|
147 |
'Supervisor_ID__c': supervisor_id,
|
148 |
'Daily_Checklist__c': checklist,
|
149 |
'Suggested_Tips__c': suggestions,
|
@@ -254,7 +237,7 @@ def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
|
|
254 |
|
255 |
def create_interface():
|
256 |
roles = get_roles_from_salesforce()
|
257 |
-
with gr.Blocks(theme="soft") as demo:
|
258 |
gr.Markdown("## 🧠 AI-Powered Supervisor Assistant")
|
259 |
|
260 |
with gr.Row():
|
@@ -303,4 +286,3 @@ def create_interface():
|
|
303 |
if __name__ == "__main__":
|
304 |
app = create_interface()
|
305 |
app.launch()
|
306 |
-
|
|
|
88 |
|
89 |
temp_pdf_path = "/tmp/" + os.path.basename(file_path)
|
90 |
shutil.copy(file_path, temp_pdf_path)
|
91 |
+
return temp_pdf_path, filename
|
92 |
|
93 |
def upload_pdf_to_salesforce_and_update_link(supervisor_name, project_id, pdf_path, pdf_name, checklist, suggestions):
|
94 |
try:
|
|
|
99 |
domain=os.getenv('SF_DOMAIN', 'login')
|
100 |
)
|
101 |
|
|
|
102 |
with open(pdf_path, "rb") as f:
|
103 |
encoded = base64.b64encode(f.read()).decode()
|
104 |
|
|
|
105 |
content = sf.ContentVersion.create({
|
106 |
'Title': pdf_name,
|
107 |
'PathOnClient': pdf_name,
|
108 |
'VersionData': encoded
|
109 |
})
|
110 |
|
|
|
111 |
content_id = content['id']
|
112 |
download_url = f"https://{sf.sf_instance}/sfc/servlet.shepherd/version/download/{content_id}"
|
113 |
|
114 |
+
query = sf.query(f"SELECT Id FROM Supervisor__c WHERE Name = '{supervisor_name}' LIMIT 1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
if query['totalSize'] == 0:
|
116 |
print("⚠️ Supervisor not found!")
|
117 |
return ""
|
118 |
|
119 |
supervisor_id = query['records'][0]['Id']
|
120 |
|
121 |
+
project_query = sf.query(f"SELECT Id FROM Project__c WHERE Name = '{project_id}' LIMIT 1")
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
if project_query['totalSize'] == 0:
|
123 |
print(f"⚠️ Project '{project_id}' not found in Salesforce!")
|
124 |
return ""
|
125 |
|
126 |
project_id_sf = project_query['records'][0]['Id']
|
127 |
|
|
|
128 |
sf.Supervisor_AI_Coaching__c.create({
|
129 |
+
'Project_ID__c': project_id_sf,
|
130 |
'Supervisor_ID__c': supervisor_id,
|
131 |
'Daily_Checklist__c': checklist,
|
132 |
'Suggested_Tips__c': suggestions,
|
|
|
237 |
|
238 |
def create_interface():
|
239 |
roles = get_roles_from_salesforce()
|
240 |
+
with gr.Blocks(theme="soft", css=".svelte-1ipelgc {display: none !important;}") as demo:
|
241 |
gr.Markdown("## 🧠 AI-Powered Supervisor Assistant")
|
242 |
|
243 |
with gr.Row():
|
|
|
286 |
if __name__ == "__main__":
|
287 |
app = create_interface()
|
288 |
app.launch()
|
|