Update app.py
Browse files
app.py
CHANGED
@@ -1,139 +1,120 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import requests, re
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
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 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
# OpenAI
|
35 |
if _key.startswith("sk-"):
|
36 |
-
return get_key_oai_info(_key)
|
37 |
-
|
38 |
if _key.startswith("AIzaSy"):
|
39 |
-
return get_key_gemini_info(_key)
|
40 |
-
|
41 |
if _key.startswith("pst-"):
|
42 |
-
return get_key_nai_info(_key)
|
43 |
-
|
44 |
-
if (
|
45 |
-
|
46 |
-
|
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 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
-
|
98 |
-
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
claude_options = [
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
]
|
108 |
-
|
109 |
with gr.Row():
|
110 |
with gr.Column():
|
111 |
-
|
112 |
-
lines=5,
|
113 |
-
|
114 |
-
label="API
|
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
|
130 |
-
|
131 |
-
clear_button.click(fn=clear_inputs, inputs=[
|
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()
|