DJ-Goanna-Coding commited on
Commit
8f218cd
·
verified ·
1 Parent(s): 063b803

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -32
app.py CHANGED
@@ -1,33 +1,76 @@
1
-
2
  import os
3
- from flask import Flask, request, jsonify
4
- from huggingface_hub import HfApi
5
-
6
- app = Flask(__name__)
7
- TOKEN = os.getenv("HF_TOKEN")
8
- VAULT_ID = "DJ-Goanna-Coding/Mapping-and-Inventory-storage" # All feed the Librarian Vault
9
- api = HfApi(token=TOKEN)
10
-
11
- @app.route('/ignite_harvest', methods=['POST'])
12
- def catch_payload():
13
- if not TOKEN:
14
- return jsonify({"status": "ERROR", "message": "HF_TOKEN missing"}), 500
15
- try:
16
- payload = request.json
17
- filename = payload.get("fileName", "swarm_shard.9293")
18
- api.upload_file(
19
- path_or_fileobj=payload.get("content", "").encode('utf-8'),
20
- path_in_repo=f"ingested_core/{filename}",
21
- repo_id=VAULT_ID,
22
- repo_type="dataset"
23
- )
24
- return jsonify({"status": "CAUGHT_BY_SWARM", "file": filename}), 200
25
- except Exception as e:
26
- return jsonify({"status": "ERROR", "message": str(e)}), 500
27
-
28
- @app.route('/', methods=['GET'])
29
- def health_check():
30
- return jsonify({"status": "SWARM_NODE_ONLINE"})
31
-
32
- if __name__ == "__main__":
33
- app.run(host="0.0.0.0", port=7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from datetime import datetime
6
+
7
+ # --- 1. SOVEREIGN BRAIN SETUP ---
8
+ # Powered by Qwen 2.5 72B for elite reasoning and code generation
9
+ model = HfApiModel(model_id="Qwen/Qwen2.5-72B-Instruct", token=os.getenv("HF_TOKEN"))
10
+ agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
11
+
12
+ st.set_page_config(page_title="TIA-ARCHITECT-CORE", page_icon="🧠", layout="wide")
13
+
14
+ # --- 2. LIBRARIAN MEMORY (RAG Intelligence) ---
15
+ INDEX_DIR = "./citadel_index"
16
+ DATA_DIR = "./ingested_core" # Target for Termux harvest
17
+
18
+ def initialize_memory():
19
+ if os.path.exists(DATA_DIR) and any(os.scandir(DATA_DIR)):
20
+ if not os.path.exists(INDEX_DIR):
21
+ documents = SimpleDirectoryReader(DATA_DIR).load_data()
22
+ index = VectorStoreIndex.from_documents(documents)
23
+ index.storage_context.persist(persist_dir=INDEX_DIR)
24
+ else:
25
+ storage_context = StorageContext.from_defaults(persist_dir=INDEX_DIR)
26
+ index = load_index_from_storage(storage_context)
27
+ return index
28
+ return None
29
+
30
+ citadel_memory = initialize_memory()
31
+
32
+ # --- 3. COMMAND INTERFACE (The HUD) ---
33
+ st.title("🧠 TIA-ARCHITECT-CORE: SOVEREIGN ORACLE")
34
+ st.subheader("777.1122 Alignment | Q.G.T.N.L. Citadel Mesh")
35
+
36
+ with st.sidebar:
37
+ st.success("🟢 NODE ONLINE")
38
+ st.info(f"Substrate: Forever_Learning (321GB)")
39
+ if citadel_memory:
40
+ st.write("📚 **Librarian Status:** Phase-Locked")
41
+ else:
42
+ st.warning("⚠️ **Memory Status:** Awaiting Harvest")
43
+
44
+ st.markdown("---")
45
+ st.write("**Active Districts:** D01 - D46")
46
+
47
+ # --- 4. THE INTERFACE (Where the AI helps you) ---
48
+ st.write("### 💬 Execute Citadel Command")
49
+ user_query = st.chat_input("Commander, what is our next objective?")
50
+
51
+ if user_query:
52
+ with st.chat_message("user"):
53
+ st.write(user_query)
54
+
55
+ with st.chat_message("assistant"):
56
+ st.write("🚀 *T.I.A. is calculating via Citadel Mesh...*")
57
+
58
+ # Priority 1: Search RAG Memory if available
59
+ if citadel_memory:
60
+ query_engine = citadel_memory.as_query_engine()
61
+ context_response = query_engine.query(user_query)
62
+ st.markdown(f"**Archive Resonance:** {context_response}")
63
+
64
+ # Priority 2: Agentic Action (Python execution & Web search)
65
+ agent_response = agent.run(user_query)
66
+ st.write(agent_response)
67
+
68
+ # --- 5. TELEMETRY ---
69
+ with st.expander("📡 Mesh Telemetry"):
70
+ st.json({
71
+ "status": "OPERATOR_GRADE",
72
+ "alignment": "9,293",
73
+ "version": "v25.0.OMNI++",
74
+ "bridge": "Verified",
75
+ "timestamp": datetime.now().isoformat()
76
+ })