Spaces:
Running
Running
Update notebook/demo.ipynb
Browse files- notebook/demo.ipynb +53 -0
notebook/demo.ipynb
CHANGED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import nbformat as nbf
|
2 |
+
|
3 |
+
# Create a new notebook
|
4 |
+
nb = nbf.v4.new_notebook()
|
5 |
+
|
6 |
+
# Add cells
|
7 |
+
nb.cells = [
|
8 |
+
nbf.v4.new_markdown_cell("# Demo: AI-Powered Scientific Research Companion\nThis notebook demonstrates how to use the `Dispatcher` to search for papers, retrieve reproducible notebook cells, and fetch a knowledge graph."),
|
9 |
+
nbf.v4.new_code_cell("""\
|
10 |
+
from orchestrator.dispatcher import Dispatcher
|
11 |
+
|
12 |
+
# Initialize dispatcher
|
13 |
+
dispatcher = Dispatcher()
|
14 |
+
|
15 |
+
# Example query
|
16 |
+
query = "CRISPR delivery"
|
17 |
+
|
18 |
+
# 1. Search for papers
|
19 |
+
papers = dispatcher.search_papers(query, limit=3)
|
20 |
+
print("Papers found:")
|
21 |
+
for p in papers:
|
22 |
+
print(f"- {p['title']} (ID: {p['id']})")
|
23 |
+
"""),
|
24 |
+
nbf.v4.new_code_cell("""\
|
25 |
+
# 2. Retrieve notebook cells for the first paper
|
26 |
+
if papers:
|
27 |
+
first_id = papers[0]['id']
|
28 |
+
cells = dispatcher.get_notebook_cells(first_id)
|
29 |
+
print(f"Notebook cells for paper {first_id}:")
|
30 |
+
for i, cell in enumerate(cells, 1):
|
31 |
+
print(f"Cell {i}:")
|
32 |
+
print(cell)
|
33 |
+
print("------")
|
34 |
+
"""),
|
35 |
+
nbf.v4.new_code_cell("""\
|
36 |
+
# 3. Fetch knowledge graph for the first paper
|
37 |
+
if papers:
|
38 |
+
graph = dispatcher.get_graph(first_id)
|
39 |
+
print("Graph nodes:")
|
40 |
+
for node in graph.get("nodes", []):
|
41 |
+
print(node)
|
42 |
+
print("Graph edges:")
|
43 |
+
for edge in graph.get("edges", []):
|
44 |
+
print(edge)
|
45 |
+
""")
|
46 |
+
]
|
47 |
+
|
48 |
+
# Save the notebook
|
49 |
+
nb_path = "/mnt/data/demo.ipynb"
|
50 |
+
with open(nb_path, "w") as f:
|
51 |
+
nbf.write(nb, f)
|
52 |
+
|
53 |
+
nb_path
|