Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,10 +8,35 @@ from memory import MemoryVectorStore
|
|
| 8 |
from auth import authorize
|
| 9 |
from session import init_session_db, create_session, log_interaction, get_session_logs
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
init_session_db()
|
| 17 |
|
|
|
|
| 8 |
from auth import authorize
|
| 9 |
from session import init_session_db, create_session, log_interaction, get_session_logs
|
| 10 |
|
| 11 |
+
import gradio as gr
|
| 12 |
+
from sentence_transformers import SentenceTransformer
|
| 13 |
+
import faiss
|
| 14 |
+
import numpy as np
|
| 15 |
|
| 16 |
+
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 17 |
+
index = faiss.IndexFlatL2(384)
|
| 18 |
+
memory_text = []
|
| 19 |
+
|
| 20 |
+
def autonomous_agent(input_text):
|
| 21 |
+
vec = model.encode([input_text])
|
| 22 |
+
index.add(vec)
|
| 23 |
+
memory_text.append(input_text)
|
| 24 |
+
|
| 25 |
+
if index.ntotal > 1:
|
| 26 |
+
D, I = index.search(vec, k=2)
|
| 27 |
+
related = memory_text[I[0][1]]
|
| 28 |
+
response = f"🧠 Memory Match: {related}\n🤖 Working on: {input_text}"
|
| 29 |
+
else:
|
| 30 |
+
response = f"🤖 Received: {input_text}\n🧠 No prior memory yet."
|
| 31 |
+
|
| 32 |
+
return response
|
| 33 |
+
|
| 34 |
+
ui = gr.Interface(fn=autonomous_agent, inputs="text", outputs="text", title="Autonomous AI Agent", description="Self-enhancing chatbot with vector memory.")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
from gradio.routes import mount_gradio_app
|
| 38 |
+
# Mount Gradio app on FastAPI
|
| 39 |
+
app = mount_gradio_app(app, ui, path='/gradio')
|
| 40 |
|
| 41 |
init_session_db()
|
| 42 |
|