Spaces:
Runtime error
Runtime error
Commit
·
9eb771a
1
Parent(s):
eb1af61
Update app.py
Browse files
app.py
CHANGED
@@ -159,6 +159,40 @@ def delete_endpoint(
|
|
159 |
else:
|
160 |
return f"something went wrong {response.status_code} = {response.text}"
|
161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
with gr.Blocks() as demo2:
|
163 |
gr.Markdown("""
|
164 |
#### Your 🤗 Access Token <span style="color:red;">(Required)</span>
|
@@ -321,6 +355,94 @@ with gr.Blocks() as demo2:
|
|
321 |
security_selector],
|
322 |
outputs=status_txt)
|
323 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
# Delete Endpoint
|
325 |
gr.Markdown("""
|
326 |
### <br><center style="color:green">(Delete 🗑️ Endpoint)</center>
|
|
|
159 |
else:
|
160 |
return f"something went wrong {response.status_code} = {response.text}"
|
161 |
|
162 |
+
def update_endpoint(
|
163 |
+
hf_token_input,
|
164 |
+
endpoint_name_input,
|
165 |
+
min_node_selector,
|
166 |
+
max_node_selector,
|
167 |
+
instance_type,
|
168 |
+
):
|
169 |
+
payload ={
|
170 |
+
"compute": {
|
171 |
+
"instanceSize": instance_type.split("·")[0].split("[")[1].split("]")[0],
|
172 |
+
"instanceType": instance_type.split("·")[-1].strip(),
|
173 |
+
"scaling": {
|
174 |
+
"maxReplica": max_node_selector,
|
175 |
+
"minReplica": min_node_selector
|
176 |
+
}
|
177 |
+
}}
|
178 |
+
|
179 |
+
response = requests.put(
|
180 |
+
f"https://api.endpoints.huggingface.cloud/endpoint/{endpoint_name_input}",
|
181 |
+
headers = {
|
182 |
+
"Authorization": f"Bearer {hf_token_input.strip()}",
|
183 |
+
"Content-Type": "application/json",
|
184 |
+
},
|
185 |
+
data=payload,
|
186 |
+
)
|
187 |
+
if response.status_code == 401:
|
188 |
+
return "Invalid token"
|
189 |
+
elif response.status_code == 404:
|
190 |
+
return f"Error: {response.text}"
|
191 |
+
elif response.status_code == 202:
|
192 |
+
return f"Endpoint {endpoint_name_input} updated successfully."
|
193 |
+
else:
|
194 |
+
return f"something went wrong {response.status_code} = {response.text}"
|
195 |
+
|
196 |
with gr.Blocks() as demo2:
|
197 |
gr.Markdown("""
|
198 |
#### Your 🤗 Access Token <span style="color:red;">(Required)</span>
|
|
|
355 |
security_selector],
|
356 |
outputs=status_txt)
|
357 |
|
358 |
+
# Update Endpoint
|
359 |
+
gr.Markdown("""
|
360 |
+
### <br><center style="color:green">(Update Endpoint)</center>
|
361 |
+
""")
|
362 |
+
with gr.Row():
|
363 |
+
gr.Markdown("""
|
364 |
+
#### Cloud Provider
|
365 |
+
""")
|
366 |
+
|
367 |
+
gr.Markdown("""
|
368 |
+
#### Cloud Region
|
369 |
+
""")
|
370 |
+
|
371 |
+
with gr.Row():
|
372 |
+
update_provider_selector = gr.Dropdown(
|
373 |
+
choices=providers,
|
374 |
+
interactive=True,
|
375 |
+
show_label=False,
|
376 |
+
)
|
377 |
+
|
378 |
+
update_region_selector = gr.Dropdown(
|
379 |
+
[],
|
380 |
+
value="",
|
381 |
+
interactive=True,
|
382 |
+
show_label=False,
|
383 |
+
)
|
384 |
+
|
385 |
+
with gr.Row():
|
386 |
+
gr.Markdown("""
|
387 |
+
#### Endpoint Name
|
388 |
+
""")
|
389 |
+
gr.Markdown("""
|
390 |
+
#### Instance Type
|
391 |
+
""")
|
392 |
+
|
393 |
+
with gr.Row():
|
394 |
+
update_endpoint_name_input = gr.Textbox(
|
395 |
+
show_label=False
|
396 |
+
)
|
397 |
+
update_compute_selector = gr.Dropdown(
|
398 |
+
[],
|
399 |
+
value="",
|
400 |
+
interactive=True,
|
401 |
+
show_label=False,
|
402 |
+
)
|
403 |
+
with gr.Row():
|
404 |
+
gr.Markdown("""
|
405 |
+
#### Min Number of Nodes
|
406 |
+
""")
|
407 |
+
gr.Markdown("""
|
408 |
+
#### Max Number of Nodes
|
409 |
+
""")
|
410 |
+
with gr.Row():
|
411 |
+
update_min_node_input = gr.Number(
|
412 |
+
value=1,
|
413 |
+
interactive=True,
|
414 |
+
show_label=False,
|
415 |
+
)
|
416 |
+
|
417 |
+
update_max_node_input = gr.Number(
|
418 |
+
value=1,
|
419 |
+
interactive=True,
|
420 |
+
show_label=False,
|
421 |
+
)
|
422 |
+
update_button = gr.Button(
|
423 |
+
value="Update",
|
424 |
+
)
|
425 |
+
|
426 |
+
update_status_txt = gr.Textbox(
|
427 |
+
value="status",
|
428 |
+
interactive=False
|
429 |
+
)
|
430 |
+
|
431 |
+
update_provider_selector.change(update_regions, inputs=update_provider_selector, outputs=update_region_selector)
|
432 |
+
update_region_selector.change(update_compute_options, inputs=[update_provider_selector, update_region_selector], outputs=update_compute_selector)
|
433 |
+
|
434 |
+
update_button.click(
|
435 |
+
update_endpoint,
|
436 |
+
inputs=[
|
437 |
+
hf_token_input,
|
438 |
+
update_endpoint_name_input,
|
439 |
+
update_min_node_input,
|
440 |
+
update_max_node_input,
|
441 |
+
update_compute_selector
|
442 |
+
],
|
443 |
+
outputs=update_status_txt
|
444 |
+
)
|
445 |
+
|
446 |
# Delete Endpoint
|
447 |
gr.Markdown("""
|
448 |
### <br><center style="color:green">(Delete 🗑️ Endpoint)</center>
|