ai-pokemon-card / app.py
Ron Au
Initial D
5c239ba
raw
history blame
1.22 kB
import time
from flask import Flask, jsonify, render_template, request
from modules.details import load_lists, rand_details
from modules.inference import generate_image
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
@app.route('/')
def index():
return render_template('index.html', **rand_details())
tasks = {}
@app.route('/task/create')
def create_task():
prompt = request.args.get('prompt') or "покемон"
task_id = f"{str(time.time())}_{prompt}"
tasks[task_id] = {
"task_id": task_id,
"prompt": prompt,
"status": "pending",
"poll_count": 0,
}
return jsonify(tasks[task_id])
@app.route('/task/queue')
def queue_task():
task_id = request.args.get('task_id')
tasks[task_id]["value"] = generate_image(tasks[task_id]["prompt"])
tasks[task_id]["status"] = "complete"
return jsonify(tasks[task_id])
@app.route('/task/poll')
def poll_task():
task_id = request.args.get('task_id')
tasks[task_id]["poll_count"] += 1
return jsonify(tasks[task_id])
@app.route('/details')
def generate_details():
return jsonify(rand_details())
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860)