import os import sys from flask import Flask, jsonify, request, app from flask_cors import CORS current_dir = os.path.dirname(os.path.abspath(__file__)) parent_dir = os.path.dirname(current_dir) sys.path.append(parent_dir) from model_prediction_wrapper import slice_sentences app = Flask(__name__) CORS(app, resources={r"/api/*": {"origins": "https://procid-git.github.io"}}) @app.route('/api/predict', methods=['POST']) def get_ai_prediction(): if 'aiImage' not in request.files: return jsonify({"prediction": "Error, no file uploaded"}), 400 image = request.files['aiImage'] ai_prediction = slice_sentences(image.stream) return jsonify({"prediction": ai_prediction}) if __name__ == "__main__": port = int(os.environ.get("PORT", 7860)) app.run(host="0.0.0.0", port=port, debug=True)