|
from flask import Flask, jsonify, request, send_from_directory
|
|
from backend.utils import (
|
|
generate_counseling_response,
|
|
generate_medication_response,
|
|
classify_diabetes,
|
|
classify_medicine,
|
|
get_llama_response
|
|
)
|
|
import os
|
|
|
|
app = Flask(__name__, static_folder='frontend', template_folder='frontend')
|
|
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return send_from_directory(app.static_folder, 'index.html')
|
|
|
|
|
|
|
|
@app.route('/styles.css')
|
|
def styles():
|
|
return send_from_directory(app.static_folder, 'styles.css')
|
|
|
|
|
|
|
|
@app.route('/script.js')
|
|
def script():
|
|
return send_from_directory(app.static_folder, 'script.js')
|
|
|
|
|
|
|
|
@app.route('/api/counseling', methods=['POST'])
|
|
def counseling():
|
|
data = request.json
|
|
question = data.get('question')
|
|
if not question:
|
|
return jsonify({"error": "Question is required."}), 400
|
|
|
|
response = generate_counseling_response(question)
|
|
return jsonify({"response": response})
|
|
|
|
|
|
|
|
@app.route('/api/medication', methods=['POST'])
|
|
def medication():
|
|
data = request.json
|
|
question = data.get('question')
|
|
if not question:
|
|
return jsonify({"error": "Question is required."}), 400
|
|
|
|
response = generate_medication_response(question)
|
|
return jsonify({"response": response})
|
|
|
|
|
|
|
|
@app.route('/api/diabetes_classification', methods=['POST'])
|
|
def diabetes_classification():
|
|
data = request.json
|
|
|
|
|
|
glucose = data.get('glucose')
|
|
bmi = data.get('bmi')
|
|
age = data.get('age')
|
|
|
|
|
|
if glucose is None or bmi is None or age is None:
|
|
return jsonify({"error": "Please provide glucose, bmi, and age."}), 400
|
|
|
|
result = classify_diabetes(glucose, bmi, age)
|
|
return jsonify({"result": result})
|
|
|
|
|
|
|
|
@app.route('/api/medicine_classification', methods=['POST'])
|
|
def medicine_classification():
|
|
data = request.json
|
|
|
|
|
|
age = data.get('age')
|
|
gender = data.get('gender')
|
|
blood_type = data.get('blood_type')
|
|
medical_condition = data.get('medical_condition')
|
|
test_results = data.get('test_results')
|
|
|
|
|
|
if not (age and gender and blood_type and medical_condition and test_results):
|
|
return jsonify({"error": "Please provide Age, Gender, Blood Type, Medical Condition, and Test Results."}), 400
|
|
|
|
|
|
new_data = {
|
|
'Age': [int(age)],
|
|
'Gender': [gender],
|
|
'Blood Type': [blood_type],
|
|
'Medical Condition': [medical_condition],
|
|
'Test Results': [test_results]
|
|
}
|
|
|
|
|
|
medicine = classify_medicine(new_data)
|
|
return jsonify({"medicine": medicine[0]})
|
|
|
|
|
|
|
|
|
|
@app.route('/api/general', methods=['POST'])
|
|
def general_chat():
|
|
data = request.json
|
|
question = data.get('question')
|
|
if not question:
|
|
return jsonify({"error": "Question is required."}), 400
|
|
|
|
|
|
llama_response = get_llama_response(question)
|
|
return jsonify({"response": llama_response})
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True)
|
|
|