5m4ck3r commited on
Commit
d2df03b
1 Parent(s): 1b04bb1

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -6
main.py CHANGED
@@ -1,7 +1,7 @@
1
- from flask import Flask, jsonify
2
  import asyncio
3
  import os
4
- from hiou import hugging, Ahugging, browser
5
  import json
6
 
7
  async def get_answer(image: str, question: str):
@@ -35,11 +35,20 @@ async def get_answer(image: str, question: str):
35
 
36
  app = Flask(__name__)
37
 
38
- # Example async route using asyncio.sleep
39
- @app.route('/async-task')
40
  async def async_task():
41
- await asyncio.sleep(2) # Simulate async task
42
- return jsonify({"message": "Async task completed!"})
 
 
 
 
 
 
 
 
 
 
43
 
44
  @app.route('/')
45
  def home():
 
1
+ from flask import Flask, jsonify, request
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):
 
35
 
36
  app = Flask(__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
  def home():