Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,24 @@ from diffusers import DiffusionPipeline
|
|
5 |
import torch
|
6 |
import time
|
7 |
import psutil
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Get the number of physical CPU cores (excluding hyperthreads)
|
10 |
NUM_CPU_CORES = psutil.cpu_count(logical=True)
|
|
|
5 |
import torch
|
6 |
import time
|
7 |
import psutil
|
8 |
+
from huggingface_hub import snapshot_download # New import
|
9 |
+
|
10 |
+
# ... (Other imports and variables remain the same)
|
11 |
+
|
12 |
+
def load_pipeline(model_id):
|
13 |
+
if model_id in PIPELINES:
|
14 |
+
return PIPELINES[model_id]
|
15 |
+
else:
|
16 |
+
# Download model using snapshot_download to handle LFS files
|
17 |
+
model_path = snapshot_download(repo_id=model_id, local_dir="./models") # Download and cache models
|
18 |
+
pipe = DiffusionPipeline.from_pretrained(model_path, torch_dtype=torch.float32)
|
19 |
+
pipe.to(DEVICE)
|
20 |
+
PIPELINES[model_id] = pipe
|
21 |
+
return pipe
|
22 |
+
|
23 |
+
|
24 |
+
# ... (Rest of your code remains the same)
|
25 |
+
|
26 |
|
27 |
# Get the number of physical CPU cores (excluding hyperthreads)
|
28 |
NUM_CPU_CORES = psutil.cpu_count(logical=True)
|