Spaces:
Sleeping
Sleeping
File size: 2,706 Bytes
43b5b7f 28b3018 43b5b7f 28b3018 43b5b7f 28b3018 43b5b7f 28b3018 43b5b7f 28b3018 43b5b7f 99572a2 2e5c244 99572a2 3b189fb 99572a2 3b189fb |
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
from flask import Flask, request, jsonify
from asgiref.sync import async_to_sync
from hiou import *
import traceback
app = Flask(__name__)
async def generate_illu(subject, out1, out2, expression, bgdesc, bgcol):
gene = gen()
result = await gene.generate_illustrator(subject, out1, out2, expression, bgdesc, bgcol)
return result
async def generate_image(prompt, negative):
gene = gen()
result = await gene.generete_image(prompt, negative)
return result
@app.route('/illu')
def gettans_task():
query_string = request.args.get('s')
tore = request.args.get('t', 4)
try:
tore = int(tore)
except:
tore = 4
ser = search()
result = ser.search(query_string, tore)
return jsonify(
result
)
@app.route('/genillu')
def generateIllus():
subject = request.args.get('subject')
out1 = request.args.get('out1')
out2 = request.args.get('out2')
expression = request.args.get('exp')
bgdesc = request.args.get('desc')
bgcol = request.args.get('bgcol')
try:
resul = async_to_sync(generate_illu)(subject, out1, out2, expression, bgdesc, bgcol)
except Exception as e:
print(f"ERROR : {e}, {traceback.format_exc()}")
return jsonify([])
return jsonify(resul)
@app.route('/genimg')
def generate_ImageS():
prompt = request.args.get("prompt")
negative = request.args.get("negative")
try:
resul = async_to_sync(generate_image)(prompt, negative)
except Exception as e:
print(f"ERROR : {e}, {traceback.format_exc()}")
return jsonify([])
return jsonify(resul)
@app.route('/')
def root():
return jsonify(
{
"status" : True,
"message" : "Nothing here"
}
)
@app.route("/solution")
def getSolution_from_query():
query = request.args.get("query")
try:
cl = getSolution()
out = cl.get_solution(query)
return jsonify(
{
"status" : True,
"msg" : out
}
)
except:
print(f"ERROR : {traceback.format_exc()}")
return jsonify(
{
"status" : False,
"msg" : "Something error has occur"
}
)
@app.route("/convert", methods=["POST"])
def convert_to_readable():
try:
xml = request.data.decode("utf-8")
if not xml:
return jsonify({"status": False, "msg": "No XML provided"}), 400
conv = convertBlock()
txt = conv.convert(xml)
return jsonify({"status": True, "msg": txt})
except Exception:
return jsonify({"status": False, "msg": f"Error: {traceback.format_exc()}"}), 500
|