Spaces:
Sleeping
Sleeping
| # Patch applied at Space startup: reduce Qwen timeout from 75s to 15s | |
| # This file is sourced by the entry point | |
| import re, os | |
| PATCH_DONE_FLAG = "/app/.qwen_timeout_patched" | |
| def apply_patch(): | |
| if os.path.exists(PATCH_DONE_FLAG): | |
| return | |
| try: | |
| for fpath in ["/app/main.py", os.path.join(os.path.dirname(__file__), "main.py")]: | |
| if os.path.exists(fpath): | |
| with open(fpath, "r") as f: | |
| content = f.read() | |
| # Change timeout=75 to timeout=15 | |
| orig = 'r=requests.post("https://router.huggingface.co/v1/chat/completions",headers=headers,json=payload,timeout=75)' | |
| new = 'r=requests.post("https://router.huggingface.co/v1/chat/completions",headers=headers,json=payload,timeout=15)' | |
| if orig in content: | |
| content = content.replace(orig, new) | |
| with open(fpath, "w") as f: | |
| f.write(content) | |
| print("[patch] Applied Qwen timeout patch (75s → 15s) to", fpath) | |
| break | |
| # Create flag file | |
| with open(PATCH_DONE_FLAG, "w") as f: | |
| f.write("ok") | |
| except Exception as e: | |
| print("[patch] Failed to apply patch:", e) | |
| apply_patch() | |