Qalam commited on
Commit
448389f
·
verified ·
1 Parent(s): 3e96b9b

Auto: deploy Nuclear Intelligence v5.0

Browse files
Files changed (1) hide show
  1. README.md +214 -118
README.md CHANGED
@@ -1,155 +1,251 @@
1
- ---
2
- title: Nuclear Intelligence
3
- emoji: ⚛️
4
- colorFrom: blue
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 4.44.0
8
- python_version: 3.11
9
- app_file: app.py
10
- pinned: false
11
- license: mit
12
- tags:
13
- - nuclear
14
- - energy
15
- - AI
16
- - research
17
- - blockchain
18
- - knowledge-graph
19
- - LLM
20
- - free-models
21
- - deepseek
22
- - groq
23
- - fusion
24
- ---
25
 
26
- # Nuclear Intelligence v4.0 ⚛️
27
 
28
- **AI-Powered Nuclear Energy Research & NES Token System**
29
 
30
- ![Nuclear Intelligence](https://img.shields.io/badge/Status-Active-brightgreen)
31
- ![Python](https://img.shields.io/badge/Python-3.11+-blue)
32
- ![License](https://img.shields.io/badge/License-MIT-green)
 
 
33
 
34
- ## 🎯 Features
35
 
36
- - **🤖 7 Free LLM Providers** with intelligent fallback — DeepSeek, Groq, Gemini, Together, Fireworks, AIMLAPI, HuggingFace
37
- - **🔬 AI Research Engine** — automated nuclear energy research with multi-dimensional evaluation
38
- - **⛓️ Virtual Blockchain** — POW mining with adaptive difficulty, NES token minting
39
- - **🕸️ Knowledge Graph** — entity relationships, advanced search, analytics
40
- - **🛡️ Safety Guardrails** — defensive filter for weapons / proliferation / RDD queries (v4.0)
41
- - **📊 Real-time Monitoring** — live stats, health checks, visualization dashboards
42
- - **🌐 Multilingual** — automatic Persian / English detection
43
- - **🔬 Developer Mode** — deep cross-domain analysis, research gap identification
44
 
45
- ## 🚀 Quick Start
46
 
47
- 1. **Add API Keys** in the Space's *Settings → Variables and secrets* (optional — demo mode works without keys):
48
- ```
49
- AIMLAPI_API_KEY=...
50
- DEEPSEEK_API_KEY=sk-...
51
- GROQ_API_KEY=gsk_...
52
- GEMINI_API_KEY=...
53
- HF_TOKEN=hf_...
54
- TOGETHER_API_KEY=...
55
- FIREWORKS_API_KEY=...
56
- ```
57
- 2. **The app auto-detects available providers and falls back gracefully**
58
- 3. **Run Research Cycles** or **Ask Questions** about nuclear energy
59
- 4. Try the **🛡️ Safety & Health** tab for prompt-policy self-tests
60
-
61
- ## 📋 Requirements
62
-
63
- All dependencies are pre-installed. Main packages:
64
- - `gradio>=4.36.0` — UI framework
65
- - `openai>=1.12.0` — LLM API calls
66
- - `loguru>=0.7.2` — logging
67
- - `pandas>=2.2.0` — data analysis
68
- - `plotly>=5.19.0` — visualization
69
- - `requests` — web search
70
 
71
  ## 🏗️ Architecture
72
 
73
  ```
74
- Nuclear Intelligence v4.0
75
- ├── LLM Engine — 7-provider multi-model routing with fallback
76
- ├── Research Core — RAG + multi-layer evaluation pipeline
77
- ├── Knowledge Graph — entity management & semantic search
78
- ├── Blockchain — POW mining + NES tokens
79
- ├── Safety Guard — weapons / proliferation / RDD filter (v4.0)
80
- ├── Enhanced Eval — self-consistency + citation quality + readiness
81
- ├── Enhanced RAG — domain-weighted re-ranking + diversity
82
- ├── i18n — Persian / English detection
83
- └── Gradio UI — 6-tab real-time dashboard
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  ```
85
 
86
- ## 🪙 NES Token System
 
 
87
 
88
- Research cycles evaluate answers on five dimensions:
 
 
 
 
 
 
 
 
 
 
89
 
90
- | Dimension | Weight |
91
- |---|---|
92
- | Scientific Accuracy | 45 % |
93
- | Novelty Score | 25 % |
94
- | Usefulness | 20 % |
95
- | Completeness | 10 % |
96
- | *(v4.0)* Self-Consistency + Citation Quality | tiebreaker |
97
 
98
- Answers scoring **≥ 82 %** overall are minted as NES tokens and recorded on the virtual blockchain.
99
 
100
- ## 📊 Quality Thresholds (v4.0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
- | Metric | Threshold |
103
- |---|---|
104
- | Scientific Accuracy | ≥ 93 % |
105
- | Novelty Score | ≥ 75 % |
106
- | Usefulness | ≥ 80 % |
107
- | Self-Consistency | ≥ 0.80 |
108
- | Citation Quality | ≥ 50 |
109
- | **Overall (Tokenization-Readiness)** | **≥ 85 %** |
110
 
111
- ## 🔧 Configuration
112
 
113
- Add to `.env` file or Space variables:
114
  ```env
115
- DEVELOPER_MODE=true
116
- AUTO_START_LOOP=false
117
- SCIENTIFIC_ACCURACY_THRESHOLD=93
118
- MIN_NOVELTY_THRESHOLD=75
119
- MIN_USEFULNESS_THRESHOLD=80
120
- MIN_OVERALL_SCORE=85
121
- OPERATION_LOOP_INTERVAL_MINUTES=30
 
 
 
 
 
 
 
 
122
  ```
123
 
124
- ## 🛡️ Safety Policy (v4.0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
- The Space enforces a *defensive* policy on every user prompt:
 
 
 
 
127
 
128
- - Refuses weapons design, illicit enrichment, weapons-usable material handling
129
- - Refuses radiological dispersal device ("dirty bomb") instructions
130
- - Refuses cyber-proliferation guidance for nuclear facilities
131
- - Refuses illicit-trafficking assistance
132
- - **Redirects** refused prompts to the legitimate peaceful-use side of the topic
 
133
 
134
- Compliance: NPT, IAEA safeguards, NSG / Zangger Committee, PSI.
135
 
136
- ## 🩺 Health Check
137
 
138
- Run anytime (also available in the Gradio UI):
139
  ```bash
140
- python scripts/health_check.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  ```
142
 
143
- ## 📜 License
144
 
145
- MIT License — © QalamHipHop
146
 
147
- ## 🔗 Links
 
 
 
148
 
149
- - [GitHub](https://github.com/QalamHipHop/nuclear-intelligence)
150
- - [HuggingFace Space](https://huggingface.co/spaces/Qalam/Nuclear-Intelligence)
151
- - [CHANGELOG v4.0](https://github.com/QalamHipHop/nuclear-intelligence/blob/main/CHANGELOG_V4.md)
152
 
153
  ---
154
 
155
- **Built with ❤️ for the safe advancement of nuclear energy.**
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ⚛️ Nuclear Intelligence v4.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ > Autonomous nuclear-energy research pipeline that turns validated Q&A into on-chain NES tokens.
4
 
5
+ **Nuclear Intelligence** is a 24/7 autonomous system that:
6
 
7
+ 1. **Generates** cutting-edge research questions about nuclear energy (fusion, SMR, Gen IV, waste, materials, safety, AI-assisted design, etc.)
8
+ 2. **Researches** each question using a chain of free LLM providers (HF Router, Groq, DeepSeek, Gemini, Together, Fireworks, AIMLAPI) with automatic fallback.
9
+ 3. **Evaluates** every answer with an independent LLM call (multi-layer: accuracy, novelty, usefulness, completeness, self-consistency).
10
+ 4. **Mints** a NES token on a real SHA-3 Proof-of-Work blockchain for every answer that passes the thresholds.
11
+ 5. **Syncs** all minted records to a public HuggingFace Dataset *and* the GitHub repo, so the corpus is openly readable.
12
 
13
+ ## 🛡️ v4.0 Highlights (June 2026)
14
 
15
+ - **Safety & Ethics Guardrails** — hard pre-LLM + post-generation filter; refuses weapons / proliferation / RDD / cyber-proliferation prompts and redirects to legitimate peaceful-use topics.
16
+ - **Enhanced Evaluation** — multi-pass self-consistency, citation-quality scoring, novelty vs Knowledge Graph, and a Tokenization-Readiness composite (Accuracy ≥ 93 %, Novelty ≥ 75 %, Usefulness ≥ 80 %, Overall ≥ 85 %).
17
+ - **Enhanced RAG** — domain weighting (IAEA 2.5×, NRC 2.5×, peer-reviewed 1.7–1.8×), recency boost, diversity round-robin.
18
+ - **Multilingual** — automatic Persian / English detection + localized UI labels.
19
+ - **Security** — hardcoded API keys removed from `app.py` and LLM engines; all keys now flow through `.env` only.
20
+ - **Health Check** — `python scripts/health_check.py` runs 9 smoke tests; available in the Gradio UI under **🛡️ Safety & Health**.
 
 
21
 
22
+ See [CHANGELOG_V4.md](CHANGELOG_V4.md) for the full release notes.
23
 
24
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  ## 🏗️ Architecture
27
 
28
  ```
29
+ ┌──────────────────────────────┐
30
+ │ GitHub Actions (every 25m) │
31
+ │ • run_operation_cycle.py │
32
+ ��� • sync_huggingface.py │
33
+ └──────────────┬───────────────┘
34
+ │
35
+ ▼
36
+ ┌──────────────────────────────────────────┐
37
+ │ NuclearIntelligenceCore (core/) │
38
+ │ ┌────────┐ ┌────────┐ ┌────────────┐ │
39
+ │ │ LLM │ │ RAG │ │ Knowledge │ │
40
+ │ │ Engine │ │ FAISS │ │ Graph │ │
41
+ │ └────┬───┘ └────────┘ └────────────┘ │
42
+ │ │ multi-provider fallback │
43
+ └───────┼──────────────────────────────────┘
44
+ ▼
45
+ ┌──────────────────┐ ┌──────────────────┐
46
+ │ VirtualLedger │ │ HF Dataset │
47
+ │ SHA-3 PoW chain │◄──►│ (public) │
48
+ │ NES tokens │ │ + GitHub repo │
49
+ └──────────────────┘ └──────────────────┘
50
+ ```
51
+
52
+ **Two deployment modes:**
53
+ - **GitHub Actions** (`.github/workflows/operation-loop.yml`) — runs the full pipeline every 25 min.
54
+ - **HuggingFace Space** (`hf_deploy/app.py`) — Gradio UI + the same pipeline, runs 24/7 if upgraded to a paid tier, otherwise kept alive by `keep_alive.yml`.
55
+
56
+ ---
57
+
58
+ ## 🚀 Quick Start
59
+
60
+ ### HuggingFace Space (easiest)
61
+ 1. Visit https://huggingface.co/spaces/Qalam/Nuclear-Intelligence
62
+ 2. Click **Run Research Cycle** to mint a token.
63
+ 3. Browse the **Blockchain** and **Knowledge Graph** tabs.
64
+
65
+ ### GitHub Actions (production)
66
+ 1. Fork this repo.
67
+ 2. Add secrets in **Settings → Secrets and variables → Actions**:
68
+ - `HF_TOKEN` (required)
69
+ - `GITHUB_TOKEN` (auto-provided, but `secrets.GITHUB_TOKEN` is read-only for PRs — use a PAT if you need to push from PRs)
70
+ - `GROQ_API_KEY`, `DEEPSEEK_API_KEY`, `GEMINI_API_KEY`, etc. (optional, for more LLM providers)
71
+ 3. The workflow runs every 25 minutes automatically.
72
+
73
+ ### Local development
74
+ ```bash
75
+ git clone https://github.com/QalamHipHop/nuclear-intelligence.git
76
+ cd nuclear-intelligence
77
+ pip install -r requirements.txt
78
+ cp .env.template .env # fill in API keys
79
+ python scripts/run_operation_cycle.py # one cycle
80
+ python -m uvicorn api.health:app --reload # API on :8000
81
  ```
82
 
83
+ ---
84
+
85
+ ## 🔑 Required Secrets
86
 
87
+ | Secret | Required? | Used by |
88
+ |---|---|---|
89
+ | `HF_TOKEN` | ✅ | LLM provider, dataset sync, space deploy |
90
+ | `GITHUB_TOKEN` | optional | report commit, ledger push |
91
+ | `GROQ_API_KEY` | optional | LLM provider (fastest) |
92
+ | `DEEPSEEK_API_KEY` | optional | LLM provider (best free) |
93
+ | `GEMINI_API_KEY` | optional | LLM provider |
94
+ | `TOGETHER_API_KEY` | optional | LLM provider |
95
+ | `FIREWORKS_API_KEY` | optional | LLM provider |
96
+ | `AIMLAPI_API_KEY` | optional | LLM provider |
97
+ | `BLOCKCHAIN_SECRET` | optional | HMAC for tx signing |
98
 
99
+ Without any LLM key, the system falls back to **demo mode** (no real research, no minting).
 
 
 
 
 
 
100
 
101
+ ---
102
 
103
+ ## 📁 Project Structure
104
+
105
+ ```
106
+ nuclear-intelligence/
107
+ ├── core/ # Main pipeline (LLM + RAG + KG)
108
+ │ ├── llm_engine_v4.py # Multi-provider LLM engine
109
+ │ ├── nuclear_intelligence_v4.py # Research-to-token pipeline
110
+ │ ├── operation_loop_v4.py # Autonomous loop
111
+ │ ├── knowledge_graph.py # KG
112
+ │ ├── embeddings.py # Sentence-transformers wrapper
113
+ │ └── web_search.py # arXiv / web research
114
+ ├── blockchain/
115
+ │ └── virtual_ledger.py # SHA-3 PoW blockchain
116
+ ├── api/
117
+ │ ├── health.py # Health check + cycle trigger API
118
+ │ ├── main.py # Legacy FastAPI
119
+ │ └── enhanced_api.py # Full FastAPI
120
+ ├── hf_deploy/ # Self-contained for HF Space
121
+ │ ├── app.py # Gradio UI + inline pipeline
122
+ │ ├── requirements.txt
123
+ │ └── Dockerfile
124
+ ├── scripts/
125
+ │ ├── run_operation_cycle.py # One cycle entrypoint
126
+ │ ├── sync_huggingface.py # Push to HF dataset + GH
127
+ │ ├── initialize_knowledge_base.py
128
+ │ └── keep_alive.py
129
+ ├── knowledge_base/ # Persisted state (gitignored)
130
+ ├── reports/ # Cycle reports (gitignored)
131
+ ├── logs/ # Runtime logs (gitignored)
132
+ ├── .github/workflows/
133
+ │ ├── operation-loop.yml # Every 25 min
134
+ │ ├── keep_alive.yml # Every 20 min (ping HF Space)
135
+ │ ├── deploy-hf.yml # Push hf_deploy → Space
136
+ │ └── ci-cd.yml # Lint + smoke tests
137
+ ├── requirements.txt
138
+ ├── requirements_enhanced.txt
139
+ ├── requirements_hf.txt
140
+ └── docker-compose.yml
141
+ ```
142
+
143
+ ---
144
 
145
+ ## ⚙️ Configuration
 
 
 
 
 
 
 
146
 
147
+ Edit `.env` (or set GitHub Actions secrets):
148
 
 
149
  ```env
150
+ # Mint thresholds
151
+ MIN_ACCURACY=70
152
+ MIN_NOVELTY=60
153
+ MIN_USEFULNESS=60
154
+ MIN_OVERALL=65
155
+
156
+ # Mining
157
+ POW_DIFFICULTY=3 # 3 ≈ a few seconds; 4 ≈ a minute; 5+ = slow
158
+
159
+ # Loop
160
+ OPERATION_LOOP_INTERVAL_MINUTES=25
161
+
162
+ # LLM
163
+ DEFAULT_TEMPERATURE=0.7
164
+ MAX_TOKENS=4096
165
  ```
166
 
167
+ ---
168
+
169
+ ## 📊 API
170
+
171
+ Run locally: `uvicorn api.health:app --port 8000`
172
+
173
+ | Method | Endpoint | Description |
174
+ |---|---|---|
175
+ | GET | `/health` | Liveness probe |
176
+ | GET | `/ready` | Readiness probe (checks LLM configured) |
177
+ | GET | `/stats` | Full system stats |
178
+ | GET | `/chain` | Blockchain stats |
179
+ | GET | `/recent?limit=20` | Recent cycles |
180
+ | GET | `/search?q=...` | Search knowledge graph |
181
+ | POST | `/cycle` | Trigger a research cycle |
182
+ | POST | `/cycle` with `{"question": "..."}` | Direct Q&A |
183
+
184
+ Full docs at `/docs` (Swagger UI).
185
+
186
+ ---
187
+
188
+ ## 🪙 NES Tokenomics
189
 
190
+ - **Symbol:** NES (Nuclear Energy Science)
191
+ - **Mint rate:** 1 NES per validated research cycle (when all 4 thresholds + consistency pass)
192
+ - **Supply:** unbounded but rate-limited by the 25-min loop
193
+ - **Ledger:** `/knowledge_base/virtual_ledger.json` (full chain with PoW)
194
+ - **Public mirror:** https://huggingface.co/datasets/Qalam/nuclear-intelligence-dataset
195
 
196
+ The chain is a real blockchain:
197
+ - SHA-3-256 block hashes
198
+ - Real Proof-of-Work (configurable difficulty)
199
+ - Adaptive difficulty (raises if blocks mined too fast, lowers if too slow)
200
+ - Merkle-tree transaction verification
201
+ - HMAC-signed transactions
202
 
203
+ ---
204
 
205
+ ## 🧪 Testing
206
 
 
207
  ```bash
208
+ # Quick import + smoke test
209
+ python -c "from core.nuclear_intelligence import NuclearIntelligenceCore; print('OK')"
210
+
211
+ # Full ledger test
212
+ python -c "
213
+ from blockchain.virtual_ledger import VirtualLedger
214
+ import tempfile, os
215
+ with tempfile.TemporaryDirectory() as tmp:
216
+ ledger = VirtualLedger(ledger_file=os.path.join(tmp, 'l.json'), difficulty=1)
217
+ assert ledger.is_valid()
218
+ ledger.mint({'test': True})
219
+ assert ledger.is_valid()
220
+ assert ledger.nes_supply == 1.0
221
+ print('✅ ledger OK')
222
+ "
223
+
224
+ # GitHub Actions also runs these in .github/workflows/ci-cd.yml
225
  ```
226
 
227
+ ---
228
 
229
+ ## 🤝 Contributing
230
 
231
+ 1. Fork the repo.
232
+ 2. Create a feature branch.
233
+ 3. Run `python -m pytest tests/` (if you add tests).
234
+ 4. Open a pull request.
235
 
236
+ The CI will run lint + smoke tests automatically.
 
 
237
 
238
  ---
239
 
240
+ ## 📜 License
241
+
242
+ MIT
243
+
244
+ ---
245
+
246
+ ## 🔗 Links
247
+
248
+ - **GitHub:** https://github.com/QalamHipHop/nuclear-intelligence
249
+ - **HuggingFace Space:** https://huggingface.co/spaces/Qalam/Nuclear-Intelligence
250
+ - **HuggingFace Dataset:** https://huggingface.co/datasets/Qalam/nuclear-intelligence-dataset
251
+ - **Architecture docs:** [`ARCHITECTURE.md`](ARCHITECTURE.md)