-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
104 lines (89 loc) · 4.86 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Data-API Implementation 2022 Smart India Hackathon
# Contributors Garvit Chouhan, Kaustub Dutt Pandey, Chelsi Jain
"""
-------------------------------------------------------------------------------
Data-API Documentation |
-------------------------------------------------------------------------------
|
POST /search |
Form-Data |
- Image : file |
- Mode : 0 ( Real-Dataset ) |
1 ( Dummy-Dataset ) |
Returns |
{ Task : URL(/state/<Task_id>) } |
|
-------------------------------------------------------------------------------
|
GET /search/<Task_id> |
|
Returns |
{ 'Phase':<_>, 'Info':<_> } |
- Phase: Success Info : Person-Details (Dictionary) |
- Phase: Process Info : Current Running Process (String) |
- Phase: Failure Info : Error Message (String) |
|
* Personal-Details : |
{ |
Img (image_link) |
Report_link ( Redirects to Report Page ) |
Profile_link ( Redirects to Full Profile Page ) |
Name |
Current_Age |
Gender |
Father_Name |
Place_of_Missing |
Date_of_Missing |
} |
|
* Current Running Process : |
- 'Fetching New Data' |
- 'Encoding New Data' |
- 'Updating Database State' |
- 'Flex Searching Image' |
|
* Error Message : |
- 'No Image Uploaded' |
- 'No Face Detected' |
- 'Person Not Found' |
|
-------------------------------------------------------------------------------
"""
# Dependencies
from Flex_Algo.Background_Task_Module import *
from flask import Flask, jsonify, request
from flask_pymongo import PyMongo,ObjectId
from dotenv import load_dotenv
from flask_cors import CORS
import os
load_dotenv()
# Initialize Flask App
app = Flask(__name__)
# Connect MongoDB
app.config["MONGO_URI"] = os.getenv("MONGO_URI")
mongo = PyMongo(app)
# API Cross Origin Support
CORS = CORS(app)
# Runtime Catch
def before_request():
app.jinja_env.cache = {}
app.before_request(before_request)
#Flex-Background-Process
Flex_Process = Background_Task(mongo)
# search endpoint
@app.route('/search', methods=['POST'])
def result():
if request.method == 'POST':
if 'Image' not in request.files: File = None
else: File = request.files['Image']
Mode = bool(int(request.form.get('Mode')))
task = Flex_Process.run(File,Mode)
return jsonify(task)
# state endpoint
@app.route("/state/<ObjectId:task_id>")
def state(task_id):
res = Flex_Process.state(task_id)
return jsonify(res)
# Run Server
if __name__ == '__main__':
app.run()