Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,32 @@
|
|
1 |
-
from flask import Flask, request, jsonify, send_file
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
pipe = DiffusionPipeline.from_pretrained(
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
img_io = io.BytesIO()
|
34 |
-
output_image.save(img_io, 'PNG')
|
35 |
-
img_io.seek(0)
|
36 |
-
|
37 |
-
return send_file(img_io, mimetype='image/png')
|
38 |
-
|
39 |
-
if __name__ == '__main__':
|
40 |
-
app.run(host='0.0.0.0', port=7860)
|
|
|
1 |
+
import os from flask import Flask, request, jsonify, send_file from diffusers import DiffusionPipeline import torch from PIL import Image import io
|
2 |
+
|
3 |
+
Set Hugging Face cache directory to a writable path
|
4 |
+
|
5 |
+
os.environ['HF_HOME'] = '/home/user/.cache/huggingface'
|
6 |
+
|
7 |
+
app = Flask(name)
|
8 |
+
|
9 |
+
Load the model on CPU
|
10 |
+
|
11 |
+
pipe = DiffusionPipeline.from_pretrained( "sudo-ai/zero123plus-v1.2", torch_dtype=torch.float32 ) pipe.to("cpu")
|
12 |
+
|
13 |
+
@app.route("/", methods=["GET"]) def index(): return jsonify({"message": "Zero123Plus API is running."})
|
14 |
+
|
15 |
+
@app.route("/generate", methods=["POST"]) def generate(): if 'image' not in request.files: return jsonify({"error": "No image uploaded"}), 400
|
16 |
+
|
17 |
+
image_file = request.files['image']
|
18 |
+
input_image = Image.open(image_file).convert("RGB")
|
19 |
+
|
20 |
+
# Generate new views
|
21 |
+
result = pipe(image=input_image, num_inference_steps=25)
|
22 |
+
output_image = result.images[0]
|
23 |
+
|
24 |
+
# Save to a BytesIO object
|
25 |
+
img_io = io.BytesIO()
|
26 |
+
output_image.save(img_io, 'PNG')
|
27 |
+
img_io.seek(0)
|
28 |
+
|
29 |
+
return send_file(img_io, mimetype='image/png')
|
30 |
+
|
31 |
+
if name == "main": app.run(host="0.0.0.0", port=7860)
|
32 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|