|
from flask import Flask, request, jsonify
|
|
from tensorflow.keras.models import load_model
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
from io import BytesIO
|
|
import base64
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
cnn_model = load_model("C:\\Users\\Sedef\\Downloads\\arcweb (1)\\arcweb\\cnn_model_epoch_100.h5")
|
|
|
|
def generate_prompt(params):
|
|
"""Kullanıcı girdilerinden bir prompt oluştur."""
|
|
prompt = (
|
|
f"{params['bedroom']} yatak odası, {params['bathroom']} banyo, "
|
|
f"{params['kitchen']} mutfak, {params['livingroom']} oturma odası, "
|
|
f"{params['diningroom']} yemek odası, {params['entrance']} m² giriş, "
|
|
f"{params['garage']} garaj ve {params['kidsroom']} çocuk odası içeren bir mimari plan."
|
|
)
|
|
return prompt
|
|
|
|
@app.route("/generate_plan", methods=["POST"])
|
|
def generate_plan():
|
|
|
|
data = request.json
|
|
prompt = generate_prompt(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input_data = np.array([[data['bedroom'], data['bathroom'], data['kitchen'],
|
|
data['livingroom'], data['diningroom'],
|
|
data['entrance'], data['garage'], data['kidsroom']]])
|
|
|
|
|
|
prediction = cnn_model.predict(input_data)
|
|
|
|
|
|
|
|
img = prediction.reshape((64, 64, 3))
|
|
plt.imshow(img)
|
|
plt.axis("off")
|
|
|
|
|
|
buffer = BytesIO()
|
|
plt.savefig(buffer, format="png")
|
|
buffer.seek(0)
|
|
img_base64 = base64.b64encode(buffer.getvalue()).decode()
|
|
|
|
return jsonify({"image_url": f"data:image/png;base64,{img_base64}"})
|
|
|
|
if __name__ == "__main__":
|
|
app.run(debug=True) |