Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,22 +2,27 @@ import io
|
|
2 |
import base64
|
3 |
import torch
|
4 |
from flask import Flask, request, jsonify
|
5 |
-
from diffusers import StableDiffusionPipeline # Placeholder;
|
6 |
from PIL import Image
|
7 |
import logging
|
|
|
|
|
8 |
|
9 |
logging.basicConfig(level=logging.INFO)
|
10 |
logger = logging.getLogger(__name__)
|
11 |
|
12 |
app = Flask(__name__)
|
13 |
|
14 |
-
# Load the model once
|
15 |
try:
|
16 |
logger.info("Loading Stable Fast 3D pipeline...")
|
|
|
|
|
17 |
pipe = StableDiffusionPipeline.from_pretrained(
|
18 |
"stabilityai/stable-fast-3d",
|
19 |
torch_dtype=torch.float32,
|
20 |
cache_dir="/tmp/hf_home",
|
|
|
21 |
)
|
22 |
pipe.to("cpu")
|
23 |
logger.info("=== Application Startup at CPU mode =====")
|
@@ -52,11 +57,9 @@ def generate():
|
|
52 |
image = Image.open(io.BytesIO(base64.b64decode(image_data))).convert("RGB")
|
53 |
|
54 |
logger.info("Processing image with pipeline...")
|
55 |
-
|
56 |
-
|
57 |
-
output_mesh = result.mesh # Hypothetical output; may be .glb or .obj
|
58 |
|
59 |
-
# Save mesh to temporary file and encode
|
60 |
output_path = "/tmp/output.glb"
|
61 |
output_mesh.save(output_path)
|
62 |
with open(output_path, "rb") as f:
|
|
|
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
|
7 |
import logging
|
8 |
+
import os
|
9 |
+
from huggingface_hub import HfFolder
|
10 |
|
11 |
logging.basicConfig(level=logging.INFO)
|
12 |
logger = logging.getLogger(__name__)
|
13 |
|
14 |
app = Flask(__name__)
|
15 |
|
16 |
+
# Load the model once at startup (on CPU) with authentication
|
17 |
try:
|
18 |
logger.info("Loading Stable Fast 3D pipeline...")
|
19 |
+
# Use your Hugging Face token (set as environment variable or hardcoded for testing)
|
20 |
+
token = os.getenv("HF_TOKEN") or "your_hf_token_here" # Replace with your token
|
21 |
pipe = StableDiffusionPipeline.from_pretrained(
|
22 |
"stabilityai/stable-fast-3d",
|
23 |
torch_dtype=torch.float32,
|
24 |
cache_dir="/tmp/hf_home",
|
25 |
+
token=token, # Pass token for authentication
|
26 |
)
|
27 |
pipe.to("cpu")
|
28 |
logger.info("=== Application Startup at CPU mode =====")
|
|
|
57 |
image = Image.open(io.BytesIO(base64.b64decode(image_data))).convert("RGB")
|
58 |
|
59 |
logger.info("Processing image with pipeline...")
|
60 |
+
result = pipe(image) # Adjust based on SF3D documentation
|
61 |
+
output_mesh = result.mesh # Hypothetical; check SF3D output format
|
|
|
62 |
|
|
|
63 |
output_path = "/tmp/output.glb"
|
64 |
output_mesh.save(output_path)
|
65 |
with open(output_path, "rb") as f:
|