Spaces:
Running on Zero
Running on Zero
Upload app.py
Browse files
app.py
CHANGED
|
@@ -4308,6 +4308,19 @@ def _condition_key(session,prompt,references,canvas,frames,rewrite,reference_res
|
|
| 4308 |
ensure_ascii=False).encode()).hexdigest()
|
| 4309 |
|
| 4310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4311 |
def encode_remote(prompt,references,canvas,num_frames,rewrite_prompt=False,session_id='',reference_resize_mode='legacy'):
|
| 4312 |
from gradio_client import handle_file
|
| 4313 |
from safetensors import safe_open
|
|
@@ -4340,6 +4353,7 @@ def encode_remote(prompt,references,canvas,num_frames,rewrite_prompt=False,sessi
|
|
| 4340 |
except Exception:
|
| 4341 |
_CONDITION_CACHE.pop(key,None)
|
| 4342 |
job=None
|
|
|
|
| 4343 |
try:
|
| 4344 |
fields=dict(prompt=prompt,media=[handle_file(p) for _,p in references],
|
| 4345 |
kinds=','.join(k for k,_ in references),num_frames=num_frames,rewrite_prompt=bool(rewrite_prompt))
|
|
@@ -4349,13 +4363,26 @@ def encode_remote(prompt,references,canvas,num_frames,rewrite_prompt=False,sessi
|
|
| 4349 |
else:
|
| 4350 |
fields.update(canvas=canvas,api_name='/encode_ref2va')
|
| 4351 |
job=conditioner().submit(**fields)
|
|
|
|
| 4352 |
path,plan=job.result(timeout=300)
|
|
|
|
| 4353 |
result=read(path,plan)
|
| 4354 |
except Exception as error:
|
| 4355 |
if job is not None:
|
| 4356 |
try:job.cancel()
|
| 4357 |
except Exception:pass
|
| 4358 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4359 |
if key and os.path.getsize(path)<=256*1048576:
|
| 4360 |
root=os.path.join(tempfile.gettempdir(),'h3-condition-cache');os.makedirs(root,exist_ok=True)
|
| 4361 |
dest=os.path.join(root,key+'.safetensors');temporary=dest+'.'+uuid.uuid4().hex
|
|
|
|
| 4308 |
ensure_ascii=False).encode()).hexdigest()
|
| 4309 |
|
| 4310 |
|
| 4311 |
+
def _conditioner_error_detail(error):
|
| 4312 |
+
"""Keep upstream diagnostics useful without exposing credentials or signed links."""
|
| 4313 |
+
detail=str(getattr(error,'message',None) or str(error) or 'No error details were returned.')
|
| 4314 |
+
for name,value in os.environ.items():
|
| 4315 |
+
if value and len(value)>=8 and any(word in name.upper() for word in ('TOKEN','SECRET','PASSWORD','API_KEY')):
|
| 4316 |
+
detail=detail.replace(value,'[redacted]')
|
| 4317 |
+
detail=re.sub(r'hf_[A-Za-z0-9]+','[redacted]',detail)
|
| 4318 |
+
detail=re.sub(r'(?i)\bBearer\s+[^\s\"\'<>]+','Bearer [redacted]',detail)
|
| 4319 |
+
detail=re.sub(r'https?://[^\s\"\'<>]+','[remote URL]',detail)
|
| 4320 |
+
detail=re.sub(r'(?i)\b(token|api[_-]?key|password|secret)\s*[:=]\s*[^\s,;]+',r'\1=[redacted]',detail)
|
| 4321 |
+
return detail[:2000]
|
| 4322 |
+
|
| 4323 |
+
|
| 4324 |
def encode_remote(prompt,references,canvas,num_frames,rewrite_prompt=False,session_id='',reference_resize_mode='legacy'):
|
| 4325 |
from gradio_client import handle_file
|
| 4326 |
from safetensors import safe_open
|
|
|
|
| 4353 |
except Exception:
|
| 4354 |
_CONDITION_CACHE.pop(key,None)
|
| 4355 |
job=None
|
| 4356 |
+
stage='submitting'
|
| 4357 |
try:
|
| 4358 |
fields=dict(prompt=prompt,media=[handle_file(p) for _,p in references],
|
| 4359 |
kinds=','.join(k for k,_ in references),num_frames=num_frames,rewrite_prompt=bool(rewrite_prompt))
|
|
|
|
| 4363 |
else:
|
| 4364 |
fields.update(canvas=canvas,api_name='/encode_ref2va')
|
| 4365 |
job=conditioner().submit(**fields)
|
| 4366 |
+
stage='waiting_for_conditioner'
|
| 4367 |
path,plan=job.result(timeout=300)
|
| 4368 |
+
stage='reading_conditioning'
|
| 4369 |
result=read(path,plan)
|
| 4370 |
except Exception as error:
|
| 4371 |
if job is not None:
|
| 4372 |
try:job.cancel()
|
| 4373 |
except Exception:pass
|
| 4374 |
+
import html
|
| 4375 |
+
detail=_conditioner_error_detail(error)
|
| 4376 |
+
# Do not discard the upstream AppError: it carries the actual failure.
|
| 4377 |
+
# No traceback locals, prompt or upload data are added to diagnostics.
|
| 4378 |
+
_runtime_event('conditioner_failed',stage=stage,error_type=type(error).__name__)
|
| 4379 |
+
print('[conditioner-error] '+json.dumps(dict(stage=stage,error_type=type(error).__name__,detail=detail),ensure_ascii=False),flush=True)
|
| 4380 |
+
raise gr.Error(
|
| 4381 |
+
f'Conditioner failed ({type(error).__name__}; {stage}): {html.escape(detail)}\n\n'
|
| 4382 |
+
'No video GPU request was sent. No retry was submitted. '
|
| 4383 |
+
'A started conditioner job may still use quota. If the message has no details, '
|
| 4384 |
+
'open Logs in the conditioner Space and copy its traceback.'
|
| 4385 |
+
) from None
|
| 4386 |
if key and os.path.getsize(path)<=256*1048576:
|
| 4387 |
root=os.path.join(tempfile.gettempdir(),'h3-condition-cache');os.makedirs(root,exist_ok=True)
|
| 4388 |
dest=os.path.join(root,key+'.safetensors');temporary=dest+'.'+uuid.uuid4().hex
|