Skip to content

Commit c8ecdcd

Browse files
committed
google collab jupyter_dash bug fix
1 parent c1ed9e5 commit c8ecdcd

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

novalad/api/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
get_file_extension, get_filename,is_cloud_storage_path,
88
is_valid_url, extract_filename_from_url
99
)
10-
from novalad.api.exception import APIError, InvalidArgumentException, FileFormatNotSupportedException
10+
from novalad.api.exception import APIError, InvalidArgumentException, FileFormatNotSupportedException, FileNotUploaded
1111
from novalad.utils.progress import tqdm
1212

1313
class NovaladClient(BaseAPIClient):
@@ -79,12 +79,14 @@ def upload(self, file_path: Optional[str] = None, folder_path: Optional[str] = N
7979
:raises InvalidArgumentException: If both or neither of file_path and folder_path are provided.
8080
:raises APIError: If the upload process encounters an error.
8181
"""
82+
self.uploaded = False
8283
if (file_path is None and folder_path is None) or (file_path is not None and folder_path is not None):
8384
raise InvalidArgumentException("You must provide either 'file_path' or 'folder_path', but not both.")
8485

8586
if file_path and is_filepath(file_path):
8687
upload_url = self._upload_url(file_path)
8788
self._upload_to_cloud(file_path, upload_url)
89+
self.uploaded = True
8890

8991
elif folder_path and is_folderpath(folder_path):
9092
files = get_files_from_folder(folder_path)
@@ -95,6 +97,7 @@ def upload(self, file_path: Optional[str] = None, folder_path: Optional[str] = N
9597
for file in tqdm(supported_files, desc="Uploading files"):
9698
upload_url = self._upload_url(file)
9799
self._upload_to_cloud(file, upload_url)
100+
self.uploaded = True
98101

99102
def run(self, url : str = None,
100103
skip_non_important_images : bool = True,
@@ -108,6 +111,9 @@ def run(self, url : str = None,
108111
"skip_header_footer" : skip_header_footer
109112
}
110113

114+
if not self.uploaded:
115+
raise FileNotUploaded("File not Uploaded, Either the path/url is invalid or document is corrupted.")
116+
111117
if (self.file_id is None and url is None) or (self.file_id is not None and url is not None):
112118
raise InvalidArgumentException("You must upload local file or provide 'url', but not both.")
113119

novalad/api/exception.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class InvalidArgumentException(Exception):
1111
pass
1212

1313

14+
class FileNotUploaded(Exception):
15+
pass
16+
1417
class FileFormatNotSupportedException(Exception):
1518
pass
1619

novalad/render/graph.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
1-
import os
21
import sys
32
import json
4-
5-
# Universal imports
63
import dash_cytoscape as cyto
74
from dash import html, dcc
85
from dash.dependencies import Input, Output
96

107
# Use JupyterDash in Colab, Dash locally
11-
try:
12-
if "google.colab" in sys.modules:
13-
from jupyter_dash import JupyterDash as DashApp
14-
else:
15-
from dash import Dash as DashApp
16-
except ImportError:
17-
from dash import Dash as DashApp
8+
if "google.colab" in sys.modules:
9+
from jupyter_dash import JupyterDash
10+
DashApp = JupyterDash
11+
else:
12+
from dash import Dash
13+
DashApp = Dash
1814

1915

20-
def render_knowledge_graph(data: dict, save: bool = False, filename: str = "kg.html") -> None:
16+
def render_knowledge_graph(data: dict) -> None:
2117
"""
2218
Render an interactive knowledge graph using Dash and Dash Cytoscape.
2319
2420
Args:
2521
data (dict): Knowledge graph data with nodes and edges.
26-
save (bool): If True, saves the graph as a static HTML file.
27-
filename (str): Output filename for HTML export.
2822
2923
Returns:
3024
None
3125
"""
32-
data = data["data"].get("knowledge_graphs", {})
26+
graph_data = data["data"].get("knowledge_graphs", {})
3327

34-
# Convert data to Cytoscape elements
28+
# Convert to Cytoscape elements
3529
elements = []
3630

37-
for node in data["nodes"]:
31+
for node in graph_data["nodes"]:
3832
elements.append({
3933
"data": {
4034
"id": node["id"],
@@ -47,7 +41,7 @@ def render_knowledge_graph(data: dict, save: bool = False, filename: str = "kg.h
4741
}
4842
})
4943

50-
for edge in data["edges"]:
44+
for edge in graph_data["edges"]:
5145
elements.append({
5246
"data": {
5347
"source": edge["fromId"],
@@ -56,8 +50,8 @@ def render_knowledge_graph(data: dict, save: bool = False, filename: str = "kg.h
5650
}
5751
})
5852

53+
# Build the app
5954
app = DashApp(__name__)
60-
6155
app.layout = html.Div([
6256
html.H3("Interactive Knowledge Graph"),
6357
html.Div(id="node-info", style={"margin": "10px", "font-size": "14px", "color": "#F58634"}),
@@ -98,12 +92,8 @@ def display_click_info(node_data):
9892
return f"Selected Node: {node_data['hover_text']}"
9993
return "Click on a node to see details"
10094

101-
if save:
102-
app.run_server(mode="inline", debug=False)
103-
# Use selenium or dash-export to save actual HTML content if needed
104-
print("Note: Static export not implemented in this version.")
95+
# Show app inline if in Colab, else open in browser
96+
if "google.colab" in sys.modules:
97+
app.run_server(mode='inline', debug=True)
10598
else:
106-
if "google.colab" in sys.modules:
107-
app.run_server(mode="inline", debug=True)
108-
else:
109-
app.run_server(debug=True)
99+
app.run_server(debug=True)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "novalad"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
description = "Novalad: AI-powered platform for transforming unstructured documents like PDFs and PowerPoints into machine-readable, structured data."
55
authors = ["Novalad <info@novalad.ai>"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)