Upload api_client.py
Browse files- api_client.py +11 -3
api_client.py
CHANGED
|
@@ -439,12 +439,20 @@ def describe_image_with_svision(image_path: str, is_face: bool = True) -> Tuple[
|
|
| 439 |
tuple (descripci贸n_completa, nombre_abreviado)
|
| 440 |
"""
|
| 441 |
try:
|
| 442 |
-
from gradio_client import Client,
|
| 443 |
|
| 444 |
# Conectar al space svision con timeout generoso para cold start de ZeroGPU
|
| 445 |
svision_url = os.getenv("SVISION_URL", "https://veureu-svision.hf.space")
|
| 446 |
print(f"[svision] Connectant a {svision_url}...")
|
| 447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
|
| 449 |
# Preparar prompt seg煤n el tipo
|
| 450 |
if is_face:
|
|
@@ -462,7 +470,7 @@ def describe_image_with_svision(image_path: str, is_face: bool = True) -> Tuple[
|
|
| 462 |
|
| 463 |
# IMPORTANTE: usar file() de gradio_client para enviar el archivo correctamente
|
| 464 |
result = client.predict(
|
| 465 |
-
|
| 466 |
prompt, # texto
|
| 467 |
256, # max_new_tokens
|
| 468 |
0.7, # temperature
|
|
|
|
| 439 |
tuple (descripci贸n_completa, nombre_abreviado)
|
| 440 |
"""
|
| 441 |
try:
|
| 442 |
+
from gradio_client import Client, handle_file
|
| 443 |
|
| 444 |
# Conectar al space svision con timeout generoso para cold start de ZeroGPU
|
| 445 |
svision_url = os.getenv("SVISION_URL", "https://veureu-svision.hf.space")
|
| 446 |
print(f"[svision] Connectant a {svision_url}...")
|
| 447 |
+
|
| 448 |
+
# Autenticar con HuggingFace token para obtener m谩s cuota de ZeroGPU
|
| 449 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 450 |
+
if hf_token:
|
| 451 |
+
client = Client(svision_url, hf_token=hf_token)
|
| 452 |
+
print(f"[svision] Autenticat amb token HF")
|
| 453 |
+
else:
|
| 454 |
+
client = Client(svision_url)
|
| 455 |
+
print(f"[svision] Sense autenticaci贸 (cuota limitada)")
|
| 456 |
|
| 457 |
# Preparar prompt seg煤n el tipo
|
| 458 |
if is_face:
|
|
|
|
| 470 |
|
| 471 |
# IMPORTANTE: usar file() de gradio_client para enviar el archivo correctamente
|
| 472 |
result = client.predict(
|
| 473 |
+
handle_file(image_path), # Enviar el archivo usando el helper de gradio
|
| 474 |
prompt, # texto
|
| 475 |
256, # max_new_tokens
|
| 476 |
0.7, # temperature
|