IMG_OA / app.py
API-Handler's picture
Upload 4 files
6349504 verified
raw
history blame contribute delete
957 Bytes
# server.py
from flask import Flask, request, jsonify
from image_handler import ImageHandler
import os
app = Flask(__name__)
image_handler = ImageHandler()
@app.route('/v2/images/generations', methods=['POST'])
def generate_images():
try:
# Verify authorization
auth_header = request.headers.get('Authorization')
if not auth_header or not auth_header.startswith('Bearer '):
return jsonify({"error": "Invalid authorization"}), 401
# Get request data
data = request.get_json()
# Validate required fields
if not data.get('prompt'):
return jsonify({"error": "prompt is required"}), 400
# Generate images
result = image_handler.generate_images(data)
return jsonify(result)
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(port=5000, debug=True)