mike23415 commited on
Commit
4e31b1a
·
verified ·
1 Parent(s): 6585a69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import io
2
  import base64
3
  import torch
 
4
  from flask import Flask, request, jsonify
5
  from diffusers import StableDiffusionPipeline # Placeholder; adjust based on SF3D docs
6
  from PIL import Image
@@ -11,16 +12,17 @@ logger = logging.getLogger(__name__)
11
 
12
  app = Flask(__name__)
13
 
14
- # Load the model once at startup (on CPU) with token in code
15
  try:
16
  logger.info("Loading Stable Fast 3D pipeline...")
17
- # Replace 'your_hf_token_here' with your actual Hugging Face token
18
- token = "your_hf_token_here" # Hardcoded token for authentication
 
19
  pipe = StableDiffusionPipeline.from_pretrained(
20
  "stabilityai/stable-fast-3d",
21
  torch_dtype=torch.float32,
22
  cache_dir="/tmp/hf_home",
23
- token=token, # Pass token directly
24
  )
25
  pipe.to("cpu")
26
  logger.info("=== Application Startup at CPU mode =====")
 
1
  import io
2
  import base64
3
  import torch
4
+ import os
5
  from flask import Flask, request, jsonify
6
  from diffusers import StableDiffusionPipeline # Placeholder; adjust based on SF3D docs
7
  from PIL import Image
 
12
 
13
  app = Flask(__name__)
14
 
15
+ # Load the model once at startup (on CPU) with token from environment
16
  try:
17
  logger.info("Loading Stable Fast 3D pipeline...")
18
+ token = os.getenv("HF_TOKEN") # Retrieve token from environment variable
19
+ if not token:
20
+ raise ValueError("HF_TOKEN environment variable not set")
21
  pipe = StableDiffusionPipeline.from_pretrained(
22
  "stabilityai/stable-fast-3d",
23
  torch_dtype=torch.float32,
24
  cache_dir="/tmp/hf_home",
25
+ token=token, # Use the environment variable token
26
  )
27
  pipe.to("cpu")
28
  logger.info("=== Application Startup at CPU mode =====")