Spaces:
Sleeping
Sleeping
Update planner.py
Browse files- planner.py +39 -60
planner.py
CHANGED
|
@@ -1,75 +1,54 @@
|
|
| 1 |
# planner.py
|
| 2 |
import os
|
| 3 |
-
import re
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
|
| 6 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
-
client = InferenceClient(
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
goal_lower = goal.lower()
|
| 12 |
-
# Match "X days", "X weeks", etc.
|
| 13 |
-
if m := re.search(r'(\d+)\s*days?', goal_lower):
|
| 14 |
-
return int(m.group(1))
|
| 15 |
-
if m := re.search(r'(\d+)\s*weeks?', goal_lower):
|
| 16 |
-
return int(m.group(1)) * 7
|
| 17 |
-
# Default to 14 if unclear
|
| 18 |
-
return 14
|
| 19 |
|
| 20 |
def generate_task_plan(goal: str) -> str:
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
try:
|
| 53 |
response = client.chat.completions.create(
|
| 54 |
model="Qwen/Qwen2.5-Coder-7B-Instruct",
|
| 55 |
messages=[{"role": "user", "content": prompt}],
|
| 56 |
-
max_tokens=
|
| 57 |
-
temperature=0.
|
| 58 |
-
top_p=0.9,
|
| 59 |
stream=False
|
| 60 |
)
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
# Optional: Remove any leading/trailing prose (safety net)
|
| 64 |
-
lines = raw.split('\n')
|
| 65 |
-
cleaned = []
|
| 66 |
-
for line in lines:
|
| 67 |
-
if line.strip() and (line.strip()[0].isdigit() or line.strip().startswith(('1.', '2.', '3.', '4.', '5.', '6.', '7.', '8.', '9.', '10.', '11.', '12.', '13.', '14.', '15.', '16.', '17.', '18.', '19.', '20.', '21.', '22.', '23.', '24.', '25.'))):
|
| 68 |
-
cleaned.append(line)
|
| 69 |
-
elif cleaned: # Stop if we've started and hit non-task text
|
| 70 |
-
break
|
| 71 |
-
|
| 72 |
-
return '\n'.join(cleaned) if cleaned else raw
|
| 73 |
-
|
| 74 |
except Exception as e:
|
| 75 |
-
|
|
|
|
| 1 |
# planner.py
|
| 2 |
import os
|
|
|
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 6 |
+
client = InferenceClient(
|
| 7 |
+
model="Qwen/Qwen2.5-Coder-7B-Instruct",
|
| 8 |
+
token=HF_TOKEN
|
| 9 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def generate_task_plan(goal: str) -> str:
|
| 12 |
+
"""
|
| 13 |
+
Generate a realistic task plan that respects the timeline in the goal.
|
| 14 |
+
Example: "Launch a product in 4 weeks" → use up to Day 28.
|
| 15 |
+
"""
|
| 16 |
+
# Simple, clear prompt — no over-engineering
|
| 17 |
+
prompt = f"""
|
| 18 |
+
You are an experienced product manager. Break down the following goal into a clear, practical list of tasks.
|
| 19 |
+
|
| 20 |
+
Goal: "{goal}"
|
| 21 |
+
|
| 22 |
+
Important:
|
| 23 |
+
- If the goal mentions a timeframe (e.g., "in 4 weeks"), convert it to days (4 weeks = 28 days).
|
| 24 |
+
- All tasks must be completed within that total number of days.
|
| 25 |
+
- Distribute work realistically across the full timeline — don’t cram everything early.
|
| 26 |
+
- Include key phases: planning, design, development, testing, marketing, launch, and post-launch.
|
| 27 |
+
- For each task, specify:
|
| 28 |
+
• A short name
|
| 29 |
+
• A due date as "Due: Day N" (N must be ≤ total days)
|
| 30 |
+
• Dependencies (e.g., "Depends on: Task 3" or "None")
|
| 31 |
+
• A one-sentence description
|
| 32 |
+
|
| 33 |
+
Output only a numbered list like this:
|
| 34 |
+
|
| 35 |
+
1. Define product requirements - Due: Day 2 - Depends on: None
|
| 36 |
+
Description: Finalize core features and target users.
|
| 37 |
+
2. Design user interface - Due: Day 6 - Depends on: Task 1
|
| 38 |
+
Description: Create wireframes and high-fidelity mockups.
|
| 39 |
+
...
|
| 40 |
+
|
| 41 |
+
Now generate the plan for the goal above. Use the full available time wisely.
|
| 42 |
+
"""
|
| 43 |
|
| 44 |
try:
|
| 45 |
response = client.chat.completions.create(
|
| 46 |
model="Qwen/Qwen2.5-Coder-7B-Instruct",
|
| 47 |
messages=[{"role": "user", "content": prompt}],
|
| 48 |
+
max_tokens=800,
|
| 49 |
+
temperature=0.4, # Balanced: clear but not robotic
|
|
|
|
| 50 |
stream=False
|
| 51 |
)
|
| 52 |
+
return response.choices[0].message.content.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
except Exception as e:
|
| 54 |
+
return f"Error: {str(e)}"
|