Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,28 @@
|
|
| 1 |
# run_encrypted.py
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import os
|
| 4 |
import base64
|
| 5 |
from cryptography.fernet import Fernet
|
|
|
|
| 1 |
# run_encrypted.py
|
| 2 |
|
| 3 |
+
# --- BEGIN: runtime guard to guarantee websockets>=12 and avoid local shadowing ---
|
| 4 |
+
import sys, subprocess, importlib, os
|
| 5 |
+
|
| 6 |
+
# 1) Block local shadowing (e.g., a 'websockets.py' file/folder in your repo)
|
| 7 |
+
repo_shadow = any(os.path.exists(p) for p in ["websockets.py", "websockets", "./websockets.py", "./websockets"])
|
| 8 |
+
if repo_shadow:
|
| 9 |
+
raise SystemExit("Rename local 'websockets' module/folder; it shadows the real package.")
|
| 10 |
+
|
| 11 |
+
# 2) Ensure the correct package version is present *before* Gradio imports gradio_client
|
| 12 |
+
try:
|
| 13 |
+
import websockets # type: ignore
|
| 14 |
+
# If the modern submodule isn't available, force-install the right version.
|
| 15 |
+
try:
|
| 16 |
+
import websockets.asyncio # noqa: F401
|
| 17 |
+
except Exception:
|
| 18 |
+
raise ImportError
|
| 19 |
+
except Exception:
|
| 20 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "--no-cache-dir", "websockets==12.0"])
|
| 21 |
+
importlib.invalidate_caches()
|
| 22 |
+
import websockets # type: ignore
|
| 23 |
+
import websockets.asyncio # should now exist
|
| 24 |
+
# --- END: runtime guard ---
|
| 25 |
+
|
| 26 |
import os
|
| 27 |
import base64
|
| 28 |
from cryptography.fernet import Fernet
|