Update main.py
Browse files
main.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
-
from
|
2 |
import asyncio
|
3 |
import os
|
4 |
from hiou import Ahugging, browser
|
5 |
import json
|
6 |
|
7 |
-
|
8 |
filename = image
|
9 |
spid = os.getenv('SPID')
|
10 |
-
hug =
|
11 |
-
filelink =
|
12 |
data = [
|
13 |
{
|
14 |
"meta": {
|
@@ -29,28 +29,28 @@ async def get_answer(image: str, question: str):
|
|
29 |
jsnd = json.loads(datas)
|
30 |
data.append(jsnd)
|
31 |
print(f"SPID : {spid}, DATA : {data}")
|
32 |
-
|
33 |
-
|
34 |
return hug.output.get("data")[0]
|
35 |
|
36 |
-
app =
|
37 |
|
38 |
@app.route('/getans', methods=['POST'])
|
39 |
-
|
40 |
if 'file' not in request.files:
|
41 |
jsonify({"status" : False, "msg" : "No file found"}), 400
|
42 |
file = request.files['file']
|
43 |
if file.filename == '':
|
44 |
return jsonify({"error": "No selected file"}), 400
|
45 |
-
file_content =
|
46 |
headers = dict(request.headers)
|
47 |
if not headers.get("KEY") == os.getenv("KEY"):
|
48 |
return jsonify({"status" : False, "msg" : "Invalid API Key"}), 404
|
49 |
print(f"QUESTION ASKED : {headers.get('QU', '')}")
|
50 |
-
answer =
|
51 |
return jsonify({"status" : True, "ANS" : answer})
|
52 |
|
53 |
@app.route('/')
|
54 |
-
|
55 |
return jsonify({"message": "Welcome to my Flask API!"})
|
56 |
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
import asyncio
|
3 |
import os
|
4 |
from hiou import Ahugging, browser
|
5 |
import json
|
6 |
|
7 |
+
def get_answer(image: str, question: str):
|
8 |
filename = image
|
9 |
spid = os.getenv('SPID')
|
10 |
+
hug = hugging(spid)
|
11 |
+
filelink = hug.upload(open(filename, "rb"))
|
12 |
data = [
|
13 |
{
|
14 |
"meta": {
|
|
|
29 |
jsnd = json.loads(datas)
|
30 |
data.append(jsnd)
|
31 |
print(f"SPID : {spid}, DATA : {data}")
|
32 |
+
hug.filnal_setup(data, 2, 15)
|
33 |
+
hug.start()
|
34 |
return hug.output.get("data")[0]
|
35 |
|
36 |
+
app = Flask(__name__)
|
37 |
|
38 |
@app.route('/getans', methods=['POST'])
|
39 |
+
def async_task():
|
40 |
if 'file' not in request.files:
|
41 |
jsonify({"status" : False, "msg" : "No file found"}), 400
|
42 |
file = request.files['file']
|
43 |
if file.filename == '':
|
44 |
return jsonify({"error": "No selected file"}), 400
|
45 |
+
file_content = file.read()
|
46 |
headers = dict(request.headers)
|
47 |
if not headers.get("KEY") == os.getenv("KEY"):
|
48 |
return jsonify({"status" : False, "msg" : "Invalid API Key"}), 404
|
49 |
print(f"QUESTION ASKED : {headers.get('QU', '')}")
|
50 |
+
answer = get_answer(file_content, headers.get('QU', ''))
|
51 |
return jsonify({"status" : True, "ANS" : answer})
|
52 |
|
53 |
@app.route('/')
|
54 |
+
def home():
|
55 |
return jsonify({"message": "Welcome to my Flask API!"})
|
56 |
|