Spaces:
Sleeping
Sleeping
final_app
Browse files
app.py
CHANGED
|
@@ -34,6 +34,11 @@ def timeout_handler(signum, frame):
|
|
| 34 |
# Load the model
|
| 35 |
def load_model():
|
| 36 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
pipe = DiffusionPipeline.from_pretrained(
|
| 38 |
"CompVis/stable-diffusion-v1-4",
|
| 39 |
torch_dtype=torch.float16 if TORCH_DEVICE == "cuda" else torch.float32,
|
|
@@ -63,9 +68,17 @@ def load_model():
|
|
| 63 |
print(f"Warning: Could not load textual inversion concept {concept}: {e}")
|
| 64 |
except Exception as e:
|
| 65 |
print(f"Warning: Could not load textual inversion concepts: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
return pipe
|
| 68 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
print(f"Error loading model: {e}")
|
| 70 |
traceback.print_exc()
|
| 71 |
raise
|
|
|
|
| 34 |
# Load the model
|
| 35 |
def load_model():
|
| 36 |
try:
|
| 37 |
+
# Initialize signal handler only on Unix-like systems
|
| 38 |
+
if TORCH_DEVICE == "cpu" and hasattr(signal, 'SIGALRM'):
|
| 39 |
+
signal.signal(signal.SIGALRM, timeout_handler)
|
| 40 |
+
signal.alarm(2100) # 15 minutes timeout for model loading
|
| 41 |
+
|
| 42 |
pipe = DiffusionPipeline.from_pretrained(
|
| 43 |
"CompVis/stable-diffusion-v1-4",
|
| 44 |
torch_dtype=torch.float16 if TORCH_DEVICE == "cuda" else torch.float32,
|
|
|
|
| 68 |
print(f"Warning: Could not load textual inversion concept {concept}: {e}")
|
| 69 |
except Exception as e:
|
| 70 |
print(f"Warning: Could not load textual inversion concepts: {e}")
|
| 71 |
+
|
| 72 |
+
# Clear the alarm if set
|
| 73 |
+
if TORCH_DEVICE == "cpu" and hasattr(signal, 'SIGALRM'):
|
| 74 |
+
signal.alarm(0)
|
| 75 |
|
| 76 |
return pipe
|
| 77 |
except Exception as e:
|
| 78 |
+
# Clear the alarm if set
|
| 79 |
+
if TORCH_DEVICE == "cpu" and hasattr(signal, 'SIGALRM'):
|
| 80 |
+
signal.alarm(0)
|
| 81 |
+
|
| 82 |
print(f"Error loading model: {e}")
|
| 83 |
traceback.print_exc()
|
| 84 |
raise
|