Spaces:
Build error
Build error
Update generate.py
Browse files- generate.py +16 -3
generate.py
CHANGED
|
@@ -1,7 +1,20 @@
|
|
| 1 |
# generate.py
|
| 2 |
-
# --- VERSION
|
| 3 |
-
|
| 4 |
-
print("--- RUNNING GENERATE.PY VERSION
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
import torch
|
| 7 |
import cv2
|
|
|
|
| 1 |
# generate.py
|
| 2 |
+
# --- VERSION 11 (with Monkey-Patch) ---
|
| 3 |
+
|
| 4 |
+
print("--- RUNNING GENERATE.PY VERSION 11 (with Monkey-Patch) ---")
|
| 5 |
+
|
| 6 |
+
# --- MONKEY-PATCH FOR OLD TORCHVISION ---
|
| 7 |
+
# This block fixes the "ModuleNotFoundError" by tricking the system.
|
| 8 |
+
# It tells any library looking for the new `functional_tensor` module
|
| 9 |
+
# to use the old `functional` module instead.
|
| 10 |
+
try:
|
| 11 |
+
import sys
|
| 12 |
+
import torchvision.transforms.functional as F
|
| 13 |
+
sys.modules['torchvision.transforms.functional_tensor'] = F
|
| 14 |
+
print("--- Successfully applied torchvision monkey-patch. ---")
|
| 15 |
+
except Exception as e:
|
| 16 |
+
print(f"--- Could not apply torchvision monkey-patch: {e} ---")
|
| 17 |
+
# --- END OF PATCH ---
|
| 18 |
|
| 19 |
import torch
|
| 20 |
import cv2
|