Update app.py
Browse files
app.py
CHANGED
|
@@ -23,9 +23,9 @@ def verificar_api_groq(api_key):
|
|
| 23 |
top_p=0.9,
|
| 24 |
stream=False
|
| 25 |
)
|
| 26 |
-
return
|
| 27 |
-
except Exception
|
| 28 |
-
return
|
| 29 |
|
| 30 |
# Función para verificar la API de OpenAI
|
| 31 |
def verificar_api_openai(api_key):
|
|
@@ -39,56 +39,51 @@ def verificar_api_openai(api_key):
|
|
| 39 |
max_tokens=50,
|
| 40 |
temperature=0.7
|
| 41 |
)
|
| 42 |
-
return
|
| 43 |
-
except openai.OpenAIError
|
| 44 |
-
return
|
| 45 |
-
except Exception
|
| 46 |
-
return
|
| 47 |
|
| 48 |
# Función para verificar la API de Google Gemini
|
| 49 |
def verificar_api_gemini(api_key):
|
| 50 |
try:
|
| 51 |
# Configurar la API de Google Gemini
|
| 52 |
genai.configure(api_key=api_key)
|
| 53 |
-
|
| 54 |
-
# Intentar generar una respuesta simple para verificar la API
|
| 55 |
model = genai.GenerativeModel('gemini-1.5-pro')
|
| 56 |
response = model.generate_content("Test message")
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
else:
|
| 61 |
-
return "⛔ No se pudo obtener respuesta de Google Gemini."
|
| 62 |
-
except Exception as e:
|
| 63 |
-
return f"⛔ Error en Google Gemini API: {str(e)}"
|
| 64 |
|
| 65 |
# Función general para verificar una lista de API keys
|
| 66 |
def verificar_apis(api_keys_text, api_type):
|
| 67 |
api_keys = api_keys_text.strip().split("\n")
|
| 68 |
-
|
| 69 |
-
|
| 70 |
|
| 71 |
for api_key in api_keys:
|
| 72 |
api_key = api_key.strip()
|
| 73 |
if not api_key:
|
| 74 |
continue
|
|
|
|
| 75 |
if api_type == "Groq":
|
| 76 |
-
|
| 77 |
elif api_type == "OpenAI":
|
| 78 |
-
|
| 79 |
elif api_type == "Google Gemini":
|
| 80 |
-
|
| 81 |
else:
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
# Clasificar
|
| 85 |
-
if
|
| 86 |
-
|
| 87 |
else:
|
| 88 |
-
|
| 89 |
|
| 90 |
# Formatear el resultado final con las secciones separadas
|
| 91 |
-
resultado_final = "APIs
|
| 92 |
return resultado_final
|
| 93 |
|
| 94 |
# Interfaz de Gradio
|
|
@@ -105,4 +100,4 @@ iface = gr.Interface(
|
|
| 105 |
|
| 106 |
# Ejecutar la interfaz en Hugging Face Space
|
| 107 |
if __name__ == "__main__":
|
| 108 |
-
iface.launch()
|
|
|
|
| 23 |
top_p=0.9,
|
| 24 |
stream=False
|
| 25 |
)
|
| 26 |
+
return True # API válida
|
| 27 |
+
except Exception:
|
| 28 |
+
return False # API inválida
|
| 29 |
|
| 30 |
# Función para verificar la API de OpenAI
|
| 31 |
def verificar_api_openai(api_key):
|
|
|
|
| 39 |
max_tokens=50,
|
| 40 |
temperature=0.7
|
| 41 |
)
|
| 42 |
+
return True # API válida
|
| 43 |
+
except openai.OpenAIError:
|
| 44 |
+
return False # API inválida
|
| 45 |
+
except Exception:
|
| 46 |
+
return False # API inválida
|
| 47 |
|
| 48 |
# Función para verificar la API de Google Gemini
|
| 49 |
def verificar_api_gemini(api_key):
|
| 50 |
try:
|
| 51 |
# Configurar la API de Google Gemini
|
| 52 |
genai.configure(api_key=api_key)
|
|
|
|
|
|
|
| 53 |
model = genai.GenerativeModel('gemini-1.5-pro')
|
| 54 |
response = model.generate_content("Test message")
|
| 55 |
+
return response is not None # API válida si hay respuesta
|
| 56 |
+
except Exception:
|
| 57 |
+
return False # API inválida
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
# Función general para verificar una lista de API keys
|
| 60 |
def verificar_apis(api_keys_text, api_type):
|
| 61 |
api_keys = api_keys_text.strip().split("\n")
|
| 62 |
+
apis_validas = []
|
| 63 |
+
apis_invalidas = []
|
| 64 |
|
| 65 |
for api_key in api_keys:
|
| 66 |
api_key = api_key.strip()
|
| 67 |
if not api_key:
|
| 68 |
continue
|
| 69 |
+
|
| 70 |
if api_type == "Groq":
|
| 71 |
+
es_valida = verificar_api_groq(api_key)
|
| 72 |
elif api_type == "OpenAI":
|
| 73 |
+
es_valida = verificar_api_openai(api_key)
|
| 74 |
elif api_type == "Google Gemini":
|
| 75 |
+
es_valida = verificar_api_gemini(api_key)
|
| 76 |
else:
|
| 77 |
+
continue
|
| 78 |
+
|
| 79 |
+
# Clasificar las APIs en válidas o inválidas
|
| 80 |
+
if es_valida:
|
| 81 |
+
apis_validas.append(api_key)
|
| 82 |
else:
|
| 83 |
+
apis_invalidas.append(api_key)
|
| 84 |
|
| 85 |
# Formatear el resultado final con las secciones separadas
|
| 86 |
+
resultado_final = "✅ APIs válidas:\n" + "\n".join(apis_validas) + "\n\n⛔ APIs inválidas:\n" + "\n".join(apis_invalidas)
|
| 87 |
return resultado_final
|
| 88 |
|
| 89 |
# Interfaz de Gradio
|
|
|
|
| 100 |
|
| 101 |
# Ejecutar la interfaz en Hugging Face Space
|
| 102 |
if __name__ == "__main__":
|
| 103 |
+
iface.launch()
|