-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
59 lines (49 loc) · 1.74 KB
/
app.py
File metadata and controls
59 lines (49 loc) · 1.74 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
56
57
58
59
import os
from flask import Flask, request
from answer import answer_user_question
from questions import get_random_questions
from check_answers import check_answers
from flask_cors import CORS
app = Flask(__name__)
port = int(os.environ.get("PORT", 10000))
CORS(app)
@app.route("/ask-question", methods=["POST", "GET"])
def ask_question():
json_content = request.json
question = json_content.get('question')
answer = answer_user_question(question)
return {"question": question, "answer": answer}
@app.route("/check-answer", methods=["POST", "GET"])
def check_answer():
json_content = request.json
question = json_content.get('question')
answer = json_content.get('answer')
evaluation = check_answers(question, answer)
return {"question": question, "answer": answer, "evaluation": evaluation}
@app.route("/get-questions", methods=["POST", "GET"])
def get_questions():
json_content = request.json
topic = json_content.get('topic')
questions = get_random_questions(topic)
return {"Topic": topic, "Questions": questions}
@app.route("/")
def show_api_info():
return {
"name": "RAG ChatBot API for mock interview",
"creator": "M Mohamed Arafath",
"linkedin": "https://linkedin.com/in/mohamedarafath205",
"endpoints": [
{
"path": "/ask-question",
"methods": ["POST", "GET"],
"description": "Ask a question and get an AI-generated answer"
},
{
"path": "/get-questions",
"methods": ["POST", "GET"],
"description": "Gives you a list of questions from the loaded PDF's"
}
]
}
if __name__ == "__main__":
app.run(host="0.0.0.0", port=port)