Spaces:
Running
Running
Auto: deploy Nuclear Intelligence v5.0
Browse files- app.py +93 -74
- requirements.txt +10 -12
app.py
CHANGED
|
@@ -31,10 +31,12 @@ PORT = int(os.getenv("GRADIO_PORT", "7860"))
|
|
| 31 |
|
| 32 |
# ─── Try Imports with Fallbacks ─────────────────────────────────
|
| 33 |
gradio_available = False
|
|
|
|
| 34 |
try:
|
| 35 |
import gradio as gr
|
| 36 |
import pandas as pd
|
| 37 |
-
from loguru import logger
|
|
|
|
| 38 |
import plotly.express as px
|
| 39 |
gradio_available = True
|
| 40 |
except ImportError as e:
|
|
@@ -48,6 +50,16 @@ try:
|
|
| 48 |
except Exception:
|
| 49 |
pass
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# ═══════════════════════════════════════════════════════════════════
|
| 53 |
# LLM ENGINE — Real multi-provider with intelligent fallback
|
|
@@ -1404,80 +1416,87 @@ CSS = """
|
|
| 1404 |
.rejected { color: #ef4444; }
|
| 1405 |
"""
|
| 1406 |
|
| 1407 |
-
|
| 1408 |
-
|
| 1409 |
-
gr.
|
| 1410 |
-
"
|
| 1411 |
-
|
| 1412 |
-
|
|
|
|
|
|
|
| 1413 |
|
| 1414 |
-
|
| 1415 |
-
|
| 1416 |
-
|
| 1417 |
-
|
| 1418 |
-
|
| 1419 |
-
|
| 1420 |
-
|
| 1421 |
-
|
| 1422 |
-
|
| 1423 |
-
|
| 1424 |
-
|
| 1425 |
-
|
| 1426 |
-
|
| 1427 |
-
|
| 1428 |
-
|
| 1429 |
-
|
| 1430 |
-
|
| 1431 |
-
|
| 1432 |
-
|
| 1433 |
-
|
| 1434 |
-
|
| 1435 |
-
|
| 1436 |
-
|
| 1437 |
-
|
| 1438 |
-
|
| 1439 |
-
|
| 1440 |
-
|
| 1441 |
-
|
| 1442 |
-
|
| 1443 |
-
|
| 1444 |
-
|
| 1445 |
-
|
| 1446 |
-
|
| 1447 |
-
|
| 1448 |
-
|
| 1449 |
-
|
| 1450 |
-
|
| 1451 |
-
|
| 1452 |
-
|
| 1453 |
-
|
| 1454 |
-
|
| 1455 |
-
|
| 1456 |
-
|
| 1457 |
-
|
| 1458 |
-
|
| 1459 |
-
|
| 1460 |
-
|
| 1461 |
-
|
| 1462 |
-
|
| 1463 |
-
|
| 1464 |
-
|
| 1465 |
-
|
| 1466 |
-
|
| 1467 |
-
|
| 1468 |
-
|
| 1469 |
-
|
| 1470 |
-
|
| 1471 |
-
|
| 1472 |
-
|
| 1473 |
-
|
| 1474 |
-
|
| 1475 |
-
|
|
|
|
|
|
|
| 1476 |
|
| 1477 |
|
| 1478 |
if __name__ == "__main__":
|
| 1479 |
-
|
| 1480 |
-
|
| 1481 |
-
|
| 1482 |
-
|
| 1483 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# ─── Try Imports with Fallbacks ─────────────────────────────────
|
| 33 |
gradio_available = False
|
| 34 |
+
logger = None # explicit init to satisfy NameError-on-attribute paths
|
| 35 |
try:
|
| 36 |
import gradio as gr
|
| 37 |
import pandas as pd
|
| 38 |
+
from loguru import logger as _loguru_logger
|
| 39 |
+
logger = _loguru_logger
|
| 40 |
import plotly.express as px
|
| 41 |
gradio_available = True
|
| 42 |
except ImportError as e:
|
|
|
|
| 50 |
except Exception:
|
| 51 |
pass
|
| 52 |
|
| 53 |
+
# ── Logger fallback (must exist even if loguru import failed) ────
|
| 54 |
+
if logger is None:
|
| 55 |
+
import logging as _logging
|
| 56 |
+
logger = _logging.getLogger("hf_deploy")
|
| 57 |
+
if not logger.handlers:
|
| 58 |
+
_h = _logging.StreamHandler()
|
| 59 |
+
_h.setFormatter(_logging.Formatter("%(asctime)s | %(levelname)s | %(message)s"))
|
| 60 |
+
logger.addHandler(_h)
|
| 61 |
+
logger.setLevel(_logging.INFO)
|
| 62 |
+
|
| 63 |
|
| 64 |
# ═══════════════════════════════════════════════════════════════════
|
| 65 |
# LLM ENGINE — Real multi-provider with intelligent fallback
|
|
|
|
| 1416 |
.rejected { color: #ef4444; }
|
| 1417 |
"""
|
| 1418 |
|
| 1419 |
+
demo = None
|
| 1420 |
+
if gradio_available:
|
| 1421 |
+
with gr.Blocks(title="Nuclear Intelligence v5.0") as demo:
|
| 1422 |
+
gr.Markdown("# ⚛️ Nuclear Intelligence v5.0", elem_id="title")
|
| 1423 |
+
gr.Markdown(
|
| 1424 |
+
"**Autonomous nuclear energy research → multi-layer evaluation → SHA-3 PoW mining → NES token**\n\n"
|
| 1425 |
+
"All research is produced by real LLMs. Evaluation is independent. Mining is real Proof-of-Work."
|
| 1426 |
+
)
|
| 1427 |
|
| 1428 |
+
with gr.Row():
|
| 1429 |
+
with gr.Column(scale=1):
|
| 1430 |
+
stats_box = gr.Markdown(get_system_stats)
|
| 1431 |
+
refresh_stats = gr.Button("🔄 Refresh Stats", variant="secondary")
|
| 1432 |
+
export_btn = gr.Button("💾 Export State")
|
| 1433 |
+
export_out = gr.Markdown()
|
| 1434 |
+
|
| 1435 |
+
with gr.Accordion("🔌 LLM Engine", open=False):
|
| 1436 |
+
llm_status = gr.Markdown(get_llm_status)
|
| 1437 |
+
refresh_llm = gr.Button("📡 Check Providers")
|
| 1438 |
+
|
| 1439 |
+
with gr.Column(scale=3):
|
| 1440 |
+
with gr.Tabs():
|
| 1441 |
+
with gr.Tab("🚀 Research Center"):
|
| 1442 |
+
with gr.Row():
|
| 1443 |
+
run_btn = gr.Button("🚀 Run Research Cycle", variant="primary")
|
| 1444 |
+
dev_chk = gr.Checkbox(label="Developer Mode", value=True)
|
| 1445 |
+
sync_chk = gr.Checkbox(label="Sync to HF Dataset", value=True)
|
| 1446 |
+
cycle_out = gr.Markdown("### Click button to start research...")
|
| 1447 |
+
|
| 1448 |
+
with gr.Accordion("🔍 Manual Q&A", open=False):
|
| 1449 |
+
q_input = gr.Textbox(
|
| 1450 |
+
label="Ask a nuclear question",
|
| 1451 |
+
placeholder="e.g. How do molten salt reactors handle tritium breeding?",
|
| 1452 |
+
)
|
| 1453 |
+
q_btn = gr.Button("Search & Answer")
|
| 1454 |
+
q_out = gr.Markdown()
|
| 1455 |
+
|
| 1456 |
+
with gr.Tab("⛓️ Blockchain"):
|
| 1457 |
+
verify_btn = gr.Button("⛓️ Verify Ledger Integrity")
|
| 1458 |
+
verify_out = gr.Markdown()
|
| 1459 |
+
gr.Markdown("### Latest Transactions")
|
| 1460 |
+
chain_table = gr.DataFrame(get_chain_df)
|
| 1461 |
+
|
| 1462 |
+
with gr.Tab("🕸️ Knowledge Graph"):
|
| 1463 |
+
search_input = gr.Textbox(label="Search", placeholder="e.g. fusion, reactor, safety")
|
| 1464 |
+
limit_input = gr.Slider(label="Limit", minimum=1, maximum=50, value=10, step=1)
|
| 1465 |
+
search_btn = gr.Button("Search")
|
| 1466 |
+
search_out = gr.Markdown()
|
| 1467 |
+
gr.Markdown("### Latest Entities")
|
| 1468 |
+
entities_table = gr.DataFrame(get_entities_df)
|
| 1469 |
+
|
| 1470 |
+
with gr.Tab("📈 Analytics"):
|
| 1471 |
+
with gr.Row():
|
| 1472 |
+
chart1 = gr.Plot(get_category_chart)
|
| 1473 |
+
chart2 = gr.Plot(get_score_chart)
|
| 1474 |
+
gr.Markdown("### Recent Cycles")
|
| 1475 |
+
history_table = gr.DataFrame(get_history_df)
|
| 1476 |
+
|
| 1477 |
+
# Event handlers
|
| 1478 |
+
refresh_stats.click(get_system_stats, outputs=stats_box)
|
| 1479 |
+
refresh_llm.click(get_llm_status, outputs=llm_status)
|
| 1480 |
+
run_btn.click(run_cycle, inputs=[dev_chk, sync_chk], outputs=cycle_out)
|
| 1481 |
+
q_btn.click(ask_q, inputs=[q_input, dev_chk], outputs=q_out)
|
| 1482 |
+
verify_btn.click(verify_chain, outputs=verify_out)
|
| 1483 |
+
search_btn.click(search_kg, inputs=[search_input, limit_input], outputs=search_out)
|
| 1484 |
+
export_btn.click(export_state, outputs=export_out)
|
| 1485 |
+
|
| 1486 |
+
# Auto-refresh stats every 30s
|
| 1487 |
+
timer = gr.Timer(30)
|
| 1488 |
+
timer.tick(get_system_stats, outputs=stats_box)
|
| 1489 |
+
timer.tick(get_chain_df, outputs=chain_table)
|
| 1490 |
+
timer.tick(get_entities_df, outputs=entities_table)
|
| 1491 |
+
timer.tick(get_history_df, outputs=history_table)
|
| 1492 |
|
| 1493 |
|
| 1494 |
if __name__ == "__main__":
|
| 1495 |
+
if demo is not None:
|
| 1496 |
+
try:
|
| 1497 |
+
demo.launch(server_name="0.0.0.0", server_port=PORT, css=CSS)
|
| 1498 |
+
except TypeError:
|
| 1499 |
+
# Gradio 6.0+ deprecated css in launch() too; pass only valid kwargs
|
| 1500 |
+
demo.launch(server_name="0.0.0.0", server_port=PORT)
|
| 1501 |
+
else:
|
| 1502 |
+
print("⚠️ Gradio not available; cannot launch UI. Run via 'huggingface_hub' sync or programmatic import.")
|
requirements.txt
CHANGED
|
@@ -1,15 +1,13 @@
|
|
| 1 |
-
# Nuclear Intelligence
|
| 2 |
-
#
|
|
|
|
| 3 |
|
| 4 |
-
# Core Framework
|
| 5 |
-
gradio>=4.36.0
|
| 6 |
-
|
| 7 |
-
# Data
|
| 8 |
-
pandas>=2.0.0
|
| 9 |
-
numpy>=1.26.0
|
| 10 |
|
| 11 |
# LLM & API
|
| 12 |
-
openai>=1.12.0
|
| 13 |
httpx>=0.27.0
|
| 14 |
requests>=2.31.0
|
| 15 |
python-dotenv>=1.0.0
|
|
@@ -21,8 +19,8 @@ cryptography>=42.0.0
|
|
| 21 |
loguru>=0.7.2
|
| 22 |
plotly>=5.19.0
|
| 23 |
|
| 24 |
-
# HuggingFace
|
| 25 |
-
huggingface-hub>=0.22.0
|
| 26 |
|
| 27 |
-
#
|
| 28 |
PyGithub>=2.3.0
|
|
|
|
| 1 |
+
# Nuclear Intelligence v4.0 - HuggingFace Space Requirements
|
| 2 |
+
# Optimized for HF Spaces (Python 3.11, Docker)
|
| 3 |
+
# Keep minimal: install size and build time matter.
|
| 4 |
|
| 5 |
+
# Core Framework
|
| 6 |
+
gradio>=4.36.0,<5.0.0
|
| 7 |
+
pandas>=2.2.0,<3.0.0
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# LLM & API
|
| 10 |
+
openai>=1.12.0,<2.0.0
|
| 11 |
httpx>=0.27.0
|
| 12 |
requests>=2.31.0
|
| 13 |
python-dotenv>=1.0.0
|
|
|
|
| 19 |
loguru>=0.7.2
|
| 20 |
plotly>=5.19.0
|
| 21 |
|
| 22 |
+
# HuggingFace
|
| 23 |
+
huggingface-hub>=0.22.0
|
| 24 |
|
| 25 |
+
# PyGithub used by sync_huggingface.py (imported lazily)
|
| 26 |
PyGithub>=2.3.0
|