Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,43 +4,55 @@ import time
|
|
| 4 |
|
| 5 |
def test_antena(ip, usuario, password):
|
| 6 |
try:
|
| 7 |
-
# Intentar conexion HTTP simple
|
| 8 |
session = requests.Session()
|
| 9 |
-
|
| 10 |
-
# Probar endpoint de login
|
| 11 |
login_url = f"http://{ip}/api/login"
|
| 12 |
login_data = {"username": usuario, "password": password}
|
| 13 |
|
| 14 |
response = session.post(login_url, json=login_data, timeout=10)
|
| 15 |
|
| 16 |
if response.status_code == 200:
|
| 17 |
-
# Login exitoso, obtener status
|
| 18 |
status_url = f"http://{ip}/api/v1/status"
|
| 19 |
status_response = session.get(status_url, timeout=10)
|
| 20 |
|
| 21 |
if status_response.status_code == 200:
|
| 22 |
-
resultado = "
|
| 23 |
-
resultado += "
|
| 24 |
-
resultado += "
|
|
|
|
|
|
|
| 25 |
return resultado
|
| 26 |
else:
|
| 27 |
-
return "LOGIN OK pero no
|
| 28 |
else:
|
| 29 |
-
return "ERROR DE LOGIN
|
| 30 |
|
| 31 |
except Exception as e:
|
| 32 |
-
return "ERROR
|
| 33 |
|
| 34 |
-
# Interfaz
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
gr.
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
|
|
|
| 4 |
|
| 5 |
def test_antena(ip, usuario, password):
|
| 6 |
try:
|
|
|
|
| 7 |
session = requests.Session()
|
|
|
|
|
|
|
| 8 |
login_url = f"http://{ip}/api/login"
|
| 9 |
login_data = {"username": usuario, "password": password}
|
| 10 |
|
| 11 |
response = session.post(login_url, json=login_data, timeout=10)
|
| 12 |
|
| 13 |
if response.status_code == 200:
|
|
|
|
| 14 |
status_url = f"http://{ip}/api/v1/status"
|
| 15 |
status_response = session.get(status_url, timeout=10)
|
| 16 |
|
| 17 |
if status_response.status_code == 200:
|
| 18 |
+
resultado = "✅ CONEXIÓN EXITOSA\n\n"
|
| 19 |
+
resultado += f"IP: {ip}\n"
|
| 20 |
+
resultado += f"Usuario: {usuario}\n"
|
| 21 |
+
resultado += f"Hora: {time.strftime('%H:%M:%S')}\n\n"
|
| 22 |
+
resultado += "📊 Métricas obtenidas correctamente via API"
|
| 23 |
return resultado
|
| 24 |
else:
|
| 25 |
+
return f"⚠️ LOGIN OK pero no métricas\n\nError status: {status_response.status_code}"
|
| 26 |
else:
|
| 27 |
+
return f"❌ ERROR DE LOGIN\n\nCódigo: {response.status_code}"
|
| 28 |
|
| 29 |
except Exception as e:
|
| 30 |
+
return f"🔴 ERROR DE CONEXIÓN\n\nDetalle: {str(e)}"
|
| 31 |
|
| 32 |
+
# Interfaz con área de resultados GRANDE
|
| 33 |
+
with gr.Blocks() as demo:
|
| 34 |
+
gr.Markdown("# 📡 TEST UBIQUITI")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
with gr.Column(scale=1):
|
| 38 |
+
ip_input = gr.Textbox(label="IP del equipo", value="192.168.1.24")
|
| 39 |
+
user_input = gr.Textbox(label="Usuario", value="admin")
|
| 40 |
+
pass_input = gr.Textbox(label="Contraseña", type="password")
|
| 41 |
+
btn = gr.Button("🚀 EJECUTAR TEST", variant="primary")
|
| 42 |
+
|
| 43 |
+
with gr.Column(scale=2):
|
| 44 |
+
# Área de resultados MÁS GRANDE
|
| 45 |
+
output = gr.Textbox(
|
| 46 |
+
label="RESULTADOS",
|
| 47 |
+
lines=10, # 10 líneas de alto
|
| 48 |
+
max_lines=20,
|
| 49 |
+
show_copy_button=True
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
btn.click(
|
| 53 |
+
fn=test_antena,
|
| 54 |
+
inputs=[ip_input, user_input, pass_input],
|
| 55 |
+
outputs=output
|
| 56 |
+
)
|
| 57 |
|
| 58 |
+
demo.launch()
|