Spaces:
Sleeping
Sleeping
Create regulation.py
Browse files- genesis/regulation.py +60 -0
genesis/regulation.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# genesis/regulation.py
|
2 |
+
import os
|
3 |
+
import requests
|
4 |
+
from typing import Dict
|
5 |
+
|
6 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
7 |
+
|
8 |
+
def analyze_regulatory_pathways(therapy_description: str) -> Dict:
|
9 |
+
"""
|
10 |
+
Analyze regulatory risks and pathways for a therapy or technology.
|
11 |
+
Uses OpenAI GPT-4 to reason about approval timelines and steps.
|
12 |
+
"""
|
13 |
+
try:
|
14 |
+
if not OPENAI_API_KEY:
|
15 |
+
raise ValueError("Missing OPENAI_API_KEY")
|
16 |
+
|
17 |
+
headers = {
|
18 |
+
"Authorization": f"Bearer {OPENAI_API_KEY}",
|
19 |
+
"Content-Type": "application/json"
|
20 |
+
}
|
21 |
+
payload = {
|
22 |
+
"model": "gpt-4o-mini",
|
23 |
+
"messages": [
|
24 |
+
{
|
25 |
+
"role": "system",
|
26 |
+
"content": (
|
27 |
+
"You are a senior FDA and EMA regulatory affairs expert "
|
28 |
+
"specializing in synthetic biology, gene therapies, and living therapeutics. "
|
29 |
+
"Provide an evidence-based, structured assessment of approval pathways."
|
30 |
+
)
|
31 |
+
},
|
32 |
+
{
|
33 |
+
"role": "user",
|
34 |
+
"content": (
|
35 |
+
f"Analyze the regulatory approval process for:\n{therapy_description}\n\n"
|
36 |
+
"Include:\n"
|
37 |
+
"1. Likely classification (e.g., ATMP, Biologic, Device)\n"
|
38 |
+
"2. Key regulatory agencies and applicable guidelines\n"
|
39 |
+
"3. Estimated approval timeline\n"
|
40 |
+
"4. Common risks & how to mitigate them\n"
|
41 |
+
"5. Post-market surveillance requirements"
|
42 |
+
)
|
43 |
+
}
|
44 |
+
],
|
45 |
+
"temperature": 0.2
|
46 |
+
}
|
47 |
+
|
48 |
+
r = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload, timeout=60)
|
49 |
+
r.raise_for_status()
|
50 |
+
data = r.json()
|
51 |
+
text = data["choices"][0]["message"]["content"]
|
52 |
+
|
53 |
+
return {
|
54 |
+
"analysis": text.strip(),
|
55 |
+
"source": "OpenAI GPT-4o Regulatory Module"
|
56 |
+
}
|
57 |
+
|
58 |
+
except Exception as e:
|
59 |
+
print(f"[Regulation] Failed: {e}")
|
60 |
+
return {"analysis": "Regulatory analysis unavailable at this time.", "source": "Error"}
|