Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,96 +1,21 @@
|
|
| 1 |
import os
|
| 2 |
-
os.environ["TRANSFORMERS_CACHE"] = "/data/cache"
|
| 3 |
-
import json, os
|
| 4 |
-
from agentos_core import AgentCore
|
| 5 |
-
from context_graph import ContextGraph
|
| 6 |
-
from identity_core import IdentityCore
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
IDENTITY_PATH = "agent_identities.json"
|
| 11 |
-
os.makedirs("data", exist_ok=True)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
if os.path.exists(MEMORY_PATH):
|
| 15 |
-
with open(MEMORY_PATH, "r") as f:
|
| 16 |
-
memory = json.load(f)
|
| 17 |
-
else:
|
| 18 |
-
memory = {}
|
| 19 |
|
| 20 |
-
|
| 21 |
-
agent
|
| 22 |
-
graph = ContextGraph()
|
| 23 |
-
identity = IdentityCore()
|
| 24 |
-
|
| 25 |
-
# === SAVE MEMORY AFTER EACH RUN ===
|
| 26 |
-
def interact(prompt):
|
| 27 |
-
response = agent.run(prompt)
|
| 28 |
-
with open(MEMORY_PATH, "w") as f:
|
| 29 |
-
json.dump(agent.memory, f, indent=2)
|
| 30 |
-
return response
|
| 31 |
|
| 32 |
iface = gr.Interface(
|
| 33 |
-
fn=
|
| 34 |
inputs="text",
|
| 35 |
outputs="text",
|
| 36 |
title="🧠 AgentOS MVP",
|
| 37 |
-
description="Self-learning agent with memory, telemetry, and
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
# === CONTEXT QUERY TAB ===
|
| 41 |
-
def query_context_ui(agent_id, keyword):
|
| 42 |
-
return "\n".join(graph.query_context(agent_id, keyword))
|
| 43 |
-
|
| 44 |
-
context_view = gr.Interface(
|
| 45 |
-
fn=query_context_ui,
|
| 46 |
-
inputs=[
|
| 47 |
-
gr.Textbox(label="Agent ID"),
|
| 48 |
-
gr.Textbox(label="Keyword")
|
| 49 |
-
],
|
| 50 |
-
outputs="text",
|
| 51 |
-
title="🕸 Context Memory Query",
|
| 52 |
-
description="Search what the agent already knows or has linked in memory."
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
# === IDENTITY VIEWER TAB ===
|
| 56 |
-
def show_identities():
|
| 57 |
-
if os.path.exists(IDENTITY_PATH):
|
| 58 |
-
with open(IDENTITY_PATH, "r") as f:
|
| 59 |
-
return json.dumps(json.load(f), indent=2)
|
| 60 |
-
return "No digital DNA file found yet."
|
| 61 |
-
|
| 62 |
-
dna_viewer = gr.Interface(
|
| 63 |
-
fn=show_identities,
|
| 64 |
-
inputs=[],
|
| 65 |
-
outputs="text",
|
| 66 |
-
title="🔐 Digital DNA Viewer",
|
| 67 |
-
description="View all agent identities and their cryptographic signatures."
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
# === VERIFY IDENTITY TAB ===
|
| 71 |
-
def verify_identity():
|
| 72 |
-
if not os.path.exists(IDENTITY_PATH):
|
| 73 |
-
return "No identity file found."
|
| 74 |
-
with open(IDENTITY_PATH, "r") as f:
|
| 75 |
-
data = json.load(f)
|
| 76 |
-
last_id = list(data.keys())[-1]
|
| 77 |
-
sig = data[last_id]["signature"]
|
| 78 |
-
result = identity.verify_identity(last_id, sig)
|
| 79 |
-
return f"Verification result for {last_id}: {result}"
|
| 80 |
-
|
| 81 |
-
verify_btn = gr.Interface(
|
| 82 |
-
fn=lambda: verify_identity(),
|
| 83 |
-
inputs=[],
|
| 84 |
-
outputs="text",
|
| 85 |
-
title="🧩 Verify Agent Identity",
|
| 86 |
-
description="Checks cryptographic DNA of the latest agent instance."
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
# === COMBINE ALL ===
|
| 90 |
-
app = gr.TabbedInterface(
|
| 91 |
-
[iface, context_view, dna_viewer, verify_btn],
|
| 92 |
-
["AgentOS Core", "Context Query", "Digital DNA Viewer", "Verify Identity"]
|
| 93 |
)
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
| 96 |
-
|
|
|
|
| 1 |
import os
|
| 2 |
+
os.environ["TRANSFORMERS_CACHE"] = "/data/cache"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from agentos_core_v4 import AgentCore # or agentos_core if you're not on v4
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
agent = AgentCore()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
def run_agent(prompt):
|
| 10 |
+
return agent.run(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
iface = gr.Interface(
|
| 13 |
+
fn=run_agent,
|
| 14 |
inputs="text",
|
| 15 |
outputs="text",
|
| 16 |
title="🧠 AgentOS MVP",
|
| 17 |
+
description="Self-learning agent with vector memory, telemetry, and personality."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
)
|
| 19 |
|
| 20 |
if __name__ == "__main__":
|
| 21 |
+
iface.launch()
|