sasaki-saku commited on
Commit
1ad76f4
1 Parent(s): 06f38cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -32
app.py CHANGED
@@ -1,19 +1,30 @@
1
  import gradio as gr
2
  import anthropic
3
- from api_usage import get_subscription, check_key_availability, check_key_ant_availability, check_key_gemini_availability, check_key_azure_availability, get_azure_status, get_azure_deploy
4
 
5
  def sort_key(key):
6
  _key = key.strip()
7
  if _key.startswith("sk-ant-"):
8
- return get_key_ant_info(_key)
 
 
9
  elif _key.startswith("AIzaSy"):
10
- return get_key_gemini_info(_key)
 
 
 
 
11
  elif "openai.azure.com" in _key.split(';')[0]:
12
- return get_key_azure_info(_key)
13
- elif _key.startswith("AKIA"):
14
- return get_key_aws_info(_key)
 
 
 
 
15
  else:
16
- return get_key_oai_info(_key)
 
17
 
18
  def get_key_oai_info(key):
19
  # Return a dictionary containing key information
@@ -63,34 +74,58 @@ def get_key_gemini_info(key):
63
  "models": key_avai[1]}
64
  return info_dict
65
 
66
- def get_key_azure_info(key):
67
- key_avai = check_key_azure_availability(key)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  if key_avai[0]:
69
- azure_deploy = get_azure_deploy(key)
70
- status = get_azure_status(key, azure_deploy)
71
- info_dict = {#"account_name": "",
72
- "key_type": "Microsoft Azure OpenAI",
73
- "key_availability": key_avai[0],
74
- "gpt4_32k_availability": status[1],
75
- "gpt4_turbo_availability": status[2],
76
- "gpt4_availability": status[3],
77
- "gpt35_availability": status[4],
78
- "models": key_avai[1],
79
- "deployments": azure_deploy,
80
- "moderation_response": status[0]}
81
- else:
82
- info_dict = {#"account_name": "",
83
- "key_type": "Microsoft Azure OpenAI",
84
- "key_availability": False,
85
- "models": None,
86
- "deployments": None,
87
- "moderation_response": ""}
88
  return info_dict
89
 
90
  def get_key_aws_info(key):
91
  info_dict = {#"account_name": "",
92
- "key_type": "Amazon AWS Claude",
93
- "status": " Soon™ "}
 
 
 
 
 
 
94
  return info_dict
95
 
96
  def clear_inputs(text):
@@ -98,7 +133,9 @@ def clear_inputs(text):
98
 
99
  with gr.Blocks() as demo:
100
  gr.Markdown('''
101
- # OpenAI/Anthropic/Google Gemini/Microsoft Azure API Key Status Checker
 
 
102
 
103
  *(Based on shaocongma, CncAnon1 and Drago key checkers)*
104
 
@@ -107,7 +144,7 @@ with gr.Blocks() as demo:
107
 
108
  with gr.Row():
109
  with gr.Column():
110
- key = gr.Textbox(lines=1, max_lines=1, label="OpenAI/Anthropic/Gemini/Azure API Key")
111
  with gr.Row():
112
  clear_button = gr.Button("Clear")
113
  submit_button = gr.Button("Submit", variant="primary")
 
1
  import gradio as gr
2
  import anthropic
3
+ from api_usage import get_subscription, check_key_availability, check_key_ant_availability, check_key_gemini_availability, check_key_azure_availability, get_azure_status, get_azure_deploy, check_key_mistral_availability, check_mistral_quota
4
 
5
  def sort_key(key):
6
  _key = key.strip()
7
  if _key.startswith("sk-ant-"):
8
+ return get_key_ant_info(_key)
9
+ elif _key.startswith("sk-"):
10
+ return get_key_oai_info(_key)
11
  elif _key.startswith("AIzaSy"):
12
+ return get_key_gemini_info(_key)
13
+ elif len(_key.split(':')) == 2 and _key.split(':')[1].islower() and len(_key.split(':')[1]) == 32:
14
+ endpoint = _key.split(':')[0]
15
+ api_key = _key.split(':')[1]
16
+ return get_key_azure_info(endpoint, api_key)
17
  elif "openai.azure.com" in _key.split(';')[0]:
18
+ endpoint = _key.split(';')[0]
19
+ api_key = _key.split(';')[1]
20
+ return get_key_azure_info(endpoint, api_key)
21
+ elif _key.startswith("AKIA") and len(_key.split(':')[0]) == 20 and _key.split(':')[0].isupper():
22
+ return get_key_aws_info(_key)
23
+ elif len(_key) == 32:
24
+ return get_key_mistral_info(_key)
25
  else:
26
+ return not_supported(_key)
27
+
28
 
29
  def get_key_oai_info(key):
30
  # Return a dictionary containing key information
 
74
  "models": key_avai[1]}
75
  return info_dict
76
 
77
+ def get_key_gemini_info(key):
78
+ key_avai = check_key_gemini_availability(key)
79
+ info_dict = {#"account_name": "",
80
+ "key_type": "Google Gemini",
81
+ "key_availability": key_avai[0],
82
+ "models": key_avai[1]}
83
+ return info_dict
84
+
85
+ def get_key_azure_info(endpoint, api_key):
86
+ key_avai = check_key_azure_availability(endpoint, api_key)
87
+ info_dict = {#"account_name": "",
88
+ "key_type": "Microsoft Azure OpenAI",
89
+ "key_availability": key_avai[0],
90
+ "gpt35_availability": "",
91
+ "gpt4_availability": "",
92
+ "gpt4_turbo_availability": "",
93
+ "gpt4_32k_availability": "",
94
+ "moderation_response": "",
95
+ "deployments": "",
96
+ "models": ""}
97
  if key_avai[0]:
98
+ azure_deploy = get_azure_deploy(endpoint, api_key)
99
+ status = get_azure_status(endpoint, api_key, azure_deploy)
100
+ info_dict["gpt35_availability"] = status[1],
101
+ info_dict["gpt4_availability"] = status[2],
102
+ info_dict["gpt4_turbo_availability"] = status[3],
103
+ info_dict["gpt4_32k_availability"] = status[4],
104
+ info_dict["moderation_response"] = status[0],
105
+ info_dict["models"] = key_avai[1],
106
+ info_dict["deployments"] = azure_deploy
107
+ return info_dict
108
+
109
+ def get_key_mistral_info(key):
110
+ key_avai = check_key_mistral_availability(key)
111
+ info_dict = {#"account_name": "",
112
+ "key_type": "Mistral AI",
113
+ "key_availability": key_avai,
114
+ "has_quota": ""}
115
+ if key_avai:
116
+ info_dict['has_quota'] = check_mistral_quota(key)
117
  return info_dict
118
 
119
  def get_key_aws_info(key):
120
  info_dict = {#"account_name": "",
121
+ "key_type": "Amazon AWS Claude",
122
+ "status": " Soon™ "}
123
+ return info_dict
124
+
125
+ def not_supported(key):
126
+ info_dict = {#"account_name": "",
127
+ "key_type": "Not supported",
128
+ "status": ""}
129
  return info_dict
130
 
131
  def clear_inputs(text):
 
133
 
134
  with gr.Blocks() as demo:
135
  gr.Markdown('''
136
+ # API Key Status Checker
137
+
138
+ ### Supported: OpenAI/Anthropic/Google Gemini/Microsoft Azure/Mistral AI
139
 
140
  *(Based on shaocongma, CncAnon1 and Drago key checkers)*
141
 
 
144
 
145
  with gr.Row():
146
  with gr.Column():
147
+ key = gr.Textbox(lines=1, max_lines=1, label="API Key")
148
  with gr.Row():
149
  clear_button = gr.Button("Clear")
150
  submit_button = gr.Button("Submit", variant="primary")