File size: 3,513 Bytes
02b9964
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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')

# Serve the main HTML file for the frontend
@app.route('/')
def index():
    return send_from_directory(app.static_folder, 'index.html')


# Serve the CSS files
@app.route('/styles.css')
def styles():
    return send_from_directory(app.static_folder, 'styles.css')


# Serve the JavaScript files
@app.route('/script.js')
def script():
    return send_from_directory(app.static_folder, 'script.js')


# Route for Counseling Model
@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})


# Route for Medication Info Model
@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})


# Route for Diabetes Classification
@app.route('/api/diabetes_classification', methods=['POST'])
def diabetes_classification():
    data = request.json

    # Extract input features
    glucose = data.get('glucose')
    bmi = data.get('bmi')
    age = data.get('age')

    # Validate input data
    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})


# Route for Medicine Classification
@app.route('/api/medicine_classification', methods=['POST'])
def medicine_classification():
    data = request.json

    # Extract input features
    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')

    # Validate input data
    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

    # Prepare the new data as a DataFrame
    new_data = {
        'Age': [int(age)],
        'Gender': [gender],
        'Blood Type': [blood_type],
        'Medical Condition': [medical_condition],
        'Test Results': [test_results]
    }

    # Call the classification function
    medicine = classify_medicine(new_data)
    return jsonify({"medicine": medicine[0]})



# Route for General Chat (Llama 3.1 API using Groq Cloud)
@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

    # Get formatted response from LLaMA 3.1 hosted on Groq Cloud
    llama_response = get_llama_response(question)
    return jsonify({"response": llama_response})


if __name__ == '__main__':
    app.run(debug=True)