Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import base64
|
|
3 |
import torch
|
4 |
import os
|
5 |
from flask import Flask, request, jsonify
|
6 |
-
from diffusers import StableDiffusionPipeline # Placeholder; adjust based on
|
7 |
from PIL import Image
|
8 |
import logging
|
9 |
|
@@ -12,17 +12,14 @@ logger = logging.getLogger(__name__)
|
|
12 |
|
13 |
app = Flask(__name__)
|
14 |
|
15 |
-
# Load the model once at startup (on CPU)
|
16 |
try:
|
17 |
-
logger.info("Loading
|
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 |
-
"
|
23 |
torch_dtype=torch.float32,
|
24 |
cache_dir="/tmp/hf_home",
|
25 |
-
token=token, #
|
26 |
)
|
27 |
pipe.to("cpu")
|
28 |
logger.info("=== Application Startup at CPU mode =====")
|
@@ -37,7 +34,7 @@ def pil_to_base64(image):
|
|
37 |
|
38 |
@app.route("/")
|
39 |
def home():
|
40 |
-
return "
|
41 |
|
42 |
@app.route("/generate", methods=["POST"])
|
43 |
def generate():
|
@@ -57,8 +54,8 @@ def generate():
|
|
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
|
61 |
-
output_mesh = result.mesh # Hypothetical; check
|
62 |
|
63 |
output_path = "/tmp/output.glb"
|
64 |
output_mesh.save(output_path)
|
|
|
3 |
import torch
|
4 |
import os
|
5 |
from flask import Flask, request, jsonify
|
6 |
+
from diffusers import StableDiffusionPipeline # Placeholder; adjust based on InstantMesh docs
|
7 |
from PIL import Image
|
8 |
import logging
|
9 |
|
|
|
12 |
|
13 |
app = Flask(__name__)
|
14 |
|
15 |
+
# Load the model once at startup (on CPU) without token (test only)
|
16 |
try:
|
17 |
+
logger.info("Loading TencentARC InstantMesh pipeline...")
|
|
|
|
|
|
|
18 |
pipe = StableDiffusionPipeline.from_pretrained(
|
19 |
+
"TencentARC/InstantMesh",
|
20 |
torch_dtype=torch.float32,
|
21 |
cache_dir="/tmp/hf_home",
|
22 |
+
# token=token, # Comment out or remove for test
|
23 |
)
|
24 |
pipe.to("cpu")
|
25 |
logger.info("=== Application Startup at CPU mode =====")
|
|
|
34 |
|
35 |
@app.route("/")
|
36 |
def home():
|
37 |
+
return "TencentARC InstantMesh CPU API is running!"
|
38 |
|
39 |
@app.route("/generate", methods=["POST"])
|
40 |
def generate():
|
|
|
54 |
image = Image.open(io.BytesIO(base64.b64decode(image_data))).convert("RGB")
|
55 |
|
56 |
logger.info("Processing image with pipeline...")
|
57 |
+
result = pipe(image) # Adjust based on InstantMesh documentation
|
58 |
+
output_mesh = result.mesh # Hypothetical; check InstantMesh output format
|
59 |
|
60 |
output_path = "/tmp/output.glb"
|
61 |
output_mesh.save(output_path)
|