5m4ck3r commited on
Commit
9ae77d3
1 Parent(s): e2ac9eb

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -11
main.py CHANGED
@@ -1,14 +1,14 @@
1
- from quart import Quart, request, jsonify
2
  import asyncio
3
  import os
4
  from hiou import Ahugging, browser
5
  import json
6
 
7
- async def get_answer(image: str, question: str):
8
  filename = image
9
  spid = os.getenv('SPID')
10
- hug = Ahugging(spid)
11
- filelink = await hug.upload(open(filename, "rb"))
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
- await hug.filnal_setup(data, 2, 15)
33
- await hug.start()
34
  return hug.output.get("data")[0]
35
 
36
- app = Quart(__name__)
37
 
38
  @app.route('/getans', methods=['POST'])
39
- async 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 = await 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 = await get_answer(file_content, headers.get('QU', ''))
51
  return jsonify({"status" : True, "ANS" : answer})
52
 
53
  @app.route('/')
54
- async def home():
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