Spaces:
Runtime error
Runtime error
Commit
路
8236d91
1
Parent(s):
f5f3d31
updated code
Browse files- app.py +48 -27
- requirements.txt +1 -1
app.py
CHANGED
@@ -59,7 +59,6 @@ def update_compute_options(provider, region):
|
|
59 |
"Content-Type": "application/json",
|
60 |
}
|
61 |
endpoint_url = f"https://api.endpoints.huggingface.cloud/provider/{provider}/region/{region}/compute"
|
62 |
-
print(endpoint_url)
|
63 |
response = requests.get(endpoint_url, headers=headers)
|
64 |
|
65 |
for compute in response.json()['items']:
|
@@ -134,7 +133,6 @@ def submit(
|
|
134 |
|
135 |
|
136 |
payload = json.dumps(payload)
|
137 |
-
print(f"Payload: {payload}")
|
138 |
|
139 |
headers = {
|
140 |
"Authorization": f"Bearer {hf_token_input.strip()}",
|
@@ -153,7 +151,7 @@ def submit(
|
|
153 |
elif response.status_code == 202:
|
154 |
return f"Endpoint {endpoint_name_input} created successfully on {provider_selector.lower()} using {repository_selector.lower()}@{revision_selector}. \n Please check out the progress at https://ui.endpoints.huggingface.co/endpoints."
|
155 |
else:
|
156 |
-
return f"
|
157 |
|
158 |
def delete_endpoint(
|
159 |
hf_token_input,
|
@@ -173,10 +171,11 @@ def delete_endpoint(
|
|
173 |
elif response.status_code == 202:
|
174 |
return f"Endpoint {endpoint_name_input} deleted successfully."
|
175 |
else:
|
176 |
-
return f"
|
177 |
|
178 |
def get_all_endpoints(
|
179 |
hf_token_input,
|
|
|
180 |
):
|
181 |
response = requests.get(
|
182 |
f"https://api.endpoints.huggingface.cloud/endpoint",
|
@@ -185,23 +184,38 @@ def get_all_endpoints(
|
|
185 |
"Content-Type": "application/json",
|
186 |
})
|
187 |
if response.status_code == 401:
|
188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
elif response.status_code == 200:
|
190 |
endpoints_json = response.json()
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
)
|
206 |
|
207 |
def update_endpoint(
|
@@ -216,11 +230,11 @@ def update_endpoint(
|
|
216 |
"instanceSize": instance_type.split("路")[0].split("[")[1].split("]")[0],
|
217 |
"instanceType": instance_type.split("路")[-1].strip(),
|
218 |
"scaling": {
|
219 |
-
"maxReplica": max_node_selector,
|
220 |
-
"minReplica": min_node_selector
|
221 |
}
|
222 |
}}
|
223 |
-
|
224 |
response = requests.put(
|
225 |
f"https://api.endpoints.huggingface.cloud/endpoint/{endpoint_name_input}",
|
226 |
headers = {
|
@@ -236,7 +250,7 @@ def update_endpoint(
|
|
236 |
elif response.status_code == 202:
|
237 |
return f"Endpoint {endpoint_name_input} updated successfully."
|
238 |
else:
|
239 |
-
return f"
|
240 |
|
241 |
with gr.Blocks() as interface:
|
242 |
gr.Markdown("""
|
@@ -253,7 +267,7 @@ with gr.Blocks() as interface:
|
|
253 |
### All Deployed Endpoints
|
254 |
""")
|
255 |
endpoints_table = gr.Dataframe(
|
256 |
-
headers=["Endpoint Name", "
|
257 |
col_count=(9, "fixed"),
|
258 |
)
|
259 |
endpoint_info_button = gr.Button(value="Get Info")
|
@@ -398,7 +412,7 @@ with gr.Blocks() as interface:
|
|
398 |
gr.Markdown("""
|
399 |
### <br><center style="color:green">(Update 馃攣 Endpoint)</center>
|
400 |
""")
|
401 |
-
|
402 |
with gr.Row():
|
403 |
gr.Markdown("""
|
404 |
#### Cloud Provider
|
@@ -432,7 +446,9 @@ with gr.Blocks() as interface:
|
|
432 |
""")
|
433 |
|
434 |
with gr.Row():
|
435 |
-
update_endpoint_name_input = gr.
|
|
|
|
|
436 |
show_label=False
|
437 |
)
|
438 |
update_compute_selector = gr.Dropdown(
|
@@ -534,7 +550,7 @@ with gr.Blocks() as interface:
|
|
534 |
# Info Tab Events
|
535 |
endpoint_info_button.click(
|
536 |
get_all_endpoints,
|
537 |
-
inputs=hf_token_input,
|
538 |
outputs=endpoints_table
|
539 |
)
|
540 |
|
@@ -560,6 +576,11 @@ with gr.Blocks() as interface:
|
|
560 |
outputs=status_txt)
|
561 |
|
562 |
# Update Tab Events
|
|
|
|
|
|
|
|
|
|
|
563 |
update_provider_selector.change(update_regions, inputs=update_provider_selector, outputs=update_region_selector)
|
564 |
update_region_selector.change(update_compute_options, inputs=[update_provider_selector, update_region_selector], outputs=update_compute_selector)
|
565 |
update_button.click(
|
|
|
59 |
"Content-Type": "application/json",
|
60 |
}
|
61 |
endpoint_url = f"https://api.endpoints.huggingface.cloud/provider/{provider}/region/{region}/compute"
|
|
|
62 |
response = requests.get(endpoint_url, headers=headers)
|
63 |
|
64 |
for compute in response.json()['items']:
|
|
|
133 |
|
134 |
|
135 |
payload = json.dumps(payload)
|
|
|
136 |
|
137 |
headers = {
|
138 |
"Authorization": f"Bearer {hf_token_input.strip()}",
|
|
|
151 |
elif response.status_code == 202:
|
152 |
return f"Endpoint {endpoint_name_input} created successfully on {provider_selector.lower()} using {repository_selector.lower()}@{revision_selector}. \n Please check out the progress at https://ui.endpoints.huggingface.co/endpoints."
|
153 |
else:
|
154 |
+
return f"Something went wrong!, StatusCode:{response.status_code}, Error: {response.text}"
|
155 |
|
156 |
def delete_endpoint(
|
157 |
hf_token_input,
|
|
|
171 |
elif response.status_code == 202:
|
172 |
return f"Endpoint {endpoint_name_input} deleted successfully."
|
173 |
else:
|
174 |
+
return f"Something went wrong!, StatusCode:{response.status_code}, Error: {response.text}"
|
175 |
|
176 |
def get_all_endpoints(
|
177 |
hf_token_input,
|
178 |
+
method,
|
179 |
):
|
180 |
response = requests.get(
|
181 |
f"https://api.endpoints.huggingface.cloud/endpoint",
|
|
|
184 |
"Content-Type": "application/json",
|
185 |
})
|
186 |
if response.status_code == 401:
|
187 |
+
if method == "info":
|
188 |
+
return gr.DataFrame.update(
|
189 |
+
value=[["Invalid token", "Invalid token", "Invalid token", "Invalid token", "Invalid token", "Invalid token", "Invalid token", "Invalid token", "Invalid token"]],
|
190 |
+
)
|
191 |
+
else:
|
192 |
+
return gr.Dropdown.update(
|
193 |
+
value="Invalid token or No endpoints found!",
|
194 |
+
)
|
195 |
elif response.status_code == 200:
|
196 |
endpoints_json = response.json()
|
197 |
+
if method == "info":
|
198 |
+
endpoints_df = pd.DataFrame(columns=["name", "model", "provider", "compute", "status", "minReplica", "maxReplica", "createdAt", "updatedAt"])
|
199 |
+
for endpoint in endpoints_json["items"]:
|
200 |
+
endpoints_df = endpoints_df.append({
|
201 |
+
"name": endpoint["name"],
|
202 |
+
"model": endpoint["model"]["repository"] + "@" + endpoint["model"]["revision"],
|
203 |
+
"provider": endpoint["provider"]["vendor"] + "/" + endpoint["provider"]["region"],
|
204 |
+
"compute": endpoint["compute"]["instanceType"] + "路" + endpoint["compute"]["instanceSize"] + " [" + endpoint["compute"]["accelerator"] + "]",
|
205 |
+
"status": endpoint["status"]["state"],
|
206 |
+
"minReplica": endpoint["compute"]["scaling"]["minReplica"],
|
207 |
+
"maxReplica": endpoint["compute"]["scaling"]["maxReplica"],
|
208 |
+
"createdAt": endpoint["status"]["createdAt"],
|
209 |
+
"updatedAt": endpoint["status"]["updatedAt"],
|
210 |
+
}, ignore_index=True)
|
211 |
+
endpoints_df.columns = ["Endpoint Name", "Model Name @ Revision", "Provider", "Instance Type", "Status", "Min Replica", "Max Replica", "Created At", "Updated At"]
|
212 |
+
return gr.DataFrame.update(
|
213 |
+
value=endpoints_df,
|
214 |
+
)
|
215 |
+
else:
|
216 |
+
return gr.Dropdown.update(
|
217 |
+
choices=[endpoint["name"] for endpoint in endpoints_json["items"]],
|
218 |
+
value=endpoints_json["items"][0]["name"],
|
219 |
)
|
220 |
|
221 |
def update_endpoint(
|
|
|
230 |
"instanceSize": instance_type.split("路")[0].split("[")[1].split("]")[0],
|
231 |
"instanceType": instance_type.split("路")[-1].strip(),
|
232 |
"scaling": {
|
233 |
+
"maxReplica": int(max_node_selector),
|
234 |
+
"minReplica": int(min_node_selector)
|
235 |
}
|
236 |
}}
|
237 |
+
payload = json.dumps(payload)
|
238 |
response = requests.put(
|
239 |
f"https://api.endpoints.huggingface.cloud/endpoint/{endpoint_name_input}",
|
240 |
headers = {
|
|
|
250 |
elif response.status_code == 202:
|
251 |
return f"Endpoint {endpoint_name_input} updated successfully."
|
252 |
else:
|
253 |
+
return f"Something went wrong!, StatusCode:{response.status_code}, Error: {response.text}"
|
254 |
|
255 |
with gr.Blocks() as interface:
|
256 |
gr.Markdown("""
|
|
|
267 |
### All Deployed Endpoints
|
268 |
""")
|
269 |
endpoints_table = gr.Dataframe(
|
270 |
+
headers=["Endpoint Name", "Model Name", "Provider", "Instance Type", "Status", "Min Replica", "Max Replica", "Created At", "Updated At"],
|
271 |
col_count=(9, "fixed"),
|
272 |
)
|
273 |
endpoint_info_button = gr.Button(value="Get Info")
|
|
|
412 |
gr.Markdown("""
|
413 |
### <br><center style="color:green">(Update 馃攣 Endpoint)</center>
|
414 |
""")
|
415 |
+
update_endpoint_info_button = gr.Button(value="Load Endpoints 馃攦")
|
416 |
with gr.Row():
|
417 |
gr.Markdown("""
|
418 |
#### Cloud Provider
|
|
|
446 |
""")
|
447 |
|
448 |
with gr.Row():
|
449 |
+
update_endpoint_name_input = gr.Dropdown(
|
450 |
+
[],
|
451 |
+
value="",
|
452 |
show_label=False
|
453 |
)
|
454 |
update_compute_selector = gr.Dropdown(
|
|
|
550 |
# Info Tab Events
|
551 |
endpoint_info_button.click(
|
552 |
get_all_endpoints,
|
553 |
+
inputs=[hf_token_input, gr.TextArea(value="info", interactive=False, visible=False)],
|
554 |
outputs=endpoints_table
|
555 |
)
|
556 |
|
|
|
576 |
outputs=status_txt)
|
577 |
|
578 |
# Update Tab Events
|
579 |
+
update_endpoint_info_button.click(
|
580 |
+
get_all_endpoints,
|
581 |
+
inputs=[hf_token_input, gr.TextArea(value="update", interactive=False, visible=False)],
|
582 |
+
outputs=update_endpoint_name_input
|
583 |
+
)
|
584 |
update_provider_selector.change(update_regions, inputs=update_provider_selector, outputs=update_region_selector)
|
585 |
update_region_selector.change(update_compute_options, inputs=[update_provider_selector, update_region_selector], outputs=update_compute_selector)
|
586 |
update_button.click(
|
requirements.txt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
pandas
|
2 |
numpy
|
3 |
gradio
|
|
|
1 |
+
pandas==1.3.5
|
2 |
numpy
|
3 |
gradio
|