File size: 1,161 Bytes
ddc9f6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask, request, jsonify
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
import torch

app = Flask(__name__)

# ** Hafif SD Turbo Modeli ve LoRA Yükleme **
base_model = "stabilityai/sd-turbo"  # Hafif model
lora_model = "maria26/Floor_Plan_LoRA"

pipe = StableDiffusionPipeline.from_pretrained(
    base_model, torch_dtype=torch.float16, safety_checker=None
)

pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)

# LoRA'yı yükle
pipe.load_lora_weights(lora_model)

# Eğer GPU yetmezse CPU'ya geçir
device = "cuda" if torch.cuda.is_available() else "cpu"
pipe.to(device)

@app.route('/generate', methods=['POST'])
def generate():
    data = request.json
    prompt = data.get("prompt", "a simple architectural floor plan")

    try:
        image = pipe(prompt).images[0]
        image_path = "static/output.png"
        image.save(image_path)
        return jsonify({"status": "success", "image_url": image_path})
    except Exception as e:
        return jsonify({"status": "error", "message": str(e)})

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5000, debug=True)