Tpayne101 commited on
Commit
a368d99
·
verified ·
1 Parent(s): ca1e68d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -73
app.py CHANGED
@@ -1,75 +1,31 @@
1
  import gradio as gr
2
- from agentos_core_v4 import AgentCore # ⬅️ switch to v4
3
-
4
- agent = AgentCore()
5
-
6
- def run_agent(prompt):
7
- return agent.run(prompt)
8
-
9
- iface = gr.Interface(
10
- fn=run_agent,
11
- inputs="text",
12
- outputs="text",
13
- title="🧠 AgentOS MVP",
14
- description="Self-learning agent with vector memory, telemetry, and personality."
15
- )
16
-
17
- iface.launch()
18
-
19
- if __name__ == "__main__":
20
- iface.launch()
21
- from identity_core import IdentityCore
22
- import json
23
-
24
- def verify_identity():
25
- identity = IdentityCore()
26
- with open("agent_identities.json", "r") as f:
27
- data = json.load(f)
28
- last_id = list(data.keys())[-1]
29
- sig = data[last_id]["signature"]
30
- result = identity.verify_identity(last_id, sig)
31
- return f"Verification result for {last_id}: {result}"
32
- verify_btn = gr.Interface(
33
- fn=lambda: verify_identity(),
34
- inputs=[],
35
- outputs="text",
36
- title="Verify Agent Identity",
37
- description="Checks cryptographic DNA of the latest agent instance"
38
- )
39
- iface.launch(share=True)
40
- verify_btn.launch(share=True)
41
- import gradio as gr
42
  import json, os
43
-
44
- def show_identities():
45
- if os.path.exists("agent_identities.json"):
46
- with open("agent_identities.json", "r") as f:
47
- return json.dumps(json.load(f), indent=2)
48
- return "No digital DNA file found yet."
49
-
50
- dna_viewer = gr.Interface(
51
- fn=show_identities,
52
- inputs=[],
53
- outputs="text",
54
- title="🔐 Digital DNA Viewer",
55
- description="View all agent identities and their signatures."
56
- )
57
-
58
- # Combine both UIs into tabs
59
- app = gr.TabbedInterface([iface, dna_viewer], ["AgentOS Core", "Digital DNA Viewer"])
60
- app.launch()
61
- import gradio as gr
62
  from agentos_core import AgentCore
63
  from context_graph import ContextGraph
64
- import json, os
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- # --- Instantiate Core Systems ---
67
- agent = AgentCore()
68
  graph = ContextGraph()
 
69
 
70
- # --- Define main agent function ---
71
  def interact(prompt):
72
  response = agent.run(prompt)
 
 
73
  return response
74
 
75
  iface = gr.Interface(
@@ -77,10 +33,10 @@ iface = gr.Interface(
77
  inputs="text",
78
  outputs="text",
79
  title="🧠 AgentOS MVP",
80
- description="Self-learning agent with memory + telemetry."
81
  )
82
 
83
- # --- Context Query Tab ---
84
  def query_context_ui(agent_id, keyword):
85
  return "\n".join(graph.query_context(agent_id, keyword))
86
 
@@ -95,10 +51,10 @@ context_view = gr.Interface(
95
  description="Search what the agent already knows or has linked in memory."
96
  )
97
 
98
- # --- Digital DNA Viewer Tab ---
99
  def show_identities():
100
- if os.path.exists("agent_identities.json"):
101
- with open("agent_identities.json", "r") as f:
102
  return json.dumps(json.load(f), indent=2)
103
  return "No digital DNA file found yet."
104
 
@@ -107,13 +63,33 @@ dna_viewer = gr.Interface(
107
  inputs=[],
108
  outputs="text",
109
  title="🔐 Digital DNA Viewer",
110
- description="View all agent identities and their signatures."
111
  )
112
 
113
- # --- Combine all interfaces ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  app = gr.TabbedInterface(
115
- [iface, dna_viewer, context_view],
116
- ["AgentOS Core", "Digital DNA Viewer", "Context Query"]
117
  )
118
 
119
- app.launch()
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import json, os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  from agentos_core import AgentCore
4
  from context_graph import ContextGraph
5
+ from identity_core import IdentityCore
6
+
7
+ # === PATHS ===
8
+ MEMORY_PATH = "data/memory.json"
9
+ IDENTITY_PATH = "agent_identities.json"
10
+ os.makedirs("data", exist_ok=True)
11
+
12
+ # === LOAD OR INIT MEMORY ===
13
+ if os.path.exists(MEMORY_PATH):
14
+ with open(MEMORY_PATH, "r") as f:
15
+ memory = json.load(f)
16
+ else:
17
+ memory = {}
18
 
19
+ # === CORE SYSTEMS ===
20
+ agent = AgentCore(memory=memory)
21
  graph = ContextGraph()
22
+ identity = IdentityCore()
23
 
24
+ # === SAVE MEMORY AFTER EACH RUN ===
25
  def interact(prompt):
26
  response = agent.run(prompt)
27
+ with open(MEMORY_PATH, "w") as f:
28
+ json.dump(agent.memory, f, indent=2)
29
  return response
30
 
31
  iface = gr.Interface(
 
33
  inputs="text",
34
  outputs="text",
35
  title="🧠 AgentOS MVP",
36
+ description="Self-learning agent with memory, telemetry, and identity verification."
37
  )
38
 
39
+ # === CONTEXT QUERY TAB ===
40
  def query_context_ui(agent_id, keyword):
41
  return "\n".join(graph.query_context(agent_id, keyword))
42
 
 
51
  description="Search what the agent already knows or has linked in memory."
52
  )
53
 
54
+ # === IDENTITY VIEWER TAB ===
55
  def show_identities():
56
+ if os.path.exists(IDENTITY_PATH):
57
+ with open(IDENTITY_PATH, "r") as f:
58
  return json.dumps(json.load(f), indent=2)
59
  return "No digital DNA file found yet."
60
 
 
63
  inputs=[],
64
  outputs="text",
65
  title="🔐 Digital DNA Viewer",
66
+ description="View all agent identities and their cryptographic signatures."
67
  )
68
 
69
+ # === VERIFY IDENTITY TAB ===
70
+ def verify_identity():
71
+ if not os.path.exists(IDENTITY_PATH):
72
+ return "No identity file found."
73
+ with open(IDENTITY_PATH, "r") as f:
74
+ data = json.load(f)
75
+ last_id = list(data.keys())[-1]
76
+ sig = data[last_id]["signature"]
77
+ result = identity.verify_identity(last_id, sig)
78
+ return f"Verification result for {last_id}: {result}"
79
+
80
+ verify_btn = gr.Interface(
81
+ fn=lambda: verify_identity(),
82
+ inputs=[],
83
+ outputs="text",
84
+ title="🧩 Verify Agent Identity",
85
+ description="Checks cryptographic DNA of the latest agent instance."
86
+ )
87
+
88
+ # === COMBINE ALL ===
89
  app = gr.TabbedInterface(
90
+ [iface, context_view, dna_viewer, verify_btn],
91
+ ["AgentOS Core", "Context Query", "Digital DNA Viewer", "Verify Identity"]
92
  )
93
 
94
+ if __name__ == "__main__":
95
+ app.launch(share=True)