Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,7 +33,6 @@ PROMPT_TEMPLATE = """You are an AI coach for construction supervisors. Given the
|
|
33 |
|
34 |
1. A Daily Checklist based on the milestones and role.
|
35 |
2. Focus Suggestions based on concerns or keywords in the reflection log.
|
36 |
-
3. A Motivational Quote for the day.
|
37 |
|
38 |
Inputs:
|
39 |
Role: {role}
|
@@ -47,8 +46,6 @@ Checklist:
|
|
47 |
|
48 |
Suggestions:
|
49 |
-
|
50 |
-
|
51 |
-
Quote:
|
52 |
"""
|
53 |
|
54 |
# Salesforce Functions
|
@@ -108,7 +105,7 @@ def field_exists(sf, object_name, field_name):
|
|
108 |
print(f"⚠️ Error checking field {field_name}: {e}")
|
109 |
return False
|
110 |
|
111 |
-
def save_to_salesforce(role, project_id, milestones, reflection, checklist, suggestions,
|
112 |
try:
|
113 |
sf = Salesforce(
|
114 |
username=os.getenv('SF_USERNAME'),
|
@@ -182,7 +179,7 @@ def generate_fallback_suggestions(reflection):
|
|
182 |
# Generate Function
|
183 |
def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
|
184 |
if not all([role, supervisor_name, project_id, milestones, reflection]):
|
185 |
-
return "❗ Please fill all fields.", ""
|
186 |
|
187 |
prompt = PROMPT_TEMPLATE.format(
|
188 |
role=role,
|
@@ -209,9 +206,8 @@ def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
|
|
209 |
# Use fallback if generation fails
|
210 |
checklist = generate_fallback_checklist(role, milestones)
|
211 |
suggestions = generate_fallback_suggestions(reflection)
|
212 |
-
|
213 |
-
|
214 |
-
return checklist, suggestions, quote
|
215 |
|
216 |
def extract_between(text, start, end):
|
217 |
s = text.find(start)
|
@@ -219,19 +215,16 @@ def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
|
|
219 |
return text[s + len(start):e].strip() if s != -1 else ""
|
220 |
|
221 |
checklist = extract_between(result, "Checklist:\n", "Suggestions:")
|
222 |
-
suggestions = extract_between(result, "Suggestions:\n",
|
223 |
-
quote = extract_between(result, "Quote:\n", None)
|
224 |
|
225 |
# Use fallback if checklist or suggestions are empty
|
226 |
if not checklist.strip():
|
227 |
checklist = generate_fallback_checklist(role, milestones)
|
228 |
if not suggestions.strip():
|
229 |
suggestions = generate_fallback_suggestions(reflection)
|
230 |
-
if not quote.strip():
|
231 |
-
quote = "Success is the sum of small efforts, repeated day in and day out."
|
232 |
|
233 |
-
save_to_salesforce(role, project_id, milestones, reflection, checklist, suggestions,
|
234 |
-
return checklist, suggestions
|
235 |
|
236 |
# Dashboard button function
|
237 |
def open_dashboard():
|
@@ -260,7 +253,6 @@ def create_interface():
|
|
260 |
|
261 |
checklist_output = gr.Textbox(label="✅ Daily Checklist")
|
262 |
suggestions_output = gr.Textbox(label="💡 Focus Suggestions")
|
263 |
-
quote_output = gr.Textbox(label="✨ Motivational Quote")
|
264 |
dashboard_link = gr.HTML("")
|
265 |
|
266 |
role.change(fn=lambda r: gr.update(choices=get_supervisor_name_by_role(r)), inputs=role, outputs=supervisor_name)
|
@@ -268,7 +260,7 @@ def create_interface():
|
|
268 |
|
269 |
generate.click(fn=generate_outputs,
|
270 |
inputs=[role, supervisor_name, project_id, milestones, reflection],
|
271 |
-
outputs=[checklist_output, suggestions_output
|
272 |
|
273 |
clear.click(fn=lambda: ("", "", "", "", ""), inputs=None,
|
274 |
outputs=[role, supervisor_name, project_id, milestones, reflection])
|
@@ -281,4 +273,4 @@ def create_interface():
|
|
281 |
|
282 |
if __name__ == "__main__":
|
283 |
app = create_interface()
|
284 |
-
app.launch()
|
|
|
33 |
|
34 |
1. A Daily Checklist based on the milestones and role.
|
35 |
2. Focus Suggestions based on concerns or keywords in the reflection log.
|
|
|
36 |
|
37 |
Inputs:
|
38 |
Role: {role}
|
|
|
46 |
|
47 |
Suggestions:
|
48 |
-
|
|
|
|
|
49 |
"""
|
50 |
|
51 |
# Salesforce Functions
|
|
|
105 |
print(f"⚠️ Error checking field {field_name}: {e}")
|
106 |
return False
|
107 |
|
108 |
+
def save_to_salesforce(role, project_id, milestones, reflection, checklist, suggestions, supervisor_name):
|
109 |
try:
|
110 |
sf = Salesforce(
|
111 |
username=os.getenv('SF_USERNAME'),
|
|
|
179 |
# Generate Function
|
180 |
def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
|
181 |
if not all([role, supervisor_name, project_id, milestones, reflection]):
|
182 |
+
return "❗ Please fill all fields.", ""
|
183 |
|
184 |
prompt = PROMPT_TEMPLATE.format(
|
185 |
role=role,
|
|
|
206 |
# Use fallback if generation fails
|
207 |
checklist = generate_fallback_checklist(role, milestones)
|
208 |
suggestions = generate_fallback_suggestions(reflection)
|
209 |
+
save_to_salesforce(role, project_id, milestones, reflection, checklist, suggestions, supervisor_name)
|
210 |
+
return checklist, suggestions
|
|
|
211 |
|
212 |
def extract_between(text, start, end):
|
213 |
s = text.find(start)
|
|
|
215 |
return text[s + len(start):e].strip() if s != -1 else ""
|
216 |
|
217 |
checklist = extract_between(result, "Checklist:\n", "Suggestions:")
|
218 |
+
suggestions = extract_between(result, "Suggestions:\n", None)
|
|
|
219 |
|
220 |
# Use fallback if checklist or suggestions are empty
|
221 |
if not checklist.strip():
|
222 |
checklist = generate_fallback_checklist(role, milestones)
|
223 |
if not suggestions.strip():
|
224 |
suggestions = generate_fallback_suggestions(reflection)
|
|
|
|
|
225 |
|
226 |
+
save_to_salesforce(role, project_id, milestones, reflection, checklist, suggestions, supervisor_name)
|
227 |
+
return checklist, suggestions
|
228 |
|
229 |
# Dashboard button function
|
230 |
def open_dashboard():
|
|
|
253 |
|
254 |
checklist_output = gr.Textbox(label="✅ Daily Checklist")
|
255 |
suggestions_output = gr.Textbox(label="💡 Focus Suggestions")
|
|
|
256 |
dashboard_link = gr.HTML("")
|
257 |
|
258 |
role.change(fn=lambda r: gr.update(choices=get_supervisor_name_by_role(r)), inputs=role, outputs=supervisor_name)
|
|
|
260 |
|
261 |
generate.click(fn=generate_outputs,
|
262 |
inputs=[role, supervisor_name, project_id, milestones, reflection],
|
263 |
+
outputs=[checklist_output, suggestions_output])
|
264 |
|
265 |
clear.click(fn=lambda: ("", "", "", "", ""), inputs=None,
|
266 |
outputs=[role, supervisor_name, project_id, milestones, reflection])
|
|
|
273 |
|
274 |
if __name__ == "__main__":
|
275 |
app = create_interface()
|
276 |
+
app.launch()
|