Spaces:
Runtime error
Runtime error
neondaniel
commited on
Commit
•
f1a3e74
1
Parent(s):
d9f8b28
Add `huggingface_text` and `allowed_domains_override` configuration
Browse files
app.py
CHANGED
@@ -51,7 +51,10 @@ def init_config():
|
|
51 |
global clients
|
52 |
global llm_host_names
|
53 |
config = json.loads(os.environ['CONFIG'])
|
|
|
54 |
for name in config:
|
|
|
|
|
55 |
model_personas = config[name].get("personas", {})
|
56 |
client = Client(
|
57 |
api_url=os.environ.get(config[name]['api_url'],
|
@@ -66,16 +69,21 @@ def init_config():
|
|
66 |
|
67 |
def get_allowed_models(user_domain: str) -> List[str]:
|
68 |
"""
|
69 |
-
Get a list of allowed endpoints for a specified user domain
|
|
|
|
|
70 |
:param user_domain: User domain (i.e. neon.ai, google.com, guest)
|
71 |
:return: List of allowed endpoints from configuration
|
72 |
"""
|
|
|
73 |
allowed_endpoints = []
|
74 |
for client in clients:
|
75 |
-
|
|
|
|
|
76 |
# Allowed domains not specified; model is public
|
77 |
allowed_endpoints.append(client)
|
78 |
-
elif user_domain in
|
79 |
# User domain is in the allowed domain list
|
80 |
allowed_endpoints.append(client)
|
81 |
return allowed_endpoints
|
@@ -278,12 +286,12 @@ def init_gradio() -> gr.Blocks:
|
|
278 |
return clean_state, *clean_state
|
279 |
|
280 |
# Compile
|
281 |
-
|
282 |
-
accordion_info =
|
283 |
"Persona and LLM Options - Choose one:"
|
284 |
-
version =
|
285 |
f"v{datetime.now().strftime('%Y-%m-%d')}"
|
286 |
-
title =
|
287 |
f"Neon AI BrainForge Personas and Large Language Models ({version})"
|
288 |
|
289 |
with gr.Accordion(label=accordion_info, open=True,
|
|
|
51 |
global clients
|
52 |
global llm_host_names
|
53 |
config = json.loads(os.environ['CONFIG'])
|
54 |
+
reserved_keys = ("huggingface_text", "allowed_domains_override")
|
55 |
for name in config:
|
56 |
+
if name in reserved_keys:
|
57 |
+
continue
|
58 |
model_personas = config[name].get("personas", {})
|
59 |
client = Client(
|
60 |
api_url=os.environ.get(config[name]['api_url'],
|
|
|
69 |
|
70 |
def get_allowed_models(user_domain: str) -> List[str]:
|
71 |
"""
|
72 |
+
Get a list of allowed endpoints for a specified user domain. Allowed domains
|
73 |
+
are configured in each model's configuration and may optionally be overridden
|
74 |
+
in the Gradio demo configuration.
|
75 |
:param user_domain: User domain (i.e. neon.ai, google.com, guest)
|
76 |
:return: List of allowed endpoints from configuration
|
77 |
"""
|
78 |
+
overrides = config.get("allowed_domains_override", {})
|
79 |
allowed_endpoints = []
|
80 |
for client in clients:
|
81 |
+
allowed_domains = overrides.get(client,
|
82 |
+
clients[client].config.inference.allowed_domains)
|
83 |
+
if allowed_domains is None:
|
84 |
# Allowed domains not specified; model is public
|
85 |
allowed_endpoints.append(client)
|
86 |
+
elif user_domain in allowed_domains:
|
87 |
# User domain is in the allowed domain list
|
88 |
allowed_endpoints.append(client)
|
89 |
return allowed_endpoints
|
|
|
286 |
return clean_state, *clean_state
|
287 |
|
288 |
# Compile
|
289 |
+
hf_config = config.get("huggingface_text") or dict()
|
290 |
+
accordion_info = hf_config.get("accordian_info") or \
|
291 |
"Persona and LLM Options - Choose one:"
|
292 |
+
version = hf_config.get("version") or \
|
293 |
f"v{datetime.now().strftime('%Y-%m-%d')}"
|
294 |
+
title = hf_config.get("title") or \
|
295 |
f"Neon AI BrainForge Personas and Large Language Models ({version})"
|
296 |
|
297 |
with gr.Accordion(label=accordion_info, open=True,
|