Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,73 @@
|
|
| 1 |
-
|
| 2 |
import os
|
| 3 |
-
from
|
| 4 |
-
from
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
return
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import os
|
| 3 |
+
from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool
|
| 4 |
+
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, StorageContext, load_index_from_storage
|
| 5 |
+
|
| 6 |
+
# --- 1. THE BRAIN (LLM Setup) ---
|
| 7 |
+
# Powered by Qwen 2.5 72B for high-tier reasoning
|
| 8 |
+
model = HfApiModel(model_id="Qwen/Qwen2.5-72B-Instruct", token=os.getenv("HF_TOKEN"))
|
| 9 |
+
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
|
| 10 |
+
|
| 11 |
+
st.set_page_config(page_title="TIA-ARCHITECT-CORE", page_icon="🧠", layout="wide")
|
| 12 |
+
|
| 13 |
+
# --- 2. THE MEMORY (RAG Intelligence) ---
|
| 14 |
+
INDEX_DIR = "./citadel_index"
|
| 15 |
+
DATA_DIR = "./ingested_core"
|
| 16 |
+
|
| 17 |
+
def initialize_memory():
|
| 18 |
+
if os.path.exists(DATA_DIR) and any(os.scandir(DATA_DIR)):
|
| 19 |
+
if not os.path.exists(INDEX_DIR):
|
| 20 |
+
documents = SimpleDirectoryReader(DATA_DIR).load_data()
|
| 21 |
+
index = VectorStoreIndex.from_documents(documents)
|
| 22 |
+
index.storage_context.persist(persist_dir=INDEX_DIR)
|
| 23 |
+
else:
|
| 24 |
+
storage_context = StorageContext.from_defaults(persist_dir=INDEX_DIR)
|
| 25 |
+
index = load_index_from_storage(storage_context)
|
| 26 |
+
return index
|
| 27 |
+
return None
|
| 28 |
+
|
| 29 |
+
citadel_memory = initialize_memory()
|
| 30 |
+
|
| 31 |
+
# --- 3. THE HUD (UI) ---
|
| 32 |
+
st.title("🧠 TIA-ARCHITECT-CORE: SOVEREIGN ORACLE")
|
| 33 |
+
st.subheader("777.1122 Alignment | Citadel Mesh Coordination")
|
| 34 |
+
|
| 35 |
+
with st.sidebar:
|
| 36 |
+
st.success("NODE ONLINE")
|
| 37 |
+
if citadel_memory:
|
| 38 |
+
st.info("📚 Librarian Memory: Phase-Locked")
|
| 39 |
+
else:
|
| 40 |
+
st.warning("⚠️ Memory Substrate: Awaiting Harvest")
|
| 41 |
+
|
| 42 |
+
st.markdown("---")
|
| 43 |
+
st.write("**Operational Districts:** D01 - D46")
|
| 44 |
+
|
| 45 |
+
# --- 4. THE INTERFACE (Where the AI helps you) ---
|
| 46 |
+
st.write("### 💬 Execute Command")
|
| 47 |
+
query = st.chat_input("Commander, what is our next objective?")
|
| 48 |
+
|
| 49 |
+
if query:
|
| 50 |
+
with st.chat_message("user"):
|
| 51 |
+
st.write(query)
|
| 52 |
+
|
| 53 |
+
with st.chat_message("assistant"):
|
| 54 |
+
st.write("🚀 *Consulting Citadel Mesh...*")
|
| 55 |
+
|
| 56 |
+
# Priority 1: Search RAG Memory if available
|
| 57 |
+
if citadel_memory:
|
| 58 |
+
query_engine = citadel_memory.as_query_engine()
|
| 59 |
+
context_response = query_engine.query(query)
|
| 60 |
+
st.markdown(f"**Citadel Memory:** {context_response}")
|
| 61 |
+
|
| 62 |
+
# Priority 2: Agentic Reasoning/Action
|
| 63 |
+
agent_response = agent.run(query)
|
| 64 |
+
st.write(agent_response)
|
| 65 |
+
|
| 66 |
+
# --- 5. TELEMETRY ---
|
| 67 |
+
with st.expander("📡 Node Telemetry"):
|
| 68 |
+
st.json({
|
| 69 |
+
"status": "OPERATOR_GRADE",
|
| 70 |
+
"alignment": "9,293",
|
| 71 |
+
"version": "v25.0.OMNI++",
|
| 72 |
+
"substrate": "Forever_Learning (321GB)"
|
| 73 |
+
})
|