Spaces:
Sleeping
Sleeping
Jac-Zac commited on
Commit ·
e8b0701
1
Parent(s): b527c23
Adding api key field
Browse files
app.py
CHANGED
|
@@ -30,6 +30,8 @@ _SIDEBAR_REMOTE_MODEL_KEY = session_key("sidebar", "remote_model")
|
|
| 30 |
_SIDEBAR_LOCAL_MODEL_KEY = session_key("sidebar", "local_model")
|
| 31 |
_SIDEBAR_REMOTE_KEY = session_key("sidebar", "remote")
|
| 32 |
_SIDEBAR_DATASET_SOURCE_KEY = session_key("sidebar", "dataset_source")
|
|
|
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
_TABS = ["Chat", "Analysis", "Probing", "Extract"]
|
|
@@ -163,6 +165,25 @@ def _remote_model_input(remote_models: list[str]) -> str:
|
|
| 163 |
return model_name
|
| 164 |
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
def _sidebar_controls() -> SidebarState:
|
| 167 |
with st.sidebar:
|
| 168 |
st.markdown("## Persona UI")
|
|
@@ -200,6 +221,7 @@ def _sidebar_controls() -> SidebarState:
|
|
| 200 |
|
| 201 |
st.divider()
|
| 202 |
st.caption("Runtime")
|
|
|
|
| 203 |
remote = st.toggle("Remote (NDIF)", value=False, key=_SIDEBAR_REMOTE_KEY)
|
| 204 |
|
| 205 |
if remote:
|
|
|
|
| 30 |
_SIDEBAR_LOCAL_MODEL_KEY = session_key("sidebar", "local_model")
|
| 31 |
_SIDEBAR_REMOTE_KEY = session_key("sidebar", "remote")
|
| 32 |
_SIDEBAR_DATASET_SOURCE_KEY = session_key("sidebar", "dataset_source")
|
| 33 |
+
_SIDEBAR_NDIF_API_KEY = session_key("sidebar", "ndif_api_key")
|
| 34 |
+
NDIF_REGISTRATION_URL = "https://login.ndif.us/"
|
| 35 |
|
| 36 |
|
| 37 |
_TABS = ["Chat", "Analysis", "Probing", "Extract"]
|
|
|
|
| 165 |
return model_name
|
| 166 |
|
| 167 |
|
| 168 |
+
def _ndif_api_key_input() -> None:
|
| 169 |
+
"""Prompt for an NDIF API key when none is configured via the environment."""
|
| 170 |
+
import nnsight
|
| 171 |
+
|
| 172 |
+
if os.environ.get("NDIF_API_KEY") or nnsight.CONFIG.API.APIKEY:
|
| 173 |
+
return
|
| 174 |
+
|
| 175 |
+
api_key = st.text_input(
|
| 176 |
+
"NDIF API key",
|
| 177 |
+
type="password",
|
| 178 |
+
key=_SIDEBAR_NDIF_API_KEY,
|
| 179 |
+
help=f"Required for remote (NDIF) execution. Register at {NDIF_REGISTRATION_URL}",
|
| 180 |
+
)
|
| 181 |
+
if api_key:
|
| 182 |
+
nnsight.CONFIG.API.APIKEY = api_key
|
| 183 |
+
else:
|
| 184 |
+
st.caption(f"No NDIF API key found. [Get one]({NDIF_REGISTRATION_URL}).")
|
| 185 |
+
|
| 186 |
+
|
| 187 |
def _sidebar_controls() -> SidebarState:
|
| 188 |
with st.sidebar:
|
| 189 |
st.markdown("## Persona UI")
|
|
|
|
| 221 |
|
| 222 |
st.divider()
|
| 223 |
st.caption("Runtime")
|
| 224 |
+
_ndif_api_key_input()
|
| 225 |
remote = st.toggle("Remote (NDIF)", value=False, key=_SIDEBAR_REMOTE_KEY)
|
| 226 |
|
| 227 |
if remote:
|