stpete2 commited on
Commit
61a06ba
·
verified ·
1 Parent(s): 7237554

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -7,6 +7,12 @@ import io
7
  import base64
8
  from typing import Optional
9
  import uvicorn
 
 
 
 
 
 
10
 
11
  # Initialize FastAPI app
12
  app = FastAPI(title="Stable Diffusion API")
@@ -26,7 +32,11 @@ model_id = "CompVis/stable-diffusion-v1-4"
26
 
27
  # Check if CUDA is available
28
  device = "cuda" if torch.cuda.is_available() else "cpu"
29
- pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True)
 
 
 
 
30
  pipe = pipe.to(device)
31
 
32
  @app.get("/")
 
7
  import base64
8
  from typing import Optional
9
  import uvicorn
10
+ import os
11
+
12
+ # Set cache directories to writable locations
13
+ os.environ["TRANSFORMERS_CACHE"] = "/tmp/transformers_cache"
14
+ os.environ["HF_HOME"] = "/tmp/hf_home"
15
+ os.environ["HF_DATASETS_CACHE"] = "/tmp/hf_datasets_cache"
16
 
17
  # Initialize FastAPI app
18
  app = FastAPI(title="Stable Diffusion API")
 
32
 
33
  # Check if CUDA is available
34
  device = "cuda" if torch.cuda.is_available() else "cpu"
35
+ pipe = StableDiffusionPipeline.from_pretrained(
36
+ model_id,
37
+ cache_dir="/tmp/diffusers_cache",
38
+ token=os.environ.get("HF_TOKEN") # Use token from environment variable
39
+ )
40
  pipe = pipe.to(device)
41
 
42
  @app.get("/")