from flask import request, jsonify, redirect, url_for, render_template from app import app, db # from app.models import User import PIL from eden.client import Client from eden.datatypes import Image import time @app.route('/api', methods=['POST']) def process_request(): image = request.files.get('image') text = request.form.get('text') blocks = request.form.getlist('blocks') # Process image, text, and blocks as needed # log to flask log the blocks list. app.logger.info(blocks) app.logger.info(text) results = communicate_with_eden(app, image) return jsonify(results) # return jsonify(success=True) def communicate_with_eden(app, image, ip_address="172.18.0.3", port="5656"): url = f"http://{ip_address}:{port}" ## set up a client c = Client(url=url, username="abraham") # get server's identity generator_id = c.get_generator_identity() print(generator_id) app.logger.info("setting config") ## define input args to be sent config = { "width": 2000, ## width "height": 1000, ## height "input_image": Image( PIL.Image.open(image.stream) ), ## images require eden.datatypes.Image() } app.logger.info("set config, running now") # start the task run_response = c.run(config) results = c.fetch(token=run_response["token"]) print("Intitial response") # check status of the task, returns the output too if the task is complete # results = c.await_results(token=run_response["token"], interval=1, show_progress=False) i = 0 while results["status"].get("status") != "complete": results = c.fetch(token=run_response["token"]) print(results) time.sleep(0.1) i += 1 if i > 50: break return results