File size: 6,215 Bytes
9d046f0 6fae987 b8c5fd6 daee03b 6b60398 9d046f0 daee03b 6fae987 9d046f0 daee03b 9d046f0 daee03b 9d046f0 daee03b 6fae987 a2608df daee03b 6fae987 daee03b 3566cff daee03b 6fae987 6f7a373 b8c5fd6 daee03b b8c5fd6 daee03b b8c5fd6 daee03b b8c5fd6 daee03b b8c5fd6 6b60398 daee03b 6b60398 daee03b 6b60398 92e809c daee03b 92e809c daee03b 92e809c daee03b f25ea0c daee03b f25ea0c daee03b f25ea0c daee03b 92e809c daee03b 3318229 3566cff 7c3cc6c 3318229 6b60398 3318229 3566cff 3318229 3566cff 6f7a373 3566cff b8c5fd6 6b60398 92e809c f25ea0c 3318229 3566cff 6b60398 3566cff 7c3cc6c 3566cff 7c3cc6c daee03b 7c3cc6c 6fae987 daee03b 9d046f0 3318229 6fae987 daee03b f25ea0c 6fae987 9d046f0 daee03b 9d046f0 3566cff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
import gradio as gr
from groq import Groq
import openai
import requests
import json
from google import genai
from google.genai import types
from googleapiclient.discovery import build
# ---- VERIFICACIÓN GROQ ----
def verificar_api_groq(api_key):
try:
client = Groq(api_key=api_key)
completion = client.chat.completions.create(
model="openai/gpt-oss-20b",
messages=[{"role": "user", "content": "hola"}],
temperature=1,
max_completion_tokens=50,
top_p=1,
reasoning_effort="medium",
stream=False,
stop=None
)
# Verifica que haya texto en la respuesta
if completion.choices and completion.choices[0].message.content:
return True
return False
except Exception as e:
print("Error en Groq:", e)
return False
# ---- VERIFICACIÓN GEMINI (nuevo SDK google-genai) ----
def verificar_api_gemini(api_key):
try:
client = genai.Client(api_key=api_key)
model = "gemini-2.5-pro"
contents = [
types.Content(
role="user",
parts=[types.Part.from_text(text="Hola")]
)
]
generate_content_config = types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(thinking_budget=-1)
)
# No usamos streaming para solo testear
response = client.models.generate_content(
model=model,
contents=contents,
config=generate_content_config
)
# Si hay texto, la API es válida
return bool(response.candidates and response.candidates[0].content.parts[0].text.strip())
except Exception as e:
print("Error en Gemini:", e)
return False
# ---- RESTO DE FUNCIONES IGUALES ----
def verificar_api_openai(api_key):
openai.api_key = api_key
try:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hola"}],
max_tokens=50,
temperature=0.7
)
return True
except Exception:
return False
def verificar_api_openrouter(api_key):
url = "https://openrouter.ai/api/v1/chat/completions"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
data = {
"model": "google/gemma-2-9b-it:free",
"messages": [{"role": "user", "content": "What is the meaning of life?"}]
}
try:
r = requests.post(url, headers=headers, data=json.dumps(data))
return r.status_code == 200
except Exception:
return False
def verificar_api_youtube(api_key):
try:
youtube = build("youtube", "v3", developerKey=api_key)
resp = youtube.search().list(q="test", part="snippet", maxResults=1).execute()
return bool(resp.get("items", []))
except Exception:
return False
def verificar_api_pexels(api_key):
try:
url = "https://api.pexels.com/v1/search"
headers = {"Authorization": api_key}
params = {"query": "nature", "per_page": 1}
r = requests.get(url, headers=headers, params=params)
if r.status_code == 200:
d = r.json()
return "photos" in d and len(d["photos"]) > 0
return False
except Exception:
return False
def verificar_api_google_places(api_key):
try:
url = "https://maps.googleapis.com/maps/api/place/textsearch/json"
params = {"query": "restaurants", "location": "0,0", "radius": 1000, "key": api_key}
r = requests.get(url, params=params)
if r.status_code == 200:
d = r.json()
return "results" in d and len(d["results"]) > 0
return False
except Exception:
return False
def verificar_api_unsplash(api_key):
try:
url = "https://api.unsplash.com/search/photos"
headers = {"Authorization": f"Client-ID {api_key}"}
params = {"query": "nature", "per_page": 1}
r = requests.get(url, headers=headers, params=params)
if r.status_code == 200:
d = r.json()
return "results" in d and len(d["results"]) > 0
return False
except Exception:
return False
# ---- VERIFICADOR GENERAL ----
def verificar_apis(api_keys_text, api_type):
api_keys = api_keys_text.strip().split("\n")
apis_validas = []
apis_invalidas = []
for api_key in api_keys:
api_key = api_key.strip()
if not api_key:
continue
if api_type == "Groq":
es_valida = verificar_api_groq(api_key)
elif api_type == "OpenAI":
es_valida = verificar_api_openai(api_key)
elif api_type == "Google Gemini":
es_valida = verificar_api_gemini(api_key)
elif api_type == "OpenRouter":
es_valida = verificar_api_openrouter(api_key)
elif api_type == "YouTube":
es_valida = verificar_api_youtube(api_key)
elif api_type == "Pexels":
es_valida = verificar_api_pexels(api_key)
elif api_type == "Google Places":
es_valida = verificar_api_google_places(api_key)
elif api_type == "Unsplash":
es_valida = verificar_api_unsplash(api_key)
else:
continue
if es_valida:
apis_validas.append(api_key)
else:
apis_invalidas.append(api_key)
resultado_final = (
"✅ APIs válidas:\n" + "\n".join(apis_validas) +
"\n\n⛔ APIs inválidas:\n" + "\n".join(apis_invalidas)
)
return resultado_final
# ---- INTERFAZ ----
iface = gr.Interface(
fn=verificar_apis,
inputs=[
gr.Textbox(label="API Keys (una por línea)", lines=10, placeholder="Introduce cada API key..."),
gr.Radio(["Groq", "OpenAI", "Google Gemini", "OpenRouter", "YouTube", "Pexels", "Google Places", "Unsplash"], label="Tipo de API")
],
outputs="text",
title="Verificación de APIs (Groq, OpenAI, Gemini, etc.)",
description="Comprueba si tus API keys siguen activas y funcionando."
)
if __name__ == "__main__":
iface.launch()
|