superdup95 commited on
Commit
73540fd
1 Parent(s): 0360007

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -1,8 +1,15 @@
1
  import gradio as gr
2
  import openai
3
- from api_usage import get_subscription, check_key_availability #, get_usage, check_gpt4_availability, check_gpt4_32k_availability,
 
4
 
5
- def get_key_info(key):
 
 
 
 
 
 
6
  # Return a dictionary containing key information
7
  openai.api_key = key
8
  key_avai = check_key_availability()
@@ -16,7 +23,6 @@ def get_key_info(key):
16
  "quota": ""}
17
  if key_avai:
18
  info = get_subscription(key, key_avai)
19
- # info_dict["account_name"] = info["account_name"]
20
  info_dict["gpt4_availability"] = info["has_gpt4"]
21
  info_dict["gpt4_32k_availability"] = info["has_gpt4_32k"]
22
  info_dict["requests_per_minute"] = info["rpm"]
@@ -25,26 +31,34 @@ def get_key_info(key):
25
  info_dict["quota"] = info["quota"]
26
  return info_dict
27
 
 
 
 
 
 
 
 
 
28
 
29
  def clear_inputs(text):
30
  return ""
31
 
32
  with gr.Blocks() as demo:
33
  gr.Markdown('''
34
- # OpenAI API Key Status Checker
35
 
36
  *(Based on shaocongma and CncAnon1 key checker)*
37
  ''')
38
 
39
  with gr.Row():
40
  with gr.Column():
41
- key = gr.Textbox(lines=1, max_lines=1, label="OpenAI API Key")
42
  with gr.Row():
43
  clear_button = gr.Button("Clear")
44
  submit_button = gr.Button("Submit", variant="primary")
45
  with gr.Column():
46
- info = gr.JSON(label="OpenAI API Key Information")
47
 
48
  clear_button.click(fn=clear_inputs, inputs=[key], outputs=[key])
49
- submit_button.click(fn=get_key_info, inputs=[key], outputs=[info], api_name="get_key_info")
50
  demo.launch()
 
1
  import gradio as gr
2
  import openai
3
+ import anthropic
4
+ from api_usage import get_subscription, check_key_availability, check_key_ant_availability
5
 
6
+ def sort_key(key):
7
+ if key.startswith("sk-ant-"):
8
+ return get_key_ant_info(key)
9
+ else:
10
+ return get_key_oai_info(key)
11
+
12
+ def get_key_oai_info(key):
13
  # Return a dictionary containing key information
14
  openai.api_key = key
15
  key_avai = check_key_availability()
 
23
  "quota": ""}
24
  if key_avai:
25
  info = get_subscription(key, key_avai)
 
26
  info_dict["gpt4_availability"] = info["has_gpt4"]
27
  info_dict["gpt4_32k_availability"] = info["has_gpt4_32k"]
28
  info_dict["requests_per_minute"] = info["rpm"]
 
31
  info_dict["quota"] = info["quota"]
32
  return info_dict
33
 
34
+ def get_key_ant_info(key):
35
+ # Return a dictionary containing key information
36
+ ant = anthropic.Anthropic(api_key=key)
37
+ key_avai_ant = check_key_ant_availability(ant)
38
+ info_dict = {"account_name": "",
39
+ "key_availability": key_avai_ant[0],
40
+ "status": f"{key_avai_ant[1]}"}
41
+ return info_dict
42
 
43
  def clear_inputs(text):
44
  return ""
45
 
46
  with gr.Blocks() as demo:
47
  gr.Markdown('''
48
+ # OpenAI/Anthropic API Key Status Checker
49
 
50
  *(Based on shaocongma and CncAnon1 key checker)*
51
  ''')
52
 
53
  with gr.Row():
54
  with gr.Column():
55
+ key = gr.Textbox(lines=1, max_lines=1, label="OpenAI/Anthropic API Key")
56
  with gr.Row():
57
  clear_button = gr.Button("Clear")
58
  submit_button = gr.Button("Submit", variant="primary")
59
  with gr.Column():
60
+ info = gr.JSON(label="OpenAI/Anthropic API Key Information")
61
 
62
  clear_button.click(fn=clear_inputs, inputs=[key], outputs=[key])
63
+ submit_button.click(fn=sort_key, inputs=[key], outputs=[info], api_name="sort_key")
64
  demo.launch()