-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
31 lines (24 loc) · 988 Bytes
/
server.py
File metadata and controls
31 lines (24 loc) · 988 Bytes
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
import os
import json
from flask import Flask, request, jsonify
from flask_cors import CORS
from utils.get_professor_information import query_graphQL
from utils.openai_client import get_summary_and_sentiment
from utils.retrieve_reviews import get_professor_reviews
app = Flask(__name__)
CORS(app=app, threaded=True, use_reloader=True)
@app.route('/queryProfessorResults', methods=['POST'])
def query_professor_results():
# Get the request body data
payload = request.json
print(f"Received payload: {payload}")
if not isinstance(payload, dict):
return jsonify({"error": "Invalid payload structure, expecting a dictionary"}), 400
professor_names = payload.get('professorNames', [])
response = query_graphQL(professor_names)
comments = get_professor_reviews(response)
response = get_summary_and_sentiment(comments)
print(response)
return jsonify({"professorInformationList": response})
if __name__ == '__main__':
app.run(debug=True)