File size: 1,270 Bytes
d6f16db 26e1774 4393529 d6f16db 18f5113 d6f16db bf01bb4 |
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 |
from flask import Flask, jsonify
import asyncio
import os
from hiou import hugging, Ahugging, browser
import json
async def get_answer(image: str, question: str):
filename = image
spid = os.getenv('SPID')
hug = Ahugging(spid)
filelink = await hug.upload(open(filename, "rb"))
data = [
{
"meta": {
"_type": "gradio.FileData"
},
"mime_type": "image/jpeg",
"orig_name": filename,
"path": filelink.split("=", 1)[1],
"size": os.path.getsize(filename),
"url": filelink
},
question,
{
"tab_index": 0
}
]
datas = os.getenv('DATA')
jsnd = json.loads(datas)
data.append(jsnd)
print(f"SPID : {spid}, DATA : {data}")
await hug.filnal_setup(data, 2, 15)
await hug.start()
return hug.output.get("data")[0]
app = Flask(__name__)
# Example async route using asyncio.sleep
@app.route('/async-task')
async def async_task():
await asyncio.sleep(2) # Simulate async task
return jsonify({"message": "Async task completed!"})
@app.route('/')
def home():
return jsonify({"message": "Welcome to my Flask API!"})
|