geethareddy commited on
Commit
cc63678
Β·
verified Β·
1 Parent(s): 38d7eed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -38
app.py CHANGED
@@ -4,7 +4,6 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
4
  from simple_salesforce import Salesforce
5
  import os
6
  from dotenv import load_dotenv
7
- import uuid
8
 
9
  # Load environment variables
10
  load_dotenv()
@@ -32,8 +31,8 @@ model.config.pad_token_id = tokenizer.pad_token_id
32
  # Better Prompt
33
  PROMPT_TEMPLATE = """You are an AI coach for construction supervisors. Given the role, project, milestones, and a reflection log, generate:
34
 
35
- 1. A Daily Checklist based on the milestones and role.
36
- 2. Focus Suggestions based on concerns or keywords in the reflection log.
37
 
38
  Inputs:
39
  Role: {role}
@@ -49,17 +48,6 @@ Suggestions:
49
  -
50
  """
51
 
52
- # Sample data for Daily Checklist and Focus Suggestions
53
- SAMPLE_CHECKLIST = """- Conduct morning safety briefing
54
- - Review incident reports from previous day
55
- - Ensure progress on safety training
56
- - Perform daily site inspection"""
57
-
58
- SAMPLE_SUGGESTIONS = """- Monitor team coordination
59
- - Review safety protocols with the team
60
- - Follow up on reported incidents
61
- - Provide guidance on timely incident recording"""
62
-
63
  # Salesforce Functions
64
  def get_roles_from_salesforce():
65
  try:
@@ -158,10 +146,8 @@ def save_to_salesforce(role, project_id, milestones, reflection, checklist, sugg
158
  def generate_fallback_checklist(role, milestones):
159
  checklist_items = []
160
  if role.lower() == "safety officer":
161
- checklist_items.extend([
162
- "- Conduct morning safety briefing",
163
- "- Review incident reports from previous day"
164
- ])
165
 
166
  if milestones and milestones.strip():
167
  kpis = [kpi.strip() for kpi in milestones.split(",")]
@@ -170,31 +156,27 @@ def generate_fallback_checklist(role, milestones):
170
  else:
171
  checklist_items.append("- Perform daily safety inspection")
172
 
173
- return "\n".join(checklist_items) or SAMPLE_CHECKLIST
174
 
175
  def generate_fallback_suggestions(reflection):
176
  suggestions_items = []
177
  reflection_lower = reflection.lower()
178
  if "student" in reflection_lower or "learning" in reflection_lower:
179
- suggestions_items.extend([
180
- "- Ensure students are logging incidents consistently",
181
- "- Provide guidance on timely incident recording"
182
- ])
183
  if "incident" in reflection_lower:
184
  suggestions_items.append("- Follow up on reported incidents with corrective actions")
185
 
186
  if not suggestions_items:
187
- suggestions_items.extend([
188
- "- Monitor team coordination",
189
- "- Review safety protocols with the team"
190
- ])
191
 
192
- return "\n".join(suggestions_items) or SAMPLE_SUGGESTIONS
193
 
194
  # Generate Function
195
  def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
196
  if not all([role, supervisor_name, project_id, milestones, reflection]):
197
- return SAMPLE_CHECKLIST, SAMPLE_SUGGESTIONS
198
 
199
  prompt = PROMPT_TEMPLATE.format(
200
  role=role,
@@ -208,7 +190,7 @@ def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
208
  with torch.no_grad():
209
  outputs = model.generate(
210
  inputs['input_ids'],
211
- max_new_tokens=100,
212
  no_repeat_ngram_size=2,
213
  do_sample=True,
214
  top_p=0.9,
@@ -251,12 +233,12 @@ def create_interface():
251
  gr.Markdown("## 🧠 AI-Powered Supervisor Assistant")
252
 
253
  with gr.Row():
254
- role = gr.Dropdown(choices=roles, label="Role", value="Safety Officer")
255
- supervisor_name = gr.Dropdown(choices=[], label="Supervisor Name", value="John Doe")
256
- project_id = gr.Textbox(label="Project ID", value="PROJ-001", interactive=False)
257
 
258
- milestones = gr.Textbox(label="Milestones (comma-separated KPIs)", value="Safety training, daily inspection", placeholder="E.g. Safety training, daily inspection")
259
- reflection = gr.Textbox(label="Reflection Log", lines=4, value="Team is learning to log incidents, but some delays occurred.", placeholder="Any concerns, delays, updates...")
260
 
261
  with gr.Row():
262
  generate = gr.Button("Generate")
@@ -264,8 +246,8 @@ def create_interface():
264
  refresh = gr.Button("πŸ”„ Refresh Roles")
265
  dashboard_btn = gr.Button("Dashboard")
266
 
267
- checklist_output = gr.Textbox(label="βœ… Daily Checklist", value=SAMPLE_CHECKLIST)
268
- suggestions_output = gr.Textbox(label="πŸ’‘ Focus Suggestions", value=SAMPLE_SUGGESTIONS)
269
  dashboard_link = gr.HTML("")
270
 
271
  role.change(fn=lambda r: gr.update(choices=get_supervisor_name_by_role(r)), inputs=role, outputs=supervisor_name)
@@ -286,4 +268,4 @@ def create_interface():
286
 
287
  if __name__ == "__main__":
288
  app = create_interface()
289
- app.launch()
 
4
  from simple_salesforce import Salesforce
5
  import os
6
  from dotenv import load_dotenv
 
7
 
8
  # Load environment variables
9
  load_dotenv()
 
31
  # Better Prompt
32
  PROMPT_TEMPLATE = """You are an AI coach for construction supervisors. Given the role, project, milestones, and a reflection log, generate:
33
 
34
+ 1. A Daily Checklist based on the milestones and role. Ensure to include at least 4 items.
35
+ 2. Focus Suggestions based on concerns or keywords in the reflection log. Provide at least 2 suggestions.
36
 
37
  Inputs:
38
  Role: {role}
 
48
  -
49
  """
50
 
 
 
 
 
 
 
 
 
 
 
 
51
  # Salesforce Functions
52
  def get_roles_from_salesforce():
53
  try:
 
146
  def generate_fallback_checklist(role, milestones):
147
  checklist_items = []
148
  if role.lower() == "safety officer":
149
+ checklist_items.append("- Conduct morning safety briefing")
150
+ checklist_items.append("- Review incident reports from previous day")
 
 
151
 
152
  if milestones and milestones.strip():
153
  kpis = [kpi.strip() for kpi in milestones.split(",")]
 
156
  else:
157
  checklist_items.append("- Perform daily safety inspection")
158
 
159
+ return "\n".join(checklist_items)
160
 
161
  def generate_fallback_suggestions(reflection):
162
  suggestions_items = []
163
  reflection_lower = reflection.lower()
164
  if "student" in reflection_lower or "learning" in reflection_lower:
165
+ suggestions_items.append("- Ensure students are logging incidents consistently")
166
+ suggestions_items.append("- Provide guidance on timely incident recording")
 
 
167
  if "incident" in reflection_lower:
168
  suggestions_items.append("- Follow up on reported incidents with corrective actions")
169
 
170
  if not suggestions_items:
171
+ suggestions_items.append("- Monitor team coordination")
172
+ suggestions_items.append("- Review safety protocols with the team")
 
 
173
 
174
+ return "\n".join(suggestions_items)
175
 
176
  # Generate Function
177
  def generate_outputs(role, supervisor_name, project_id, milestones, reflection):
178
  if not all([role, supervisor_name, project_id, milestones, reflection]):
179
+ return "❗ Please fill all fields.", ""
180
 
181
  prompt = PROMPT_TEMPLATE.format(
182
  role=role,
 
190
  with torch.no_grad():
191
  outputs = model.generate(
192
  inputs['input_ids'],
193
+ max_new_tokens=100, # Limit output length to avoid delays
194
  no_repeat_ngram_size=2,
195
  do_sample=True,
196
  top_p=0.9,
 
233
  gr.Markdown("## 🧠 AI-Powered Supervisor Assistant")
234
 
235
  with gr.Row():
236
+ role = gr.Dropdown(choices=roles, label="Role")
237
+ supervisor_name = gr.Dropdown(choices=[], label="Supervisor Name")
238
+ project_id = gr.Textbox(label="Project ID", interactive=False)
239
 
240
+ milestones = gr.Textbox(label="Milestones (comma-separated KPIs)", placeholder="E.g. Safety training, daily inspection")
241
+ reflection = gr.Textbox(label="Reflection Log", lines=4, placeholder="Any concerns, delays, updates...")
242
 
243
  with gr.Row():
244
  generate = gr.Button("Generate")
 
246
  refresh = gr.Button("πŸ”„ Refresh Roles")
247
  dashboard_btn = gr.Button("Dashboard")
248
 
249
+ checklist_output = gr.Textbox(label="βœ… Daily Checklist")
250
+ suggestions_output = gr.Textbox(label="πŸ’‘ Focus Suggestions")
251
  dashboard_link = gr.HTML("")
252
 
253
  role.change(fn=lambda r: gr.update(choices=get_supervisor_name_by_role(r)), inputs=role, outputs=supervisor_name)
 
268
 
269
  if __name__ == "__main__":
270
  app = create_interface()
271
+ app.launch()