Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,8 +29,6 @@ Suggestions:
|
|
| 29 |
Quote:
|
| 30 |
- Your motivational quote here
|
| 31 |
|
| 32 |
-
Now, generate the checklist, suggestions, and quote for the following inputs:
|
| 33 |
-
|
| 34 |
Inputs:
|
| 35 |
Role: {role}
|
| 36 |
Project: {project_id}
|
|
@@ -76,41 +74,38 @@ def generate_outputs(role, project_id, milestones, reflection):
|
|
| 76 |
)
|
| 77 |
|
| 78 |
# Generate with attention_mask
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
| 90 |
|
| 91 |
# Decode generated text
|
| 92 |
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 93 |
|
| 94 |
-
# Parse the output
|
| 95 |
checklist = "No checklist generated."
|
| 96 |
suggestions = "No suggestions generated."
|
| 97 |
quote = "No quote generated."
|
| 98 |
|
| 99 |
-
#
|
| 100 |
if "Checklist:" in generated_text:
|
| 101 |
checklist_start = generated_text.find("Checklist:") + len("Checklist:")
|
| 102 |
-
suggestions_start = generated_text.find("Suggestions:")
|
| 103 |
-
if suggestions_start == -1:
|
| 104 |
-
suggestions_start = len(generated_text)
|
| 105 |
checklist = generated_text[checklist_start:suggestions_start].strip()
|
| 106 |
if not checklist:
|
| 107 |
checklist = "No checklist generated."
|
| 108 |
|
| 109 |
if "Suggestions:" in generated_text:
|
| 110 |
suggestions_start = generated_text.find("Suggestions:") + len("Suggestions:")
|
| 111 |
-
quote_start = generated_text.find("Quote:")
|
| 112 |
-
if quote_start == -1:
|
| 113 |
-
quote_start = len(generated_text)
|
| 114 |
suggestions = generated_text[suggestions_start:quote_start].strip()
|
| 115 |
if not suggestions:
|
| 116 |
suggestions = "No suggestions generated."
|
|
@@ -126,36 +121,40 @@ def generate_outputs(role, project_id, milestones, reflection):
|
|
| 126 |
checklist_items = []
|
| 127 |
milestone_list = [m.strip() for m in milestones.split(",")]
|
| 128 |
for i, milestone in enumerate(milestone_list, 1):
|
| 129 |
-
|
| 130 |
-
time = 8 + (i-1)*2 if i <= 3 else 4 # PM for last item
|
| 131 |
period = "AM" if i <= 3 else "PM"
|
| 132 |
checklist_items.append(f"- {milestone} by {time} {period}.")
|
| 133 |
-
# Add
|
| 134 |
if "safety" in reflection.lower():
|
| 135 |
-
checklist_items.append("- Review safety compliance by
|
| 136 |
else:
|
| 137 |
-
checklist_items.append("- Check equipment status by
|
| 138 |
checklist = "\n".join(checklist_items)
|
| 139 |
|
| 140 |
if suggestions == "No suggestions generated.":
|
| 141 |
suggestions_items = []
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
|
|
|
| 145 |
suggestions_items.append("- Follow up with suppliers to prevent future delays.")
|
| 146 |
-
if "weather" in
|
| 147 |
suggestions_items.append("- Monitor weather updates and plan contingencies.")
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
suggestions_items.append("- Brief the team on tomorrow’s goals during the daily huddle.")
|
| 150 |
suggestions = "\n".join(suggestions_items if suggestions_items else ["- Coordinate with the team.", "- Plan for contingencies."])
|
| 151 |
|
| 152 |
if quote == "No quote generated.":
|
| 153 |
-
|
| 154 |
-
if "safety" in
|
| 155 |
quote = "- Build with care—safety today ensures success tomorrow!"
|
| 156 |
-
elif "delay" in
|
| 157 |
quote = "- Keep moving forward—every challenge is a step toward success!"
|
| 158 |
-
elif "weather" in
|
| 159 |
quote = "- Steady progress leads to great achievements, no matter the weather!"
|
| 160 |
else:
|
| 161 |
quote = "- Success is built one solid step at a time!"
|
|
|
|
| 29 |
Quote:
|
| 30 |
- Your motivational quote here
|
| 31 |
|
|
|
|
|
|
|
| 32 |
Inputs:
|
| 33 |
Role: {role}
|
| 34 |
Project: {project_id}
|
|
|
|
| 74 |
)
|
| 75 |
|
| 76 |
# Generate with attention_mask
|
| 77 |
+
with torch.no_grad():
|
| 78 |
+
outputs = model.generate(
|
| 79 |
+
inputs["input_ids"],
|
| 80 |
+
attention_mask=inputs["attention_mask"],
|
| 81 |
+
max_length=1000,
|
| 82 |
+
num_return_sequences=1,
|
| 83 |
+
no_repeat_ngram_size=2,
|
| 84 |
+
do_sample=True,
|
| 85 |
+
top_p=0.9,
|
| 86 |
+
temperature=0.8,
|
| 87 |
+
pad_token_id=tokenizer.eos_token_id
|
| 88 |
+
)
|
| 89 |
|
| 90 |
# Decode generated text
|
| 91 |
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 92 |
|
| 93 |
+
# Parse the output
|
| 94 |
checklist = "No checklist generated."
|
| 95 |
suggestions = "No suggestions generated."
|
| 96 |
quote = "No quote generated."
|
| 97 |
|
| 98 |
+
# Extract sections using labels
|
| 99 |
if "Checklist:" in generated_text:
|
| 100 |
checklist_start = generated_text.find("Checklist:") + len("Checklist:")
|
| 101 |
+
suggestions_start = generated_text.find("Suggestions:") if "Suggestions:" in generated_text else len(generated_text)
|
|
|
|
|
|
|
| 102 |
checklist = generated_text[checklist_start:suggestions_start].strip()
|
| 103 |
if not checklist:
|
| 104 |
checklist = "No checklist generated."
|
| 105 |
|
| 106 |
if "Suggestions:" in generated_text:
|
| 107 |
suggestions_start = generated_text.find("Suggestions:") + len("Suggestions:")
|
| 108 |
+
quote_start = generated_text.find("Quote:") if "Quote:" in generated_text else len(generated_text)
|
|
|
|
|
|
|
| 109 |
suggestions = generated_text[suggestions_start:quote_start].strip()
|
| 110 |
if not suggestions:
|
| 111 |
suggestions = "No suggestions generated."
|
|
|
|
| 121 |
checklist_items = []
|
| 122 |
milestone_list = [m.strip() for m in milestones.split(",")]
|
| 123 |
for i, milestone in enumerate(milestone_list, 1):
|
| 124 |
+
time = 8 + (i-1)*2 if i <= 3 else 4 # Follow sample timing (8 AM, 10 AM, 12 PM, 4 PM)
|
|
|
|
| 125 |
period = "AM" if i <= 3 else "PM"
|
| 126 |
checklist_items.append(f"- {milestone} by {time} {period}.")
|
| 127 |
+
# Add context-specific task
|
| 128 |
if "safety" in reflection.lower():
|
| 129 |
+
checklist_items.append("- Review safety compliance by 4 PM.")
|
| 130 |
else:
|
| 131 |
+
checklist_items.append("- Check equipment status by 4 PM.")
|
| 132 |
checklist = "\n".join(checklist_items)
|
| 133 |
|
| 134 |
if suggestions == "No suggestions generated.":
|
| 135 |
suggestions_items = []
|
| 136 |
+
reflection_lower = reflection.lower()
|
| 137 |
+
if "safety" in reflection_lower:
|
| 138 |
+
suggestions_items.append("- Address safety concerns with a team briefing on proper procedures.")
|
| 139 |
+
if "delay" in reflection_lower or "late" in reflection_lower:
|
| 140 |
suggestions_items.append("- Follow up with suppliers to prevent future delays.")
|
| 141 |
+
if "weather" in reflection_lower:
|
| 142 |
suggestions_items.append("- Monitor weather updates and plan contingencies.")
|
| 143 |
+
if "equipment" in reflection_lower:
|
| 144 |
+
suggestions_items.append("- Schedule equipment maintenance to avoid future issues.")
|
| 145 |
+
if "suppliers" in reflection_lower:
|
| 146 |
+
suggestions_items.append("- Set up a morning call with suppliers to confirm timelines.")
|
| 147 |
+
# Add generic suggestion
|
| 148 |
suggestions_items.append("- Brief the team on tomorrow’s goals during the daily huddle.")
|
| 149 |
suggestions = "\n".join(suggestions_items if suggestions_items else ["- Coordinate with the team.", "- Plan for contingencies."])
|
| 150 |
|
| 151 |
if quote == "No quote generated.":
|
| 152 |
+
reflection_lower = reflection.lower()
|
| 153 |
+
if "safety" in reflection_lower:
|
| 154 |
quote = "- Build with care—safety today ensures success tomorrow!"
|
| 155 |
+
elif "delay" in reflection_lower or "late" in reflection_lower:
|
| 156 |
quote = "- Keep moving forward—every challenge is a step toward success!"
|
| 157 |
+
elif "weather" in reflection_lower:
|
| 158 |
quote = "- Steady progress leads to great achievements, no matter the weather!"
|
| 159 |
else:
|
| 160 |
quote = "- Success is built one solid step at a time!"
|