5m4ck3r commited on
Commit
aae2a9b
1 Parent(s): 2ee66eb

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +67 -0
main.py CHANGED
@@ -39,6 +39,42 @@ def get_answer(image: io.BytesIO, question: str):
39
  hug.start()
40
  return hug.output.get("data")[0]
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  app = Flask(__name__)
43
 
44
  @app.route('/getans', methods=['POST'])
@@ -57,6 +93,37 @@ def async_task():
57
  answer = get_answer(file_content, headers.get('QU', ''))
58
  return jsonify({"status" : True, "ANS" : answer})
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  @app.route('/')
61
  def home():
62
  return jsonify({"message": "Welcome to my Flask API!"})
 
39
  hug.start()
40
  return hug.output.get("data")[0]
41
 
42
+ def valuate_qna(p: str, r: str) -> str:
43
+ spid2 = os.getenv('SPID2')
44
+ hug = hugging(spid2)
45
+ data = [
46
+ p,
47
+ r
48
+ ]
49
+ hug.filnal_setup(data, 0, 12)
50
+ hug.start()
51
+ return hug.output.get("data", [None])[0]
52
+
53
+ def ocr(image: io.BytesIO) -> str:
54
+ spid3 = os.getenv('SPID3')
55
+ hug = hugging(spid3)
56
+ filelink = hug.upload(image)
57
+ image.seek(0, 2)
58
+ file_size = image.tell()
59
+ image.seek(0)
60
+ data = [
61
+ {
62
+ "meta": {
63
+ "_type": "gradio.FileData"
64
+ },
65
+ "mime_type": "image/jpeg",
66
+ "orig_name": "new.jpg",
67
+ "path": filelink.split("=", 1)[1],
68
+ "size": file_size,
69
+ "url": filelink
70
+ },
71
+ os.getenv('AZKEY'),
72
+ os.getenv('AZURL')
73
+ ]
74
+ hug.filnal_setup(data, 0, 13)
75
+ hug.start()
76
+ return hug.output.get("data")[0]
77
+
78
  app = Flask(__name__)
79
 
80
  @app.route('/getans', methods=['POST'])
 
93
  answer = get_answer(file_content, headers.get('QU', ''))
94
  return jsonify({"status" : True, "ANS" : answer})
95
 
96
+ @app.route('/ocr', methods=['POST'])
97
+ def async_task():
98
+ if 'file' not in request.files:
99
+ return jsonify({"status" : False, "msg" : "No file found"}), 400
100
+ file = request.files['file']
101
+ if file.filename == '':
102
+ return jsonify({"error": "No selected file"}), 400
103
+ file_content = io.BytesIO(file.read())
104
+ file_content.name = file.filename
105
+ headers = dict(request.headers)
106
+ if not headers.get("KEY") != os.getenv("KEY"):
107
+ return jsonify({"status" : False, "msg" : "Invalid API Key"}), 404
108
+ answer = ocr(file_content)
109
+ return jsonify({"status" : True, "DATA" : answer})
110
+
111
+ @app.route('/check', methods=['POST', 'GET'])
112
+ def check_f():
113
+ jsndata = request.json()
114
+ p = jsndata.get("p")
115
+ r = jsndata.get("r")
116
+ headers = dict(request.headers)
117
+ if not headers.get("KEY") != os.getenv("KEY"):
118
+ return jsonify({"status" : False, "msg" : "Invalid API Key"}), 404
119
+ data = valuate_qna(p, r)
120
+ return jsonify(
121
+ {
122
+ "status" : True,
123
+ "data" : data
124
+ }
125
+ )
126
+
127
  @app.route('/')
128
  def home():
129
  return jsonify({"message": "Welcome to my Flask API!"})