Update main.py
Browse files
main.py
CHANGED
@@ -3,6 +3,8 @@ import os
|
|
3 |
from hiou import hugging
|
4 |
import json
|
5 |
import io
|
|
|
|
|
6 |
|
7 |
def get_answer(image: io.BytesIO, question: str):
|
8 |
filename = image.name
|
@@ -80,12 +82,24 @@ app = Flask(__name__)
|
|
80 |
@app.route('/getans', methods=['POST'])
|
81 |
def gettans_task():
|
82 |
if 'file' not in request.files:
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
headers = dict(request.headers)
|
90 |
if not headers.get("KEY") != os.getenv("KEY"):
|
91 |
return jsonify({"status" : False, "msg" : "Invalid API Key"}), 404
|
@@ -96,12 +110,24 @@ def gettans_task():
|
|
96 |
@app.route('/ocr', methods=['POST'])
|
97 |
def task_ocr():
|
98 |
if 'file' not in request.files:
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
headers = dict(request.headers)
|
106 |
if not headers.get("KEY") != os.getenv("KEY"):
|
107 |
return jsonify({"status" : False, "msg" : "Invalid API Key"}), 404
|
|
|
3 |
from hiou import hugging
|
4 |
import json
|
5 |
import io
|
6 |
+
import random
|
7 |
+
import string
|
8 |
|
9 |
def get_answer(image: io.BytesIO, question: str):
|
10 |
filename = image.name
|
|
|
82 |
@app.route('/getans', methods=['POST'])
|
83 |
def gettans_task():
|
84 |
if 'file' not in request.files:
|
85 |
+
if len(request.data) > 0:
|
86 |
+
pass
|
87 |
+
else:
|
88 |
+
return jsonify({"status" : False, "msg" : "No file found"}), 400
|
89 |
+
|
90 |
+
if 'file' in request.files:
|
91 |
+
file = request.files['file']
|
92 |
+
if file.filename == '':
|
93 |
+
return jsonify({"error": "No selected file"}), 400
|
94 |
+
file_content = io.BytesIO(file.read())
|
95 |
+
file_content.name = file.filename
|
96 |
+
else:
|
97 |
+
rawFile = request.data
|
98 |
+
file = io.BytesIO(rawFile)
|
99 |
+
if not request.args.get("name"):
|
100 |
+
filename = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(10)) + ".png"
|
101 |
+
file.name = request.args.get("name", filename)
|
102 |
+
|
103 |
headers = dict(request.headers)
|
104 |
if not headers.get("KEY") != os.getenv("KEY"):
|
105 |
return jsonify({"status" : False, "msg" : "Invalid API Key"}), 404
|
|
|
110 |
@app.route('/ocr', methods=['POST'])
|
111 |
def task_ocr():
|
112 |
if 'file' not in request.files:
|
113 |
+
if len(request.data) > 0:
|
114 |
+
pass
|
115 |
+
else:
|
116 |
+
return jsonify({"status" : False, "msg" : "No file found"}), 400
|
117 |
+
|
118 |
+
if 'file' in request.files:
|
119 |
+
file = request.files['file']
|
120 |
+
if file.filename == '':
|
121 |
+
return jsonify({"error": "No selected file"}), 400
|
122 |
+
file_content = io.BytesIO(file.read())
|
123 |
+
file_content.name = file.filename
|
124 |
+
else:
|
125 |
+
rawFile = request.data
|
126 |
+
file = io.BytesIO(rawFile)
|
127 |
+
if not request.args.get("name"):
|
128 |
+
filename = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(10)) + ".png"
|
129 |
+
file.name = request.args.get("name", filename)
|
130 |
+
|
131 |
headers = dict(request.headers)
|
132 |
if not headers.get("KEY") != os.getenv("KEY"):
|
133 |
return jsonify({"status" : False, "msg" : "Invalid API Key"}), 404
|