Spaces:
Runtime error
Runtime error
File size: 702 Bytes
0987856 d10fd1a 0987856 d10fd1a 0987856 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from diffusers import StableDiffusionPipeline
import torch
from flask import Flask, request, jsonify
app = Flask(__name__)
# Load the model
model_id = "ZB-Tech/Text-to-Image"
pipeline = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipeline.to("cuda" if torch.cuda.is_available() else "cpu")
@app.route("/generate", methods=["POST"])
def generate_image():
data = request.get_json()
prompt = data.get("prompt", "A scenic landscape")
image = pipeline(prompt).images[0]
image_path = "generated_image.png"
image.save(image_path)
return jsonify({"image_url": image_path})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)
|