mgbam commited on
Commit
311fafd
·
verified ·
1 Parent(s): 320163c

Update genesis/safety.py

Browse files
Files changed (1) hide show
  1. genesis/safety.py +13 -51
genesis/safety.py CHANGED
@@ -1,58 +1,20 @@
1
- # genesis/visualization.py
2
  """
3
- Visualization tools for GENESIS-AI
4
- Uses Neo4j to query and build graphs.
5
  """
6
 
7
- import os
8
- import networkx as nx
9
- import matplotlib.pyplot as plt
10
- from py2neo import Graph
11
 
12
- NEO4J_URI = os.getenv("NEO4J_URI")
13
- NEO4J_USER = os.getenv("NEO4J_USER")
14
- NEO4J_PASSWORD = os.getenv("NEO4J_PASSWORD")
 
15
 
16
- graph_db = Graph(NEO4J_URI, auth=(NEO4J_USER, NEO4J_PASSWORD))
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
- data = graph_db.run(query).data()
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
- data = graph_db.run(query).data()
41
- G = nx.Graph()
42
- for record in data:
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}