superdup95's picture
Update app.py
73540fd
raw
history blame
2.27 kB
import gradio as gr
import openai
import anthropic
from api_usage import get_subscription, check_key_availability, check_key_ant_availability
def sort_key(key):
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
openai.api_key = key
key_avai = check_key_availability()
info_dict = {"account_name": "",
"key_availability": True if key_avai else False,
"gpt4_availability": "",
"gpt4_32k_availability": "",
"requests_per_minute": "",
"tokens_per_minute": "",
"organization": "",
"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["requests_per_minute"] = info["rpm"]
info_dict["tokens_per_minute"] = info["tpm"]
info_dict["organization"] = info["organization"]
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": f"{key_avai_ant[1]}"}
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()