Qalam commited on
Commit
4e4768b
·
verified ·
1 Parent(s): 822f90d

Auto: deploy Nuclear Intelligence v5.0

Browse files
Files changed (2) hide show
  1. app.py +93 -74
  2. 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
- with gr.Blocks(title="Nuclear Intelligence v5.0") as demo:
1408
- gr.Markdown("# ⚛️ Nuclear Intelligence v5.0", elem_id="title")
1409
- gr.Markdown(
1410
- "**Autonomous nuclear energy research multi-layer evaluation → SHA-3 PoW mining → NES token**\n\n"
1411
- "All research is produced by real LLMs. Evaluation is independent. Mining is real Proof-of-Work."
1412
- )
 
 
1413
 
1414
- with gr.Row():
1415
- with gr.Column(scale=1):
1416
- stats_box = gr.Markdown(get_system_stats)
1417
- refresh_stats = gr.Button("🔄 Refresh Stats", variant="secondary")
1418
- export_btn = gr.Button("💾 Export State")
1419
- export_out = gr.Markdown()
1420
-
1421
- with gr.Accordion("🔌 LLM Engine", open=False):
1422
- llm_status = gr.Markdown(get_llm_status)
1423
- refresh_llm = gr.Button("📡 Check Providers")
1424
-
1425
- with gr.Column(scale=3):
1426
- with gr.Tabs():
1427
- with gr.Tab("🚀 Research Center"):
1428
- with gr.Row():
1429
- run_btn = gr.Button("🚀 Run Research Cycle", variant="primary")
1430
- dev_chk = gr.Checkbox(label="Developer Mode", value=True)
1431
- sync_chk = gr.Checkbox(label="Sync to HF Dataset", value=True)
1432
- cycle_out = gr.Markdown("### Click button to start research...")
1433
-
1434
- with gr.Accordion("🔍 Manual Q&A", open=False):
1435
- q_input = gr.Textbox(
1436
- label="Ask a nuclear question",
1437
- placeholder="e.g. How do molten salt reactors handle tritium breeding?",
1438
- )
1439
- q_btn = gr.Button("Search & Answer")
1440
- q_out = gr.Markdown()
1441
-
1442
- with gr.Tab("⛓️ Blockchain"):
1443
- verify_btn = gr.Button("⛓️ Verify Ledger Integrity")
1444
- verify_out = gr.Markdown()
1445
- gr.Markdown("### Latest Transactions")
1446
- chain_table = gr.DataFrame(get_chain_df)
1447
-
1448
- with gr.Tab("🕸️ Knowledge Graph"):
1449
- search_input = gr.Textbox(label="Search", placeholder="e.g. fusion, reactor, safety")
1450
- limit_input = gr.Slider(label="Limit", minimum=1, maximum=50, value=10, step=1)
1451
- search_btn = gr.Button("Search")
1452
- search_out = gr.Markdown()
1453
- gr.Markdown("### Latest Entities")
1454
- entities_table = gr.DataFrame(get_entities_df)
1455
-
1456
- with gr.Tab("📈 Analytics"):
1457
- with gr.Row():
1458
- chart1 = gr.Plot(get_category_chart)
1459
- chart2 = gr.Plot(get_score_chart)
1460
- gr.Markdown("### Recent Cycles")
1461
- history_table = gr.DataFrame(get_history_df)
1462
-
1463
- # Event handlers
1464
- refresh_stats.click(get_system_stats, outputs=stats_box)
1465
- refresh_llm.click(get_llm_status, outputs=llm_status)
1466
- run_btn.click(run_cycle, inputs=[dev_chk, sync_chk], outputs=cycle_out)
1467
- q_btn.click(ask_q, inputs=[q_input, dev_chk], outputs=q_out)
1468
- verify_btn.click(verify_chain, outputs=verify_out)
1469
- search_btn.click(search_kg, inputs=[search_input, limit_input], outputs=search_out)
1470
- export_btn.click(export_state, outputs=export_out)
1471
-
1472
- # Auto-refresh handled client-side via gradio's built-in mechanisms
1473
- # gr.Timer() is only available in gradio>=4.40, so we leave this for the
1474
- # user to refresh manually via the button. The /keep_alive workflow on
1475
- # GitHub Actions handles external liveness.
 
 
1476
 
1477
 
1478
  if __name__ == "__main__":
1479
- try:
1480
- demo.launch(server_name="0.0.0.0", server_port=PORT, css=CSS)
1481
- except TypeError:
1482
- # Gradio 6.0+ deprecated css in launch() too; pass only valid kwargs
1483
- demo.launch(server_name="0.0.0.0", server_port=PORT)
 
 
 
 
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 v5.0 - HuggingFace Space Requirements
2
- # Pin huggingface-hub<0.26 for HfFolder compatibility with gradio
 
3
 
4
- # Core Framework (HF Spaces installs gradio 4.36.0 automatically)
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 - MUST be <0.26 for HfFolder (required by gradio 4.36)
25
- huggingface-hub>=0.22.0,<0.26
26
 
27
- # GitHub sync
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