File size: 957 Bytes
6349504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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)