Spaces:
Sleeping
Sleeping
Tu Nombre commited on
Commit ·
c78069e
1
Parent(s): 6909b4b
Teste: normalizar URL envoltorio a .hf.space antes de abrir el navegador
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import os
|
|
| 3 |
import json
|
| 4 |
import base64
|
| 5 |
import tempfile
|
|
|
|
| 6 |
from concurrent.futures import ThreadPoolExecutor
|
| 7 |
|
| 8 |
import gradio as gr
|
|
@@ -193,12 +194,24 @@ def _juzgar(objetivo, texto, ruta_img):
|
|
| 193 |
return '{"ok": false, "problemas": ["Error del modelo: ' + str(e)[:120] + '"], "resumen": "Fallo al juzgar"}'
|
| 194 |
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
def probar(url, objetivo):
|
| 197 |
url = (url or "").strip()
|
| 198 |
if not url:
|
| 199 |
return "Pon una URL.", None
|
| 200 |
if not url.startswith("http"):
|
| 201 |
url = "https://" + url
|
|
|
|
| 202 |
try:
|
| 203 |
texto, ruta, error_dom = _abrir_seguro(url)
|
| 204 |
except Exception as e:
|
|
|
|
| 3 |
import json
|
| 4 |
import base64
|
| 5 |
import tempfile
|
| 6 |
+
import re
|
| 7 |
from concurrent.futures import ThreadPoolExecutor
|
| 8 |
|
| 9 |
import gradio as gr
|
|
|
|
| 194 |
return '{"ok": false, "problemas": ["Error del modelo: ' + str(e)[:120] + '"], "resumen": "Fallo al juzgar"}'
|
| 195 |
|
| 196 |
|
| 197 |
+
def _normalizar_url(url):
|
| 198 |
+
"""Si pegan la URL-envoltorio de HF (huggingface.co/spaces/...), la
|
| 199 |
+
convierte a la URL directa .hf.space, porque en la envoltorio los
|
| 200 |
+
componentes reales viven dentro de un iframe y Playwright no los ve."""
|
| 201 |
+
m = re.search(r"huggingface\.co/spaces/([^/]+)/([^/?#]+)", url)
|
| 202 |
+
if m:
|
| 203 |
+
slug = re.sub(r"[^a-z0-9]+", "-", f"{m.group(1)}-{m.group(2)}".lower()).strip("-")
|
| 204 |
+
return f"https://{slug}.hf.space"
|
| 205 |
+
return url
|
| 206 |
+
|
| 207 |
+
|
| 208 |
def probar(url, objetivo):
|
| 209 |
url = (url or "").strip()
|
| 210 |
if not url:
|
| 211 |
return "Pon una URL.", None
|
| 212 |
if not url.startswith("http"):
|
| 213 |
url = "https://" + url
|
| 214 |
+
url = _normalizar_url(url)
|
| 215 |
try:
|
| 216 |
texto, ruta, error_dom = _abrir_seguro(url)
|
| 217 |
except Exception as e:
|