tx3bas commited on
Commit
f25ea0c
·
verified ·
1 Parent(s): 83d4b7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -8
app.py CHANGED
@@ -5,6 +5,8 @@ import google.generativeai as genai
5
  import requests
6
  import json
7
  from googleapiclient.discovery import build
 
 
8
 
9
  # Función para inicializar el cliente de Groq con la API key proporcionada
10
  def create_groq_client(api_key):
@@ -132,8 +134,8 @@ def verificar_api_google_places(api_key):
132
  url = "https://maps.googleapis.com/maps/api/place/textsearch/json"
133
  params = {
134
  "query": "restaurants",
135
- "location": "37.7749,-122.4194", # Coordenadas de San Francisco, CA
136
- "radius": 5000, # Radio de 5 km
137
  "key": api_key
138
  }
139
 
@@ -142,13 +144,33 @@ def verificar_api_google_places(api_key):
142
  # Si la respuesta es exitosa, la API es válida
143
  if response.status_code == 200:
144
  data = response.json()
145
- # Comprobar si hay resultados válidos
146
  return "results" in data and len(data["results"]) > 0
147
  else:
148
- print(f"Error en la solicitud: {response.status_code}, {response.text}")
149
  return False # API inválida
150
- except Exception as e:
151
- print(f"Excepción al verificar Google Places API: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  return False # API inválida
153
 
154
  # Función general para verificar una lista de API keys
@@ -176,6 +198,8 @@ def verificar_apis(api_keys_text, api_type):
176
  es_valida = verificar_api_pexels(api_key)
177
  elif api_type == "Google Places":
178
  es_valida = verificar_api_google_places(api_key)
 
 
179
  else:
180
  continue
181
 
@@ -194,10 +218,10 @@ iface = gr.Interface(
194
  fn=verificar_apis,
195
  inputs=[
196
  gr.Textbox(label="API Keys (una por línea)", lines=10, placeholder="Introduce cada API key en una línea diferente..."),
197
- gr.Radio(["Groq", "OpenAI", "Google Gemini", "OpenRouter", "YouTube", "Pexels", "Google Places"], label="Tipo de API")
198
  ],
199
  outputs="text",
200
- title="Verificación de Múltiples APIs (Groq, OpenAI, Google Gemini, OpenRouter, YouTube, Pexels, Google Places)",
201
  description="Ingresa una lista de API keys (una por línea) y selecciona el tipo de API para verificar cuáles están disponibles."
202
  )
203
 
 
5
  import requests
6
  import json
7
  from googleapiclient.discovery import build
8
+ from PIL import Image
9
+ from io import BytesIO
10
 
11
  # Función para inicializar el cliente de Groq con la API key proporcionada
12
  def create_groq_client(api_key):
 
134
  url = "https://maps.googleapis.com/maps/api/place/textsearch/json"
135
  params = {
136
  "query": "restaurants",
137
+ "location": "0,0",
138
+ "radius": 1000,
139
  "key": api_key
140
  }
141
 
 
144
  # Si la respuesta es exitosa, la API es válida
145
  if response.status_code == 200:
146
  data = response.json()
 
147
  return "results" in data and len(data["results"]) > 0
148
  else:
 
149
  return False # API inválida
150
+ except Exception:
151
+ return False # API inválida
152
+
153
+ # Función para verificar la API de Unsplash
154
+ def verificar_api_unsplash(api_key):
155
+ try:
156
+ url = "https://api.unsplash.com/search/photos"
157
+ headers = {
158
+ "Authorization": f"Client-ID {api_key}"
159
+ }
160
+ params = {
161
+ "query": "nature",
162
+ "per_page": 1
163
+ }
164
+
165
+ response = requests.get(url, headers=headers, params=params)
166
+
167
+ # Si la respuesta es exitosa, la API es válida
168
+ if response.status_code == 200:
169
+ data = response.json()
170
+ return "results" in data and len(data["results"]) > 0
171
+ else:
172
+ return False # API inválida
173
+ except Exception:
174
  return False # API inválida
175
 
176
  # Función general para verificar una lista de API keys
 
198
  es_valida = verificar_api_pexels(api_key)
199
  elif api_type == "Google Places":
200
  es_valida = verificar_api_google_places(api_key)
201
+ elif api_type == "Unsplash":
202
+ es_valida = verificar_api_unsplash(api_key)
203
  else:
204
  continue
205
 
 
218
  fn=verificar_apis,
219
  inputs=[
220
  gr.Textbox(label="API Keys (una por línea)", lines=10, placeholder="Introduce cada API key en una línea diferente..."),
221
+ gr.Radio(["Groq", "OpenAI", "Google Gemini", "OpenRouter", "YouTube", "Pexels", "Google Places", "Unsplash"], label="Tipo de API")
222
  ],
223
  outputs="text",
224
+ title="Verificación de Múltiples APIs (Groq, OpenAI, Google Gemini, OpenRouter, YouTube, Pexels, Google Places, Unsplash)",
225
  description="Ingresa una lista de API keys (una por línea) y selecciona el tipo de API para verificar cuáles están disponibles."
226
  )
227