Spaces:
Runtime error
Runtime error
Upload 12 files
Browse files- README.md +32 -1
- knowledge/state.json +19 -1
- memory.py +5 -12
- requirements.txt +3 -6
- src/agents/critic.py +2 -1
- src/agents/executor.py +2 -1
- src/agents/planner.py +2 -1
- src/core/cognitive_engine.py +16 -1
- src/utils/hf_packager.py +2 -1
- static/style.css +1 -108
README.md
CHANGED
@@ -1 +1,32 @@
|
|
1 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 🧠 Autonomous AI (FastAPI + Multi-Agent)
|
2 |
+
|
3 |
+
This is a multi-agent autonomous AI application using FastAPI, `ctransformers`, and Gradio. It supports:
|
4 |
+
|
5 |
+
- 🧠 Planner / Executor / Critic agents
|
6 |
+
- ✅ Session-based memory
|
7 |
+
- 📤 POST + GET endpoints
|
8 |
+
- 🎛 Web interface via Gradio
|
9 |
+
- 📦 Ready for Hugging Face Spaces
|
10 |
+
|
11 |
+
## 🚀 Run locally
|
12 |
+
|
13 |
+
```bash
|
14 |
+
pip install -r requirements.txt
|
15 |
+
python app.py
|
16 |
+
```
|
17 |
+
|
18 |
+
## 🧪 Endpoints
|
19 |
+
|
20 |
+
| Method | Endpoint | Description |
|
21 |
+
|--------|--------------------------|-------------------------|
|
22 |
+
| GET | `/status` | System check |
|
23 |
+
| GET | `/generate?prompt=...` | Quick model query |
|
24 |
+
| POST | `/generate` | Send prompt + session |
|
25 |
+
| GET | `/memory/{session_id}` | View memory |
|
26 |
+
| GET | `/summary/{session_id}` | Get recent summary |
|
27 |
+
|
28 |
+
## 🧠 Agents
|
29 |
+
|
30 |
+
- `planner`: Plans steps
|
31 |
+
- `executor`: Executes simulated code
|
32 |
+
- `critic`: Reviews execution
|
knowledge/state.json
CHANGED
@@ -1 +1,19 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"knowledge_base": {
|
3 |
+
"name": "AutonomousAI_KnowledgeBase",
|
4 |
+
"description": "Used by the autonomous AI system for context and reasoning.",
|
5 |
+
"created_at": "2025-06-26T12:00:00Z",
|
6 |
+
"last_updated": "2025-06-26T12:00:00Z",
|
7 |
+
"total_documents": 0,
|
8 |
+
"total_tokens": 0,
|
9 |
+
"embedding_model": "sentence-transformers/all-MiniLM-L6-v2",
|
10 |
+
"vector_store": {
|
11 |
+
"type": "FAISS",
|
12 |
+
"index_file": "vector_index/faiss.index",
|
13 |
+
"dimension": 384,
|
14 |
+
"metric": "cosine"
|
15 |
+
},
|
16 |
+
"memory_enabled": true,
|
17 |
+
"status": "initialized"
|
18 |
+
}
|
19 |
+
}
|
memory.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
-
import json
|
2 |
-
import os
|
3 |
|
4 |
MEMORY_FILE = "memory.json"
|
5 |
|
@@ -10,25 +9,19 @@ def init_memory():
|
|
10 |
with open(MEMORY_FILE, "r") as f:
|
11 |
return json.load(f)
|
12 |
|
13 |
-
def save_memory(
|
14 |
with open(MEMORY_FILE, "w") as f:
|
15 |
-
json.dump(
|
16 |
|
17 |
def add_to_memory(session_id, prompt, response):
|
18 |
memory = init_memory()
|
19 |
-
|
20 |
-
memory[session_id] = []
|
21 |
memory[session_id].append({"prompt": prompt, "response": response})
|
22 |
memory[session_id] = memory[session_id][-50:]
|
23 |
save_memory(memory)
|
24 |
|
25 |
def get_memory(session_id):
|
26 |
-
|
27 |
-
return memory.get(session_id, [])
|
28 |
-
|
29 |
-
def search_memory(query, memory):
|
30 |
-
# Placeholder: Return last few memory entries related to query (simple all for now)
|
31 |
-
return memory["texts"][-5:]
|
32 |
|
33 |
def get_summary(session_id, max_items=3):
|
34 |
history = get_memory(session_id)
|
|
|
1 |
+
import json, os
|
|
|
2 |
|
3 |
MEMORY_FILE = "memory.json"
|
4 |
|
|
|
9 |
with open(MEMORY_FILE, "r") as f:
|
10 |
return json.load(f)
|
11 |
|
12 |
+
def save_memory(memory):
|
13 |
with open(MEMORY_FILE, "w") as f:
|
14 |
+
json.dump(memory, f, indent=2)
|
15 |
|
16 |
def add_to_memory(session_id, prompt, response):
|
17 |
memory = init_memory()
|
18 |
+
memory.setdefault(session_id, [])
|
|
|
19 |
memory[session_id].append({"prompt": prompt, "response": response})
|
20 |
memory[session_id] = memory[session_id][-50:]
|
21 |
save_memory(memory)
|
22 |
|
23 |
def get_memory(session_id):
|
24 |
+
return init_memory().get(session_id, [])
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
def get_summary(session_id, max_items=3):
|
27 |
history = get_memory(session_id)
|
requirements.txt
CHANGED
@@ -1,10 +1,7 @@
|
|
1 |
fastapi
|
2 |
-
gradio
|
3 |
uvicorn
|
|
|
|
|
|
|
4 |
sentence-transformers
|
5 |
-
numpy
|
6 |
faiss-cpu
|
7 |
-
psutil
|
8 |
-
torch
|
9 |
-
transformers
|
10 |
-
ctransformers
|
|
|
1 |
fastapi
|
|
|
2 |
uvicorn
|
3 |
+
ctransformers
|
4 |
+
gradio
|
5 |
+
psutil
|
6 |
sentence-transformers
|
|
|
7 |
faiss-cpu
|
|
|
|
|
|
|
|
src/agents/critic.py
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
|
|
|
|
1 |
+
def review_result(step, result):
|
2 |
+
return f"Review passed for step: {step}"
|
src/agents/executor.py
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
|
|
|
|
1 |
+
def execute_step(step):
|
2 |
+
return f"Executed: {step} (simulated)"
|
src/agents/planner.py
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
|
|
|
|
1 |
+
def plan_task(goal, memory):
|
2 |
+
return [f"Analyze: {goal}", "Generate code", "Review & validate"]
|
src/core/cognitive_engine.py
CHANGED
@@ -1 +1,16 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class CognitiveEngine:
|
2 |
+
def __init__(self, model):
|
3 |
+
self.model = model
|
4 |
+
|
5 |
+
def identify_improvements(self, task_description):
|
6 |
+
prompt = f"Suggest improvements:\n\nTask: {task_description}"
|
7 |
+
return self.model(prompt).split("\n")
|
8 |
+
|
9 |
+
def generate_enhancements(self, improvements):
|
10 |
+
prompt = "Generate code for improvements:\n" + "\n".join(improvements)
|
11 |
+
return self.model(prompt)
|
12 |
+
|
13 |
+
def apply_enhancements(self, code):
|
14 |
+
print("Applying enhancements...")
|
15 |
+
print(code)
|
16 |
+
return True
|
src/utils/hf_packager.py
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
|
|
|
|
1 |
+
def create_snapshot():
|
2 |
+
return "https://huggingface.co/spaces/your-snapshot-url"
|
static/style.css
CHANGED
@@ -1,108 +1 @@
|
|
1 |
-
:
|
2 |
-
--primary: #4f46e5;
|
3 |
-
--secondary: #6366f1;
|
4 |
-
--success: #10b981;
|
5 |
-
--danger: #ef4444;
|
6 |
-
--warning: #f59e0b;
|
7 |
-
--card-bg: #ffffff;
|
8 |
-
--bg: #f8fafc;
|
9 |
-
--text: #1e293b;
|
10 |
-
}
|
11 |
-
|
12 |
-
body {
|
13 |
-
background-color: var(--bg);
|
14 |
-
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
15 |
-
margin: 0;
|
16 |
-
padding: 20px;
|
17 |
-
color: var(--text);
|
18 |
-
}
|
19 |
-
|
20 |
-
h1, h2, h3 {
|
21 |
-
color: var(--primary);
|
22 |
-
}
|
23 |
-
|
24 |
-
.tab {
|
25 |
-
background: var(--card-bg);
|
26 |
-
border-radius: 10px;
|
27 |
-
padding: 20px;
|
28 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
|
29 |
-
margin-bottom: 20px;
|
30 |
-
border: 1px solid #e2e8f0;
|
31 |
-
}
|
32 |
-
|
33 |
-
button {
|
34 |
-
background: var(--primary);
|
35 |
-
color: white;
|
36 |
-
border: none;
|
37 |
-
padding: 12px 24px;
|
38 |
-
border-radius: 8px;
|
39 |
-
cursor: pointer;
|
40 |
-
font-weight: 600;
|
41 |
-
transition: all 0.3s;
|
42 |
-
margin: 5px 0;
|
43 |
-
}
|
44 |
-
|
45 |
-
button:hover {
|
46 |
-
background: var(--secondary);
|
47 |
-
transform: translateY(-2px);
|
48 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
49 |
-
}
|
50 |
-
|
51 |
-
button.primary {
|
52 |
-
background: var(--success);
|
53 |
-
}
|
54 |
-
|
55 |
-
button.danger {
|
56 |
-
background: var(--danger);
|
57 |
-
}
|
58 |
-
|
59 |
-
textarea, input, .json-container, .code-container {
|
60 |
-
background: #f1f5f9;
|
61 |
-
border: 1px solid #cbd5e1;
|
62 |
-
border-radius: 8px;
|
63 |
-
padding: 15px;
|
64 |
-
margin: 10px 0;
|
65 |
-
width: 100%;
|
66 |
-
}
|
67 |
-
|
68 |
-
.code-container {
|
69 |
-
font-family: 'Fira Code', monospace;
|
70 |
-
white-space: pre-wrap;
|
71 |
-
}
|
72 |
-
|
73 |
-
.tabs {
|
74 |
-
display: flex;
|
75 |
-
margin-bottom: 20px;
|
76 |
-
border-bottom: 2px solid #e2e8f0;
|
77 |
-
}
|
78 |
-
|
79 |
-
.tab-button {
|
80 |
-
background: none;
|
81 |
-
color: var(--text);
|
82 |
-
border: none;
|
83 |
-
padding: 12px 20px;
|
84 |
-
border-radius: 0;
|
85 |
-
margin: 0;
|
86 |
-
}
|
87 |
-
|
88 |
-
.tab-button.active {
|
89 |
-
border-bottom: 3px solid var(--primary);
|
90 |
-
color: var(--primary);
|
91 |
-
font-weight: bold;
|
92 |
-
}
|
93 |
-
|
94 |
-
.row {
|
95 |
-
display: flex;
|
96 |
-
gap: 20px;
|
97 |
-
margin-bottom: 20px;
|
98 |
-
}
|
99 |
-
|
100 |
-
.column {
|
101 |
-
flex: 1;
|
102 |
-
}
|
103 |
-
|
104 |
-
@media (max-width: 768px) {
|
105 |
-
.row {
|
106 |
-
flex-direction: column;
|
107 |
-
}
|
108 |
-
}
|
|
|
1 |
+
body { font-family: sans-serif; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|