-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkey_app.py
50 lines (36 loc) · 1.47 KB
/
key_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
from flask import Flask, jsonify, request
from flask_cors import CORS
import json
import google.generativeai as gpt
from dotenv import load_dotenv
import os
load_dotenv()
app = Flask(__name__)
# Allow CORS for all routes from the specified origin
CORS(app, resources={r"/*": {"origins": "http://localhost:5500"}})
@app.route("/submit-answers", methods=["POST"])
def submit_answers():
try:
data = request.get_json(force=True) # Force JSON parsing
print("Received data:", data) # Log the received data
if not data:
return jsonify({"error": "No data received"}), 400
return jsonify({"message": "Answers received successfully", "data": data})
except Exception as e:
print("Error:", e) # Log the error
return jsonify({"error": str(e)}), 400
@app.route("/questions1")
def questions():
data = request.get_json(force=True) # Force JSON parsing
print("Received data:", data) # Log the received data
if not data:
return jsonify({"error": "No data received"}), 400
#take the all answers and generate question1 using gpt
#generate question1
#based on the answers and prompt
prompt = "act as carrer advisor and generate questions based on the answers"
question1 = gpt.generate_question(data, prompt)
#return question1
return jsonify({"message": "Questions received successfully", "data": question1})
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=5000)