Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +12 -25
- self_update.py +30 -0
app.py
CHANGED
@@ -8,7 +8,6 @@ import os, uuid
|
|
8 |
from memory import MemoryVectorStore
|
9 |
from auth import authorize
|
10 |
from session import init_session_db, create_session, log_interaction, get_session_logs
|
11 |
-
from diagnostics import run_diagnostics
|
12 |
|
13 |
import gradio as gr
|
14 |
from sentence_transformers import SentenceTransformer
|
@@ -20,32 +19,25 @@ index = faiss.IndexFlatL2(384)
|
|
20 |
memory_text = []
|
21 |
|
22 |
def autonomous_agent(input_text):
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
memory_text.append(input_text)
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
response = f"π€ Received: {input_text}
|
35 |
-
π§ No prior memory yet."
|
36 |
-
|
37 |
-
except Exception as e:
|
38 |
-
diag = run_diagnostics()
|
39 |
-
response = f"β Error: {str(e)}
|
40 |
-
π οΈ Diagnostics: {diag['status']}"
|
41 |
|
42 |
return response
|
43 |
|
44 |
ui = gr.Interface(fn=autonomous_agent, inputs="text", outputs="text", title="Autonomous AI Agent", description="Self-enhancing chatbot with vector memory.")
|
45 |
-
ui.launch()
|
46 |
|
47 |
app = FastAPI()
|
48 |
memory = MemoryVectorStore()
|
|
|
49 |
init_session_db()
|
50 |
|
51 |
app.add_middleware(
|
@@ -67,8 +59,7 @@ async def session_task(request: Request, x_api_key: str = Header(...)):
|
|
67 |
session_id = data.get("session_id", create_session(user))
|
68 |
memory.add(goal)
|
69 |
ideas = memory.search(goal)
|
70 |
-
|
71 |
-
result = f"[Goal]: {goal}\n[Related]: {ideas}\n[Response]: π§ working on it...\nπ οΈ System Status: {diag['status']}"
|
72 |
memory.add(result)
|
73 |
log_interaction(session_id, goal, result)
|
74 |
return {"session_id": session_id, "output": result}
|
@@ -77,8 +68,4 @@ async def session_task(request: Request, x_api_key: str = Header(...)):
|
|
77 |
def logs(sid: str):
|
78 |
return get_session_logs(sid)
|
79 |
|
80 |
-
@app.get("/diagnostics")
|
81 |
-
async def diagnostics():
|
82 |
-
return run_diagnostics()
|
83 |
-
|
84 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
|
8 |
from memory import MemoryVectorStore
|
9 |
from auth import authorize
|
10 |
from session import init_session_db, create_session, log_interaction, get_session_logs
|
|
|
11 |
|
12 |
import gradio as gr
|
13 |
from sentence_transformers import SentenceTransformer
|
|
|
19 |
memory_text = []
|
20 |
|
21 |
def autonomous_agent(input_text):
|
22 |
+
vec = model.encode([input_text])
|
23 |
+
index.add(vec)
|
24 |
+
memory_text.append(input_text)
|
|
|
25 |
|
26 |
+
if index.ntotal > 1:
|
27 |
+
D, I = index.search(vec, k=2)
|
28 |
+
related = memory_text[I[0][1]]
|
29 |
+
response = f"π§ Memory Match: {related}\nπ€ Working on: {input_text}"
|
30 |
+
else:
|
31 |
+
response = f"π€ Received: {input_text}\nπ§ No prior memory yet."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
return response
|
34 |
|
35 |
ui = gr.Interface(fn=autonomous_agent, inputs="text", outputs="text", title="Autonomous AI Agent", description="Self-enhancing chatbot with vector memory.")
|
36 |
+
ui.launch(share=False, inbrowser=False)
|
37 |
|
38 |
app = FastAPI()
|
39 |
memory = MemoryVectorStore()
|
40 |
+
|
41 |
init_session_db()
|
42 |
|
43 |
app.add_middleware(
|
|
|
59 |
session_id = data.get("session_id", create_session(user))
|
60 |
memory.add(goal)
|
61 |
ideas = memory.search(goal)
|
62 |
+
result = f"[Goal]: {goal}\n[Related]: {ideas}\n[Response]: π§ working on it..."
|
|
|
63 |
memory.add(result)
|
64 |
log_interaction(session_id, goal, result)
|
65 |
return {"session_id": session_id, "output": result}
|
|
|
68 |
def logs(sid: str):
|
69 |
return get_session_logs(sid)
|
70 |
|
|
|
|
|
|
|
|
|
71 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
self_update.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import os
|
3 |
+
import importlib.util
|
4 |
+
import requests
|
5 |
+
|
6 |
+
REPO_RAW_URL = "https://raw.githubusercontent.com/Leonydis137/Autonomous-AI/main/" # adjust if needed
|
7 |
+
|
8 |
+
def download_file(filename):
|
9 |
+
url = REPO_RAW_URL + filename
|
10 |
+
response = requests.get(url)
|
11 |
+
if response.status_code == 200:
|
12 |
+
with open(filename, "w", encoding='utf-8') as f:
|
13 |
+
f.write(response.text)
|
14 |
+
return f"β
Updated {filename}"
|
15 |
+
else:
|
16 |
+
return f"β Failed to fetch {filename}"
|
17 |
+
|
18 |
+
def self_update():
|
19 |
+
core_files = ["app.py", "memory.py", "diagnostics.py"]
|
20 |
+
results = [download_file(f) for f in core_files]
|
21 |
+
return {"status": "π Update check complete", "results": results}
|
22 |
+
|
23 |
+
def apply_hot_reload():
|
24 |
+
files = ["diagnostics", "memory"]
|
25 |
+
reloaded = []
|
26 |
+
for mod_name in files:
|
27 |
+
if mod_name in globals():
|
28 |
+
importlib.reload(globals()[mod_name])
|
29 |
+
reloaded.append(mod_name)
|
30 |
+
return {"hot_reload": reloaded}
|