Update visualizer_app.py
Browse files- visualizer_app.py +39 -39
visualizer_app.py
CHANGED
@@ -63,7 +63,9 @@ with app.setup:
|
|
63 |
if creds_var_name in globals():
|
64 |
creds_dict = globals()[creds_var_name]
|
65 |
if isinstance(creds_dict, dict) and key in creds_dict:
|
66 |
-
|
|
|
|
|
67 |
return default
|
68 |
|
69 |
@app.cell
|
@@ -109,9 +111,8 @@ def _(client_setup, wx_api_key):
|
|
109 |
@app.cell
|
110 |
def _():
|
111 |
baked_in_creds = {
|
112 |
-
"
|
113 |
-
"
|
114 |
-
"project_id": "",
|
115 |
"space_id": "",
|
116 |
}
|
117 |
return baked_in_creds
|
@@ -127,39 +128,38 @@ def client_instantiation(
|
|
127 |
):
|
128 |
### Instantiate the watsonx.ai client
|
129 |
if client_setup:
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
138 |
project_client = None
|
139 |
-
|
140 |
-
if space_id:
|
141 |
-
deployment_client = APIClient(credentials=wx_credentials, space_id=space_id)
|
142 |
-
else:
|
143 |
-
deployment_client = None
|
144 |
-
|
145 |
-
|
146 |
-
if project_client is not None:
|
147 |
-
task_credentials_details = setup_task_credentials(project_client)
|
148 |
-
else:
|
149 |
-
task_credentials_details = setup_task_credentials(deployment_client)
|
150 |
-
|
151 |
else:
|
152 |
wx_credentials = None
|
153 |
project_client = None
|
154 |
deployment_client = None
|
155 |
-
|
156 |
-
|
157 |
-
client_status = mo.md("### Client Instantiation Status will turn Green When Ready")
|
158 |
-
|
159 |
-
if project_client is not None or deployment_client is not None:
|
160 |
-
client_callout_kind = "success"
|
161 |
-
else:
|
162 |
client_callout_kind = "neutral"
|
|
|
163 |
return (
|
164 |
client_callout_kind,
|
165 |
client_status,
|
@@ -350,7 +350,7 @@ def file_and_model_select(
|
|
350 |
get_embedding_model_list,
|
351 |
run_upload_button,
|
352 |
):
|
353 |
-
select_stack = mo.hstack([get_embedding_model_list(), mo.vstack([file_loader, run_upload_button], align="center")], justify="space-around", align="center", widths=[0.3,0.3])
|
354 |
return (select_stack,)
|
355 |
|
356 |
|
@@ -384,13 +384,13 @@ def client_instantiation_form():
|
|
384 |
> If you provide both you can switch the active one in the dropdown.
|
385 |
''')
|
386 |
.batch(
|
387 |
-
wx_region = mo.ui.dropdown(regions, label="Select your watsonx.ai region:", value="
|
388 |
wx_api_key = mo.ui.text(placeholder="Add your IBM Cloud api-key...", label="IBM Cloud Api-key:",
|
389 |
kind="password", value=get_cred_value('api_key', creds_var_name='baked_in_creds')),
|
390 |
project_id = mo.ui.text(placeholder="Add your watsonx.ai project_id...", label="Project_ID:",
|
391 |
-
kind="
|
392 |
space_id = mo.ui.text(placeholder="Add your watsonx.ai space_id...", label="Space_ID:",
|
393 |
-
kind="
|
394 |
,)
|
395 |
.form(show_clear_button=True, bordered=False)
|
396 |
)
|
@@ -720,8 +720,8 @@ def sentence_splitter_setup():
|
|
720 |
|
721 |
''')
|
722 |
.batch(
|
723 |
-
chunk_size = mo.ui.slider(start=100, stop=5000, step=1, label="**Chunk Size:**", value=
|
724 |
-
chunk_overlap = mo.ui.slider(start=
|
725 |
separator = mo.ui.text(placeholder="Define a separator", label="**Separator:**", kind="text", value=" "),
|
726 |
paragraph_separator = mo.ui.text(placeholder="Define a paragraph separator",
|
727 |
label="**Paragraph Separator:**", kind="text",
|
@@ -731,7 +731,7 @@ def sentence_splitter_setup():
|
|
731 |
value="[^,.;?!]+[,.;?!]?"),
|
732 |
include_metadata= mo.ui.checkbox(value=True, label="**Include Metadata**")
|
733 |
)
|
734 |
-
.form(show_clear_button=True, bordered=False)
|
735 |
)
|
736 |
return (sentence_splitter_config,)
|
737 |
|
@@ -1651,7 +1651,7 @@ def prepare_doc_select(sentence_splitter_config):
|
|
1651 |
full_width=True,
|
1652 |
show_value=True,
|
1653 |
label="**Select a Range of Chunks to Visualize:**"
|
1654 |
-
).form(submit_button_disabled=check_state(sentence_splitter_config.value))
|
1655 |
|
1656 |
return llama_docs
|
1657 |
return (prepare_document_selection,)
|
@@ -1839,7 +1839,7 @@ def create_baseline_chart(
|
|
1839 |
def test_query(get_chunk_state):
|
1840 |
placeholder = """How can i use watsonx.data to perform vector search?"""
|
1841 |
|
1842 |
-
query = mo.ui.text_area(label="**Write text to check:**", full_width=True, rows=8, value=placeholder).form(show_clear_button=True, submit_button_disabled=check_state(get_chunk_state()))
|
1843 |
return (query,)
|
1844 |
|
1845 |
|
|
|
63 |
if creds_var_name in globals():
|
64 |
creds_dict = globals()[creds_var_name]
|
65 |
if isinstance(creds_dict, dict) and key in creds_dict:
|
66 |
+
# Return empty string if the value is None
|
67 |
+
value = creds_dict[key]
|
68 |
+
return "" if value is None else value
|
69 |
return default
|
70 |
|
71 |
@app.cell
|
|
|
111 |
@app.cell
|
112 |
def _():
|
113 |
baked_in_creds = {
|
114 |
+
"api_key": os.environ.get("WX_APIKEY"),
|
115 |
+
"project_id": os.environ.get("WX_PROJECT_ID"),
|
|
|
116 |
"space_id": "",
|
117 |
}
|
118 |
return baked_in_creds
|
|
|
128 |
):
|
129 |
### Instantiate the watsonx.ai client
|
130 |
if client_setup:
|
131 |
+
try:
|
132 |
+
wx_credentials = Credentials(
|
133 |
+
url=wx_url,
|
134 |
+
api_key=wx_api_key
|
135 |
+
)
|
136 |
+
|
137 |
+
if project_id:
|
138 |
+
project_client = APIClient(credentials=wx_credentials, project_id=project_id)
|
139 |
+
else:
|
140 |
+
project_client = None
|
141 |
+
|
142 |
+
if space_id:
|
143 |
+
deployment_client = APIClient(credentials=wx_credentials, space_id=space_id)
|
144 |
+
else:
|
145 |
+
deployment_client = None
|
146 |
|
147 |
+
client_status = mo.md("### ✅ Client Instantiation Successful ✅")
|
148 |
+
client_callout_kind = "success"
|
149 |
+
|
150 |
+
except Exception as e:
|
151 |
+
error_message = str(e)
|
152 |
+
client_status = mo.md(f"### ❌ Client Instantiation Failed\n**Error:** {error_message}\n\nCheck your region selection and credentials")
|
153 |
+
client_callout_kind = "danger"
|
154 |
project_client = None
|
155 |
+
deployment_client = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
else:
|
157 |
wx_credentials = None
|
158 |
project_client = None
|
159 |
deployment_client = None
|
160 |
+
client_status = mo.md("### This box will turn Green if client instantiation is successful")
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
client_callout_kind = "neutral"
|
162 |
+
|
163 |
return (
|
164 |
client_callout_kind,
|
165 |
client_status,
|
|
|
350 |
get_embedding_model_list,
|
351 |
run_upload_button,
|
352 |
):
|
353 |
+
select_stack = mo.hstack([get_embedding_model_list(), mo.vstack([mo.md("Drag & Drop or Double Click to select PDFs, then press **Load Files**"),file_loader, run_upload_button], align="center")], justify="space-around", align="center", widths=[0.3,0.3])
|
354 |
return (select_stack,)
|
355 |
|
356 |
|
|
|
384 |
> If you provide both you can switch the active one in the dropdown.
|
385 |
''')
|
386 |
.batch(
|
387 |
+
wx_region = mo.ui.dropdown(regions, label="Select your watsonx.ai region:", value="EU", searchable=True),
|
388 |
wx_api_key = mo.ui.text(placeholder="Add your IBM Cloud api-key...", label="IBM Cloud Api-key:",
|
389 |
kind="password", value=get_cred_value('api_key', creds_var_name='baked_in_creds')),
|
390 |
project_id = mo.ui.text(placeholder="Add your watsonx.ai project_id...", label="Project_ID:",
|
391 |
+
kind="password", value=get_cred_value('project_id', creds_var_name='baked_in_creds')),
|
392 |
space_id = mo.ui.text(placeholder="Add your watsonx.ai space_id...", label="Space_ID:",
|
393 |
+
kind="password", value=get_cred_value('space_id', creds_var_name='baked_in_creds'))
|
394 |
,)
|
395 |
.form(show_clear_button=True, bordered=False)
|
396 |
)
|
|
|
720 |
|
721 |
''')
|
722 |
.batch(
|
723 |
+
chunk_size = mo.ui.slider(start=100, stop=5000, step=1, label="**Chunk Size:**", value=275, show_value=True, full_width=True),
|
724 |
+
chunk_overlap = mo.ui.slider(start=0, stop=1000, step=1, label="**Chunk Overlap** *(Must always be smaller than Chunk Size)* **:**", value=0, show_value=True, full_width=True),
|
725 |
separator = mo.ui.text(placeholder="Define a separator", label="**Separator:**", kind="text", value=" "),
|
726 |
paragraph_separator = mo.ui.text(placeholder="Define a paragraph separator",
|
727 |
label="**Paragraph Separator:**", kind="text",
|
|
|
731 |
value="[^,.;?!]+[,.;?!]?"),
|
732 |
include_metadata= mo.ui.checkbox(value=True, label="**Include Metadata**")
|
733 |
)
|
734 |
+
.form(show_clear_button=True, bordered=False, submit_button_label="Chunk Documents")
|
735 |
)
|
736 |
return (sentence_splitter_config,)
|
737 |
|
|
|
1651 |
full_width=True,
|
1652 |
show_value=True,
|
1653 |
label="**Select a Range of Chunks to Visualize:**"
|
1654 |
+
).form(submit_button_disabled=check_state(sentence_splitter_config.value), submit_button_label="Change Document View Range")
|
1655 |
|
1656 |
return llama_docs
|
1657 |
return (prepare_document_selection,)
|
|
|
1839 |
def test_query(get_chunk_state):
|
1840 |
placeholder = """How can i use watsonx.data to perform vector search?"""
|
1841 |
|
1842 |
+
query = mo.ui.text_area(label="**Write text to check:**", full_width=True, rows=8, value=placeholder).form(show_clear_button=True, submit_button_disabled=check_state(get_chunk_state()), submit_button_label="Query and View Visualization")
|
1843 |
return (query,)
|
1844 |
|
1845 |
|