Spaces:
Sleeping
Sleeping
Download patch_qwen_timeout.py from bep40/VNEWS2: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/bep40/VNEWS2/resolve/refs%2Fpr%2F1/patch_qwen_timeout.py
- Command line
-
hf download hf://spaces/bep40/VNEWS2@refs/pr/1/patch_qwen_timeout.py
-
curl -L -o patch_qwen_timeout.py https://huggingface.co/spaces/bep40/VNEWS2/resolve/refs%2Fpr%2F1/patch_qwen_timeout.py
1.27 kB
| # 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() | |