Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
from collections import defaultdict
|
| 4 |
+
|
| 5 |
+
# -----------------------------
|
| 6 |
+
# Goal Setting Agent Algorithm
|
| 7 |
+
# -----------------------------
|
| 8 |
+
def goal_setting_agent(goals_text, priorities_text, dependencies_text, total_time):
|
| 9 |
+
|
| 10 |
+
# Parse inputs
|
| 11 |
+
G = [g.strip() for g in goals_text.split(",")]
|
| 12 |
+
P = list(map(int, priorities_text.split(",")))
|
| 13 |
+
|
| 14 |
+
# Dependencies format: g1:g2 means g1 depends on g2
|
| 15 |
+
DG = defaultdict(list)
|
| 16 |
+
if dependencies_text.strip():
|
| 17 |
+
deps = dependencies_text.split(",")
|
| 18 |
+
for d in deps:
|
| 19 |
+
g1, g2 = d.split(":")
|
| 20 |
+
DG[g1.strip()].append(g2.strip())
|
| 21 |
+
|
| 22 |
+
# Step 1: Sort goals by priority
|
| 23 |
+
goals_sorted = [g for _, g in sorted(zip(P, G), reverse=True)]
|
| 24 |
+
|
| 25 |
+
# Step 2: Ensure dependencies satisfied (simple check)
|
| 26 |
+
ordered_goals = []
|
| 27 |
+
visited = set()
|
| 28 |
+
|
| 29 |
+
def visit(g):
|
| 30 |
+
if g in visited:
|
| 31 |
+
return
|
| 32 |
+
for dep in DG[g]:
|
| 33 |
+
visit(dep)
|
| 34 |
+
visited.add(g)
|
| 35 |
+
ordered_goals.append(g)
|
| 36 |
+
|
| 37 |
+
for g in goals_sorted:
|
| 38 |
+
visit(g)
|
| 39 |
+
|
| 40 |
+
# Step 3: Decompose into milestones
|
| 41 |
+
action_plan = {}
|
| 42 |
+
for g in ordered_goals:
|
| 43 |
+
action_plan[g] = [
|
| 44 |
+
f"{g} - Milestone 1",
|
| 45 |
+
f"{g} - Milestone 2",
|
| 46 |
+
f"{g} - Milestone 3"
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
# Step 4: Assign duration
|
| 50 |
+
time_per_goal = int(total_time) // len(ordered_goals)
|
| 51 |
+
schedule = {}
|
| 52 |
+
|
| 53 |
+
current_time = 0
|
| 54 |
+
for g in ordered_goals:
|
| 55 |
+
schedule[g] = {
|
| 56 |
+
"start": current_time,
|
| 57 |
+
"end": current_time + time_per_goal,
|
| 58 |
+
"duration": time_per_goal
|
| 59 |
+
}
|
| 60 |
+
current_time += time_per_goal
|
| 61 |
+
|
| 62 |
+
# Step 5: Adjust constraints (basic)
|
| 63 |
+
# (can be extended for real-world constraints)
|
| 64 |
+
|
| 65 |
+
return (
|
| 66 |
+
json.dumps(schedule, indent=2),
|
| 67 |
+
json.dumps(DG, indent=2),
|
| 68 |
+
json.dumps(action_plan, indent=2)
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# -----------------------------
|
| 73 |
+
# Gradio UI
|
| 74 |
+
# -----------------------------
|
| 75 |
+
interface = gr.Interface(
|
| 76 |
+
fn=goal_setting_agent,
|
| 77 |
+
inputs=[
|
| 78 |
+
gr.Textbox(label="Goals (comma-separated)", placeholder="g1, g2, g3"),
|
| 79 |
+
gr.Textbox(label="Priorities (comma-separated, higher = important)", placeholder="3, 2, 1"),
|
| 80 |
+
gr.Textbox(label="Dependencies (g1:g2 format, comma-separated)", placeholder="g2:g1"),
|
| 81 |
+
gr.Number(label="Total Time Available")
|
| 82 |
+
],
|
| 83 |
+
outputs=[
|
| 84 |
+
gr.Code(label="Schedule (S)", language="json"),
|
| 85 |
+
gr.Code(label="Dependency Graph (DG)", language="json"),
|
| 86 |
+
gr.Code(label="Action Plan", language="json")
|
| 87 |
+
],
|
| 88 |
+
title="Goal Setting Agent (Algorithm 4.2)",
|
| 89 |
+
description="Generates schedule, dependency graph, and action plan based on input goals."
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
if __name__ == "__main__":
|
| 93 |
+
interface.launch()
|