mgbam commited on
Commit
5a5be73
·
verified ·
1 Parent(s): 2d1ee5e

Upload demo.ipynb

Browse files
Files changed (1) hide show
  1. notebook/demo.ipynb +74 -53
notebook/demo.ipynb CHANGED
@@ -1,53 +1,74 @@
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "dfad5f6b",
6
+ "metadata": {},
7
+ "source": [
8
+ "# Demo: AI-Powered Scientific Research Companion\n",
9
+ "This notebook demonstrates how to use the `Dispatcher` to search for papers, retrieve reproducible notebook cells, and fetch a knowledge graph."
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": null,
15
+ "id": "307d78b9",
16
+ "metadata": {},
17
+ "outputs": [],
18
+ "source": [
19
+ "from orchestrator.dispatcher import Dispatcher\n",
20
+ "\n",
21
+ "# Initialize dispatcher\n",
22
+ "dispatcher = Dispatcher()\n",
23
+ "\n",
24
+ "# Example query\n",
25
+ "query = \"CRISPR delivery\"\n",
26
+ "\n",
27
+ "# 1. Search for papers\n",
28
+ "papers = dispatcher.search_papers(query, limit=3)\n",
29
+ "print(\"Papers found:\")\n",
30
+ "for p in papers:\n",
31
+ " print(f\"- {p['title']} (ID: {p['id']})\")\n"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "execution_count": null,
37
+ "id": "8db389c8",
38
+ "metadata": {},
39
+ "outputs": [],
40
+ "source": [
41
+ "# 2. Retrieve notebook cells for the first paper\n",
42
+ "if papers:\n",
43
+ " first_id = papers[0]['id']\n",
44
+ " cells = dispatcher.get_notebook_cells(first_id)\n",
45
+ " print(f\"Notebook cells for paper {first_id}:\")\n",
46
+ " for i, cell in enumerate(cells, 1):\n",
47
+ " print(f\"Cell {i}:\")\n",
48
+ " print(cell)\n",
49
+ " print(\"------\")\n"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": null,
55
+ "id": "52666e2a",
56
+ "metadata": {},
57
+ "outputs": [],
58
+ "source": [
59
+ "# 3. Fetch knowledge graph for the first paper\n",
60
+ "if papers:\n",
61
+ " graph = dispatcher.get_graph(first_id)\n",
62
+ " print(\"Graph nodes:\")\n",
63
+ " for node in graph.get(\"nodes\", []):\n",
64
+ " print(node)\n",
65
+ " print(\"Graph edges:\")\n",
66
+ " for edge in graph.get(\"edges\", []):\n",
67
+ " print(edge)\n"
68
+ ]
69
+ }
70
+ ],
71
+ "metadata": {},
72
+ "nbformat": 4,
73
+ "nbformat_minor": 5
74
+ }