ChatGPT выдал что-то такое:
import requests
import json
from flask import Flask, request
from kandinsky2 import get_kandinsky2
app = Flask(__name__)
model = get_kandinsky2('cuda', task_type='text2img')
@app.route('/generate-image', methods=['POST'])
def generate_image():
# Get the JSON payload from the incoming request
request_data = request.get_json()
# Get the value of the 'text' key from the JSON payload
text_input = request_data['text']
# Generate an image using the text string
ages = model.generate_text2img(text_input, batch_size=4, h=512, w=512, num_steps=75, denoised_type='dynamic_threshold', dynamic_threshold_v=99.5, sampler='ddim_sampler', ddim_eta=0.01, guidance_scale=10)
# Convert the image to a JSON string and send it to the sender of the original request
result = json.dumps(ages)
payload = {'result': result}
headers = {'Content-Type': 'application/json'}
# Use the 'referer' header to get the URL of the sender of the original request
referer = request.headers.get('referer')
# Send the JSON payload to the sender of the original request using an HTTP POST request
response = requests.post(referer, json=payload, headers=headers)
return response.content, response.status_code
if __name__ == '__main__':
app.run()