Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import datetime
|
|
8 |
from dotenv import load_dotenv
|
9 |
from fpdf import FPDF
|
10 |
import html
|
|
|
11 |
|
12 |
# Load environment variables
|
13 |
load_dotenv()
|
@@ -185,57 +186,6 @@ def get_projects_for_supervisor(supervisor_name):
|
|
185 |
print(f"⚠️ Error fetching project: {e}")
|
186 |
return ""
|
187 |
|
188 |
-
# Generate Salesforce dashboard URL
|
189 |
-
def generate_salesforce_dashboard_url(supervisor_name, project_id):
|
190 |
-
return f"https://aicoachforsitesupervisors-dev-ed--c.develop.vf.force.com/apex/DashboardPage?supervisorName={supervisor_name}&projectId={project_id}"
|
191 |
-
|
192 |
-
def open_dashboard(role, supervisor_name, project_id):
|
193 |
-
url = generate_salesforce_dashboard_url(supervisor_name, project_id)
|
194 |
-
return f'<a href="{url}" target="_blank">Open Salesforce Dashboard</a>'
|
195 |
-
|
196 |
-
# Generate AI output
|
197 |
-
def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
|
198 |
-
if not all([role, supervisor_name, project_id, milestones, reflection]):
|
199 |
-
return "❗ Please fill all fields.", "", None, ""
|
200 |
-
|
201 |
-
prompt = PROMPT_TEMPLATE.format(role=role, project_id=project_id, milestones=milestones, reflection=reflection)
|
202 |
-
inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
203 |
-
try:
|
204 |
-
with torch.no_grad():
|
205 |
-
outputs = model.generate(
|
206 |
-
inputs['input_ids'],
|
207 |
-
max_new_tokens=150,
|
208 |
-
no_repeat_ngram_size=2,
|
209 |
-
do_sample=True,
|
210 |
-
top_p=0.9,
|
211 |
-
temperature=0.7,
|
212 |
-
pad_token_id=tokenizer.pad_token_id
|
213 |
-
)
|
214 |
-
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
215 |
-
except Exception as e:
|
216 |
-
print(f"⚠️ Generation error: {e}")
|
217 |
-
return "", "", None, ""
|
218 |
-
|
219 |
-
def extract_between(text, start, end):
|
220 |
-
s = text.find(start)
|
221 |
-
e = text.find(end, s) if end else len(text)
|
222 |
-
return text[s + len(start):e].strip() if s != -1 else ""
|
223 |
-
|
224 |
-
checklist = extract_between(result, "Checklist:\n", "Suggestions:")
|
225 |
-
suggestions = extract_between(result, "Suggestions:\n", None)
|
226 |
-
|
227 |
-
if not checklist.strip():
|
228 |
-
checklist = "- Perform daily safety inspection"
|
229 |
-
if not suggestions.strip():
|
230 |
-
suggestions = "- Monitor team coordination\n- Review safety protocols with the team"
|
231 |
-
|
232 |
-
pdf_path, pdf_name = save_report_as_pdf(role, supervisor_name, project_id, checklist, suggestions)
|
233 |
-
pdf_url = upload_pdf_to_salesforce_and_update_link(supervisor_name, project_id, pdf_path, pdf_name)
|
234 |
-
if pdf_url:
|
235 |
-
suggestions += f"\n\n🔗 [Download PDF Report]({pdf_url})"
|
236 |
-
|
237 |
-
return checklist, suggestions, pdf_path, f'<a href="{pdf_url}" target="_blank">Download PDF</a>' if pdf_url else ""
|
238 |
-
|
239 |
# Gradio Interface
|
240 |
def create_interface():
|
241 |
roles = get_roles_from_salesforce()
|
|
|
8 |
from dotenv import load_dotenv
|
9 |
from fpdf import FPDF
|
10 |
import html
|
11 |
+
import shutil
|
12 |
|
13 |
# Load environment variables
|
14 |
load_dotenv()
|
|
|
186 |
print(f"⚠️ Error fetching project: {e}")
|
187 |
return ""
|
188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
# Gradio Interface
|
190 |
def create_interface():
|
191 |
roles = get_roles_from_salesforce()
|