Commit last-minute
This commit is contained in:
parent
b4a97a65ab
commit
0ba7189bfc
221 changed files with 139931 additions and 1 deletions
49
server.py
Normal file
49
server.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
from flask import Flask, request, jsonify, send_from_directory
|
||||
import image_extraction
|
||||
import openAlea
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return send_from_directory(".", "index.html")
|
||||
|
||||
@app.route("/plant/generate", methods=["POST"])
|
||||
def generate():
|
||||
try:
|
||||
data = request.get_json()
|
||||
print("Dati ricevuti:", data) # 👈 debug utile
|
||||
|
||||
# Recupero valori con i nomi reali del form
|
||||
plant_type = data.get("plant") # era "type"
|
||||
days = data.get("daysFuture") # era "days"
|
||||
image_base64 = data.get("image")
|
||||
if not plant_type or not days:
|
||||
return jsonify({"error": "Specie o giorni mancanti"}), 400
|
||||
|
||||
# Se immagine è una stringa valida
|
||||
if isinstance(image_base64, str) and image_base64.strip():
|
||||
image_extraction.main()
|
||||
future_image = image_base64
|
||||
description = f"Dopo {days} giorni, la {plant_type} appare più sviluppata con foglie più larghe."
|
||||
else:
|
||||
future_image = None
|
||||
description = f"Dopo {days} giorni, la {plant_type} è stimata in crescita basata solo sui parametri."
|
||||
print(future_image)
|
||||
print(description)
|
||||
|
||||
ret = jsonify({
|
||||
"plantType": plant_type,
|
||||
"days": days,
|
||||
"futureImage": future_image,
|
||||
"description": description
|
||||
})
|
||||
print(ret)
|
||||
return ret
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
Loading…
Add table
Add a link
Reference in a new issue