Spaces:
Sleeping
Sleeping
File size: 2,659 Bytes
98c28c1 73540fd 98c28c1 73540fd 91a1375 73540fd 91a1375 73540fd 98c28c1 049253f 98c28c1 550dfd0 98c28c1 beff183 049253f 9d3366b 58e0b0e 049253f beff183 98c28c1 974eee9 58e0b0e 049253f 58e0b0e beff183 98c28c1 73540fd 00ee4c4 73540fd 98c28c1 73540fd 9784311 42d7a9a 98c28c1 73540fd 98c28c1 73540fd 98c28c1 73540fd 98c28c1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import gradio as gr
import anthropic
from api_usage import get_subscription, check_key_availability, check_key_ant_availability
def sort_key(key):
_key = key.strip()
if _key.startswith("sk-ant-"):
return get_key_ant_info(_key)
else:
return get_key_oai_info(_key)
def get_key_oai_info(key):
# Return a dictionary containing key information
key_avai = check_key_availability(key)
info_dict = {"account_name": "",
"key_availability": True if key_avai else False,
"gpt4_availability": "",
"gpt4_32k_availability": "",
"default_org": "",
"org_description": "",
"organization": "",
"models": "",
"requests_per_minute": "",
"tokens_per_minute": "",
#"tokens_per_minute_left": "",
"quota": ""}
if key_avai:
info = get_subscription(key, key_avai)
info_dict["gpt4_availability"] = info["has_gpt4"]
info_dict["gpt4_32k_availability"] = info["has_gpt4_32k"]
info_dict["default_org"] = info["default_org"]
info_dict["org_description"] = info["org_description"]
info_dict["organization"] = info["organization"]
info_dict["models"] = info["models"]
info_dict["requests_per_minute"] = info["rpm"]
info_dict["tokens_per_minute"] = info["tpm"]
info_dict["quota"] = info["quota"]
return info_dict
def get_key_ant_info(key):
# Return a dictionary containing key information
ant = anthropic.Anthropic(api_key=key)
key_avai_ant = check_key_ant_availability(ant)
info_dict = {"account_name": "",
"key_availability": key_avai_ant[0],
"status": key_avai_ant[1],
"filter_response": key_avai_ant[2]}
return info_dict
def clear_inputs(text):
return ""
with gr.Blocks() as demo:
gr.Markdown('''
# OpenAI/Anthropic API Key Status Checker
*(Based on shaocongma and CncAnon1 key checker)*
''')
with gr.Row():
with gr.Column():
key = gr.Textbox(lines=1, max_lines=1, label="OpenAI/Anthropic API Key")
with gr.Row():
clear_button = gr.Button("Clear")
submit_button = gr.Button("Submit", variant="primary")
with gr.Column():
info = gr.JSON(label="OpenAI/Anthropic API Key Information")
clear_button.click(fn=clear_inputs, inputs=[key], outputs=[key])
submit_button.click(fn=sort_key, inputs=[key], outputs=[info], api_name="sort_key")
demo.launch() |