-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.py
More file actions
55 lines (50 loc) · 2.02 KB
/
search.py
File metadata and controls
55 lines (50 loc) · 2.02 KB
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
# import useful libraries
from flask import Flask, jsonify, request
import pandas as pd
import openai
openai.api_key = "xxxx"
import pandas_gpt
###### Useful Functions ######
"""
Input array:
Object = {
'method' : 'check_db',
'context' : 'find a book that contains ship',
'student_id' : '5d66ee1de283ad380812600cbc8859789df54b15425ac883a5ff32a941248115',
'call_number' : 'JA66 .H795 1968',
'name' : 'The Obama phenomenon'
}
"""
# load datasets
physical_df = pd.read_excel('./datasets/Physical.xlsx')
online_df = pd.read_excel('./datasets/Online.xlsx')
glo_df = pd.read_excel('./datasets/GLO.xlsx')
# print("Datasets loaded")
# print(glo_df.head())
app = Flask(__name__)
@app.route('/api/data', methods=['GET'])
def search_db(obj):
context = obj['context']
# check glo
if 'graduate learning outcome' in context or 'glo' in context:
# perform check
student_details = glo_df.ask(f"find the record with {obj['student_id']} as a dictionary with the column name as the key and the record data as the value. Remove the StudentID2 key and all keys with nan values.")
# something, return first details
if len(student_details) > 0:
return jsonify(student_details)
else:
return None
# check physical and online items
else:
# search physical
try:
resource_details = physical_df.ask(f"find records with {obj['call_number']} and store it as a dictionary with the column name as the key and the record data as the value. Replace all nan values with 'Not available'. Store datetime values as string with the year, month and date.")
return jsonify(resource_details)
# search online
except:
resource_details = online_df.ask(f"find records that contain {obj['name']}. Store the column names as keys and the record data as value as a dictionary.")
return jsonify(resource_details)
finally:
return None
if __name__ == '__main__':
app.run(host='0.0.0.0',debug=True, port=5000)