prxyasd commited on
Commit
3a5a2dc
Β·
verified Β·
1 Parent(s): a665f3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -113
app.py CHANGED
@@ -1,139 +1,120 @@
 
1
  import gradio as gr
2
  import requests, re
3
- from api_usage import (
4
- get_subscription, check_key_availability, get_orgs_me,
5
- check_key_ant_availability, check_ant_rate_limit, check_key_gemini_availability,
6
- check_key_azure_availability, get_azure_status, get_azure_deploy,
7
- check_key_mistral_availability, check_mistral_quota, check_key_replicate_availability,
8
- check_key_aws_availability, check_key_or_availability, check_key_or_limits,
9
- check_gcp_anthropic, check_groq_status, check_nai_status,
10
- check_elevenlabs_status, check_xai_status, check_stability_status,
11
- check_deepseek_status, not_supported
12
- )
13
-
14
- async def sort_key(key, rate_limit, claude_model):
15
- """
16
- Check a single API key and return its info dict.
17
- """
18
  _key = key.strip()
19
 
20
- # OpenRouter
21
- if re.match(r"^sk-or-v1-[a-z0-9]{64}$", _key):
22
- return get_key_openrouter_info(_key)
23
- # Anthropic Claude
24
- if (re.match(r"^sk-ant-api03-[A-Za-z0-9\-_]{93}AA$", _key)
25
- or (_key.startswith("sk-ant-") and len(_key) == 93)
26
- or (len(_key) == 89 and re.match(r"^sk-[A-Za-z0-9]{86}$", _key))):
27
- return await get_key_ant_info(_key, rate_limit, claude_model)
28
- # Stability AI
29
- if re.match(r"^sk-[A-Za-z0-9]{48}$", _key) and len(_key) == 51 and 'T3BlbkFJ' not in _key:
30
- return get_key_stability_info(_key)
31
- # Deepseek
32
- if re.match(r"^sk-[a-f0-9]{32}$", _key):
33
- return get_key_deepseek_info(_key)
34
- # OpenAI
35
  if _key.startswith("sk-"):
36
- return get_key_oai_info(_key)
37
- # Google Gemini
38
  if _key.startswith("AIzaSy"):
39
- return get_key_gemini_info(_key)
40
- # NovelAI
41
  if _key.startswith("pst-"):
42
- return get_key_nai_info(_key)
43
- # Replicate
44
- if ((_key.startswith("r8_") and len(_key) == 40)
45
- or (_key.islower() and len(_key) == 40)):
46
- return get_key_replicate_info(_key)
47
- # xAI Grok
48
  if _key.startswith("xai-"):
49
- return get_key_xai_info(_key)
50
- # Azure OpenAI
51
- if len(_key.split(':')) == 2 and _key.split(':')[1].islower() and len(_key.split(':')[1]) == 32:
52
- endpoint, api_key = _key.split(':')
53
- return get_key_azure_info(f"{endpoint}.openai.azure.com", api_key)
54
- if "openai.azure.com" in _key:
55
- endpoint, api_key = _key.split(';')
56
- return get_key_azure_info(endpoint, api_key)
57
- # AWS
58
- if _key.startswith("AKIA") and len(_key.split(':')[0]) == 20 and _key.split(':')[0].isupper():
59
- return await get_key_aws_info(_key)
60
- # ElevenLabs
61
- if re.match(r"^[a-f0-9]{32}$", _key) or re.match(r"^sk_[a-f0-9]{48}$", _key):
62
- return get_key_elevenlabs_info(_key)
63
- # Mistral AI
64
- if re.match(r"^[A-Za-z0-9]{32}$", _key):
65
- return get_key_mistral_info(_key)
66
- # Groq
67
- if re.match(r"^gsk_[A-Za-z0-9]{20}WGdyb3FY[A-Za-z0-9]{24}$", _key):
68
- return get_key_groq_info(_key)
69
- # GCP Anthropic
70
- if re.match(r"[\w\-]+:[\w\-@\.]+:[\w\-]+:.+", _key):
71
- return await get_key_gcp_info(_key, 0)
72
- if re.match(r"[\w\-]+:[\w\-@\.]+:.+\\n", _key):
73
- return await get_key_gcp_info(_key, 1)
74
-
75
- # Fallback for unsupported formats
76
- return not_supported(_key)
77
-
78
- async def sort_keys(keys_text, rate_limit, claude_model):
79
- """
80
- Split input by newline and lookup each key in turn.
81
- Returns a mapping from each key to its info dict.
82
- """
83
- keys = [k.strip() for k in keys_text.splitlines() if k.strip()]
84
- results = {}
85
- for k in keys:
86
- results[k] = await sort_key(k, rate_limit, claude_model)
87
- return results
88
-
89
-
90
- def clear_inputs(text):
91
- return ""
92
 
93
- with gr.Blocks() as demo:
94
- gr.Markdown('''
95
- # Multi-Key API Key Status Checker
 
 
 
 
 
 
 
 
 
 
96
 
97
- Enter one API key per line; this tool will check each in turn.
98
- ''')
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  claude_options = [
101
- 'claude-3-haiku-20240307',
102
- 'claude-3-sonnet-20240229',
103
- 'claude-3-opus-20240229',
104
- 'claude-3-5-sonnet-20240620',
105
- 'claude-3-5-sonnet-20241022',
106
- 'claude-3-5-haiku-20241022'
107
  ]
108
-
109
  with gr.Row():
110
  with gr.Column():
111
- key_input = gr.Textbox(
112
- lines=5,
113
- placeholder="sk-... or AKIA...",
114
- label="API Keys (one per line)"
115
  )
116
  claude_model = gr.Dropdown(
117
  claude_options,
118
  value="claude-3-haiku-20240307",
119
- label="Claude API model",
120
- info="Model for filter_response and concurrent rate check"
121
- )
122
- rate_limit = gr.Checkbox(
123
- label="Check concurrent rate limit (Anthropic Claude)"
124
  )
 
125
  with gr.Row():
126
  clear_button = gr.Button("Clear")
127
  submit_button = gr.Button("Submit", variant="primary")
128
  with gr.Column():
129
- info = gr.JSON(label="API Keys Information", open=True)
130
-
131
- clear_button.click(fn=clear_inputs, inputs=[key_input], outputs=[key_input])
132
- submit_button.click(
133
- fn=sort_keys,
134
- inputs=[key_input, rate_limit, claude_model],
135
- outputs=[info],
136
- api_name="sort_keys"
137
- )
138
 
139
  demo.launch()
 
1
+ import asyncio
2
  import gradio as gr
3
  import requests, re
4
+ # …(μƒλž΅)…
5
+
6
+ # ────────────────────────────────────
7
+ # 1. 단일 ν‚€ 처리 ν•¨μˆ˜λ‘œ κΈ°μ‘΄ 둜직 이동
8
+ # ────────────────────────────────────
9
+ async def process_single_key(key, rate_limit, claude_model):
 
 
 
 
 
 
 
 
 
10
  _key = key.strip()
11
 
12
+ if re.match(re.compile("sk-or-v1-[a-z0-9]{64}"), _key):
13
+ return {"key": _key, **get_key_openrouter_info(_key)}
14
+
15
+ if re.match(re.compile("sk-ant-api03-[a-zA-Z0-9\\-_]{93}AA"), _key) or (
16
+ _key.startswith("sk-ant-") and len(_key) == 93
17
+ ) or (len(_key) == 89 and re.match(re.compile("sk-[a-zA-Z0-9]{86}"), _key)):
18
+ return {"key": _key, **await get_key_ant_info(_key, rate_limit, claude_model)}
19
+
20
+ if re.match(re.compile(r"sk-[a-zA-Z0-9]{48}"), _key) and len(_key) == 51 and "T3BlbkFJ" not in _key:
21
+ return {"key": _key, **get_key_stability_info(_key)}
22
+
23
+ if re.match(re.compile(r"sk-[a-f0-9]{32}"), _key):
24
+ return {"key": _key, **get_key_deepseek_info(_key)}
25
+
 
26
  if _key.startswith("sk-"):
27
+ return {"key": _key, **get_key_oai_info(_key)}
28
+
29
  if _key.startswith("AIzaSy"):
30
+ return {"key": _key, **get_key_gemini_info(_key)}
31
+
32
  if _key.startswith("pst-"):
33
+ return {"key": _key, **get_key_nai_info(_key)}
34
+
35
+ if (_key.startswith("r8_") and len(_key) == 40) or (_key.islower() and len(_key) == 40):
36
+ return {"key": _key, **get_key_replicate_info(_key)}
37
+
 
38
  if _key.startswith("xai-"):
39
+ return {"key": _key, **get_key_xai_info(_key)}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
+ if len(_key.split(":")) == 2 and _key.split(":")[1].islower() and len(_key.split(":")[1]) == 32 and "openai.azure.com" not in _key.split(":")[1]:
42
+ endpoint, api_key = _key.split(":")
43
+ return {"key": _key, **get_key_azure_info(endpoint, api_key)}
44
+
45
+ if "openai.azure.com" in _key.split(";")[0]:
46
+ endpoint, api_key = _key.split(";")
47
+ return {"key": _key, **get_key_azure_info(endpoint, api_key)}
48
+
49
+ if _key.startswith("AKIA") and len(_key.split(":")[0]) == 20 and _key.split(":")[0].isupper():
50
+ return {"key": _key, **await get_key_aws_info(_key)}
51
+
52
+ if re.match(re.compile(r"[a-f0-9]{32}"), _key) or re.match(re.compile(r"sk_[a-f0-9]{48}"), _key):
53
+ return {"key": _key, **get_key_elevenlabs_info(_key)}
54
 
55
+ if re.match(re.compile(r"[a-zA-Z0-9]{32}"), _key):
56
+ return {"key": _key, **get_key_mistral_info(_key)}
57
 
58
+ if re.match(re.compile(r"gsk_[a-zA-Z0-9]{20}WGdyb3FY[a-zA-Z0-9]{24}"), _key):
59
+ return {"key": _key, **get_key_groq_info(_key)}
60
+
61
+ if re.match(re.compile(r"[\\w\\-]+:[\\w\\-@\\.]+:[\\w-]+:.+"), _key):
62
+ return {"key": _key, **await get_key_gcp_info(_key, 0)}
63
+
64
+ if re.match(re.compile(r"[\\w\\-]+:[\\w\\-@\\.]+:.+\\n"), _key):
65
+ return {"key": _key, **await get_key_gcp_info(_key, 1)}
66
+
67
+ return {"key": _key, **not_supported(_key)}
68
+
69
+ # ────────────────────────────────────
70
+ # 2. μ—¬λŸ¬ ν‚€ ν•œκΊΌλ²ˆμ— 처리
71
+ # ────────────────────────────────────
72
+ async def sort_keys(text, rate_limit, claude_model):
73
+ keys = [k for k in text.splitlines() if k.strip()]
74
+ tasks = [process_single_key(k, rate_limit, claude_model) for k in keys]
75
+ results = await asyncio.gather(*tasks)
76
+ return results # JSON μ»΄ν¬λ„ŒνŠΈκ°€ λ¦¬μŠ€νŠΈλ„ 잘 λ³΄μ—¬μ€Œ
77
+
78
+ def clear_inputs(text): # κ·ΈλŒ€λ‘œ
79
+ return ""
80
+
81
+ # ────────────────────────────────────
82
+ # 3. UI – μž…λ ₯μ°½ 쀄 수 늘리고, μƒˆ ν•¨μˆ˜ μ—°κ²°
83
+ # ────────────────────────────────────
84
+ with gr.Blocks() as demo:
85
+ gr.Markdown(
86
+ """
87
+ # … (μ€‘λž΅) …
88
+ """
89
+ )
90
  claude_options = [
91
+ "claude-3-haiku-20240307",
92
+ "claude-3-sonnet-20240229",
93
+ "claude-3-opus-20240229",
94
+ "claude-3-5-sonnet-20240620",
95
+ "claude-3-5-sonnet-20241022",
96
+ "claude-3-5-haiku-20241022",
97
  ]
 
98
  with gr.Row():
99
  with gr.Column():
100
+ key = gr.Textbox(
101
+ lines=5, # μ—¬λŸ¬ 쀄 μž…λ ₯
102
+ max_lines=20,
103
+ label="API Key(s) β€” μ€„λ°”κΏˆμœΌλ‘œ μ—¬λŸ¬ 개 μž…λ ₯",
104
  )
105
  claude_model = gr.Dropdown(
106
  claude_options,
107
  value="claude-3-haiku-20240307",
108
+ label="Claude API model (rate-limit check용)",
 
 
 
 
109
  )
110
+ rate_limit = gr.Checkbox(label="Check concurrent rate limit (Claude, experimental)")
111
  with gr.Row():
112
  clear_button = gr.Button("Clear")
113
  submit_button = gr.Button("Submit", variant="primary")
114
  with gr.Column():
115
+ info = gr.JSON(label="API Key Information", open=True)
116
+
117
+ clear_button.click(fn=clear_inputs, inputs=[key], outputs=[key])
118
+ submit_button.click(fn=sort_keys, inputs=[key, rate_limit, claude_model], outputs=[info], api_name="sort_keys")
 
 
 
 
 
119
 
120
  demo.launch()