Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,27 +16,21 @@ access_token = os.getenv("HF_ACCESS_TOKEN")
|
|
16 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
17 |
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
pipe = pipe.to(device)
|
35 |
-
|
36 |
-
logging.info("Loading the model...")
|
37 |
-
|
38 |
-
# Load model
|
39 |
-
logging.info("Model loaded successfully.")
|
40 |
|
41 |
MAX_SEED = np.iinfo(np.int32).max
|
42 |
MAX_IMAGE_SIZE = 1024
|
|
|
16 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
17 |
|
18 |
|
19 |
+
# Global variable for the pipeline
|
20 |
+
pipe = None
|
21 |
+
|
22 |
+
def load_model():
|
23 |
+
global pipe
|
24 |
+
if pipe is None:
|
25 |
+
logging.info("Loading the Stable Diffusion model...")
|
26 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
27 |
+
"stabilityai/stable-diffusion-3-medium",
|
28 |
+
torch_dtype=torch.float16,
|
29 |
+
use_auth_token=access_token,
|
30 |
+
cache_dir="/path/to/cache" # specify cache directory
|
31 |
+
)
|
32 |
+
pipe = pipe.to(device)
|
33 |
+
logging.info("Model loaded successfully.")
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
MAX_SEED = np.iinfo(np.int32).max
|
36 |
MAX_IMAGE_SIZE = 1024
|