Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from groq import Groq
|
| 3 |
import openai
|
|
|
|
| 4 |
|
| 5 |
# Función para inicializar el cliente de Groq con la API key proporcionada
|
| 6 |
def create_groq_client(api_key):
|
|
@@ -44,6 +45,23 @@ def verificar_api_openai(api_key):
|
|
| 44 |
except Exception as e:
|
| 45 |
return f"⛔ Error general en OpenAI API: {str(e)}"
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
# Función general para verificar una lista de API keys
|
| 48 |
def verificar_apis(api_keys_text, api_type):
|
| 49 |
api_keys = api_keys_text.strip().split("\n")
|
|
@@ -56,6 +74,8 @@ def verificar_apis(api_keys_text, api_type):
|
|
| 56 |
resultado = verificar_api_groq(api_key)
|
| 57 |
elif api_type == "OpenAI":
|
| 58 |
resultado = verificar_api_openai(api_key)
|
|
|
|
|
|
|
| 59 |
else:
|
| 60 |
resultado = "⛔ Tipo de API no soportada."
|
| 61 |
resultados.append(f"API Key: {api_key} -> {resultado}")
|
|
@@ -66,13 +86,13 @@ iface = gr.Interface(
|
|
| 66 |
fn=verificar_apis,
|
| 67 |
inputs=[
|
| 68 |
gr.Textbox(label="API Keys (una por línea)", lines=10, placeholder="Introduce cada API key en una línea diferente..."),
|
| 69 |
-
gr.Radio(["Groq", "OpenAI"], label="Tipo de API")
|
| 70 |
],
|
| 71 |
outputs="text",
|
| 72 |
-
title="Verificación de Múltiples APIs (Groq
|
| 73 |
description="Ingresa una lista de API keys (una por línea) y selecciona el tipo de API para verificar cuáles están disponibles."
|
| 74 |
)
|
| 75 |
|
| 76 |
# Ejecutar la interfaz en Hugging Face Space
|
| 77 |
if __name__ == "__main__":
|
| 78 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from groq import Groq
|
| 3 |
import openai
|
| 4 |
+
import google.generativeai as genai
|
| 5 |
|
| 6 |
# Función para inicializar el cliente de Groq con la API key proporcionada
|
| 7 |
def create_groq_client(api_key):
|
|
|
|
| 45 |
except Exception as e:
|
| 46 |
return f"⛔ Error general en OpenAI API: {str(e)}"
|
| 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 |
+
if response:
|
| 59 |
+
return f"✅ Google Gemini API disponible. Respuesta: {response.text.strip()}"
|
| 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")
|
|
|
|
| 74 |
resultado = verificar_api_groq(api_key)
|
| 75 |
elif api_type == "OpenAI":
|
| 76 |
resultado = verificar_api_openai(api_key)
|
| 77 |
+
elif api_type == "Google Gemini":
|
| 78 |
+
resultado = verificar_api_gemini(api_key)
|
| 79 |
else:
|
| 80 |
resultado = "⛔ Tipo de API no soportada."
|
| 81 |
resultados.append(f"API Key: {api_key} -> {resultado}")
|
|
|
|
| 86 |
fn=verificar_apis,
|
| 87 |
inputs=[
|
| 88 |
gr.Textbox(label="API Keys (una por línea)", lines=10, placeholder="Introduce cada API key en una línea diferente..."),
|
| 89 |
+
gr.Radio(["Groq", "OpenAI", "Google Gemini"], label="Tipo de API")
|
| 90 |
],
|
| 91 |
outputs="text",
|
| 92 |
+
title="Verificación de Múltiples APIs (Groq, OpenAI, Google Gemini)",
|
| 93 |
description="Ingresa una lista de API keys (una por línea) y selecciona el tipo de API para verificar cuáles están disponibles."
|
| 94 |
)
|
| 95 |
|
| 96 |
# Ejecutar la interfaz en Hugging Face Space
|
| 97 |
if __name__ == "__main__":
|
| 98 |
+
iface.launch()
|