Spaces:
Sleeping
Sleeping
Update genesis/safety.py
Browse files- genesis/safety.py +13 -51
genesis/safety.py
CHANGED
@@ -1,58 +1,20 @@
|
|
1 |
-
# genesis/
|
2 |
"""
|
3 |
-
|
4 |
-
|
5 |
"""
|
6 |
|
7 |
-
import
|
8 |
-
import networkx as nx
|
9 |
-
import matplotlib.pyplot as plt
|
10 |
-
from py2neo import Graph
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
def generate_pathway_graph(pathway_name):
|
19 |
-
"""Generate a metabolic pathway graph from Neo4j data."""
|
20 |
-
query = f"""
|
21 |
-
MATCH (p:Pathway {{name: '{pathway_name}'}})-[r:INVOLVES]->(m:Molecule)
|
22 |
-
RETURN p, r, m
|
23 |
"""
|
24 |
-
|
25 |
-
G = nx.Graph()
|
26 |
-
for record in data:
|
27 |
-
p_name = record["p"]["name"]
|
28 |
-
m_name = record["m"]["name"]
|
29 |
-
G.add_node(p_name, color="green")
|
30 |
-
G.add_node(m_name, color="orange")
|
31 |
-
G.add_edge(p_name, m_name)
|
32 |
-
return draw_graph(G)
|
33 |
-
|
34 |
-
def generate_funding_network(company_name):
|
35 |
-
"""Generate company-investor funding network."""
|
36 |
-
query = f"""
|
37 |
-
MATCH (c:Company {{name: '{company_name}'}})-[r:FUNDED_BY]->(i:Investor)
|
38 |
-
RETURN c, r, i
|
39 |
"""
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
c_name = record["c"]["name"]
|
44 |
-
i_name = record["i"]["name"]
|
45 |
-
G.add_node(c_name, color="green")
|
46 |
-
G.add_node(i_name, color="blue")
|
47 |
-
G.add_edge(c_name, i_name)
|
48 |
-
return draw_graph(G)
|
49 |
-
|
50 |
-
def draw_graph(G):
|
51 |
-
"""Draw networkx graph as PNG."""
|
52 |
-
pos = nx.spring_layout(G)
|
53 |
-
colors = [d.get("color", "grey") for _, d in G.nodes(data=True)]
|
54 |
-
plt.figure(figsize=(8, 6))
|
55 |
-
nx.draw(G, pos, with_labels=True, node_color=colors, node_size=1500, font_size=10)
|
56 |
-
plt.savefig("graph.png")
|
57 |
-
plt.close()
|
58 |
-
return "graph.png"
|
|
|
1 |
+
# genesis/safety.py
|
2 |
"""
|
3 |
+
Biosecurity & Safety Analysis for GENESIS-AI
|
4 |
+
Checks biosecurity risks using NSABB guidelines + BWC frameworks.
|
5 |
"""
|
6 |
|
7 |
+
import re
|
|
|
|
|
|
|
8 |
|
9 |
+
DUAL_USE_KEYWORDS = [
|
10 |
+
"pathogen", "toxin", "gain of function", "bioweapon",
|
11 |
+
"select agent", "lethal", "infectious dose", "virulence"
|
12 |
+
]
|
13 |
|
14 |
+
def assess_biosecurity_risk(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
"""
|
16 |
+
Returns a biosecurity risk score (0–10) and flagged terms.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
"""
|
18 |
+
flagged = [kw for kw in DUAL_USE_KEYWORDS if re.search(rf"\b{kw}\b", text, re.IGNORECASE)]
|
19 |
+
score = min(10, len(flagged) * 2)
|
20 |
+
return {"risk_score": score, "flagged_terms": flagged}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|