File size: 3,090 Bytes
f4d267f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c4eb0d
 
b38f8c0
5c4eb0d
 
 
b38f8c0
5c4eb0d
 
 
b38f8c0
5c4eb0d
 
 
 
 
f4d267f
 
5c4eb0d
f4d267f
5c4eb0d
f4d267f
5c4eb0d
b38f8c0
f4d267f
 
 
 
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
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import gradio as gr
import json
from collections import defaultdict

# -----------------------------
# Goal Setting Agent Algorithm
# -----------------------------
def goal_setting_agent(goals_text, priorities_text, dependencies_text, total_time):

    # Parse inputs
    G = [g.strip() for g in goals_text.split(",")]
    P = list(map(int, priorities_text.split(",")))

    # Dependencies format: g1:g2 means g1 depends on g2
    DG = defaultdict(list)
    if dependencies_text.strip():
        deps = dependencies_text.split(",")
        for d in deps:
            g1, g2 = d.split(":")
            DG[g1.strip()].append(g2.strip())

    # Step 1: Sort goals by priority
    goals_sorted = [g for _, g in sorted(zip(P, G), reverse=True)]

    # Step 2: Ensure dependencies satisfied (simple check)
    ordered_goals = []
    visited = set()

    def visit(g):
        if g in visited:
            return
        for dep in DG[g]:
            visit(dep)
        visited.add(g)
        ordered_goals.append(g)

    for g in goals_sorted:
        visit(g)

    # Step 3: Decompose into milestones
    action_plan = {}
    for g in ordered_goals:
        action_plan[g] = [
            f"{g} - Milestone 1",
            f"{g} - Milestone 2",
            f"{g} - Milestone 3"
        ]

    # Step 4: Assign duration
    time_per_goal = int(total_time) // len(ordered_goals)
    schedule = {}

    current_time = 0
    for g in ordered_goals:
        schedule[g] = {
            "start": current_time,
            "end": current_time + time_per_goal,
            "duration": time_per_goal
        }
        current_time += time_per_goal

    # Step 5: Adjust constraints (basic)
    # (can be extended for real-world constraints)
   
    return (
        json.dumps(schedule, indent=2),
        json.dumps(DG, indent=2),
        json.dumps(action_plan, indent=2)
    )


# -----------------------------
# Gradio UI
# -----------------------------
interface = gr.Interface(
    fn=goal_setting_agent,
    inputs=[
        gr.Textbox(
            label="Health Goals (comma-separated)",
            value="Reduce Vata imbalance, Improve digestion (Pitta), Enhance sleep quality, Balance Kapha"
        ),
        gr.Textbox(
            label="Priorities (comma-separated, higher = important)",
            value="3, 2, 1, 2"
        ),
        gr.Textbox(
            label="Dependencies (goal1:goal2 format, comma-separated)",
            value="Enhance sleep quality:Reduce Vata imbalance, Improve digestion (Pitta):Balance Kapha"
        ),
        gr.Number(
            label="Total Time Available (in days)",
            value=21
        )
    ],
    outputs=[
        gr.Code(label="Personalized Schedule (S)", language="json"),
        gr.Code(label="Dependency Graph (DG)", language="json"),
        gr.Code(label="Ayurvedic Action Plan", language="json")
    ],
    title="Ayurvedic Goal Setting Agent (Algorithm 4.2)",
    description="Generates a personalized healing plan based on dosha imbalance, priorities, and dependencies."
)

if __name__ == "__main__":
    interface.launch()