From aebccd017d406ea8318dca6d0cfb18b5f054dead Mon Sep 17 00:00:00 2001 From: HEET VEKAIRYA Date: Sat, 26 Aug 2023 19:25:57 +0530 Subject: [PATCH] working disease prediction --- forms.py | 5 +-- server.py | 33 +++++++++++++++++++- templates/base.html | 2 +- templates/prediction.html | 64 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 templates/prediction.html diff --git a/forms.py b/forms.py index 9acedaa..40119bb 100644 --- a/forms.py +++ b/forms.py @@ -1,6 +1,6 @@ import re from flask_wtf import FlaskForm -from wtforms import StringField, SubmitField, PasswordField, SelectField, IntegerField, TextAreaField, RadioField, validators +from wtforms import StringField, SubmitField, PasswordField, SelectField, IntegerField, TextAreaField, RadioField, validators, SelectMultipleField from wtforms.validators import DataRequired from Disease import list_column_names @@ -14,7 +14,8 @@ def validate_phone_number(form, field): column_names = list_column_names("dataset/Training.csv") class DiseaseDetailsForm(FlaskForm): name = StringField("Name", validators=[DataRequired()]) - disease_list = SelectField("Disease", choices=[(column_name, column_name) for column_name in column_names]) + symptomp_list = SelectMultipleField("Disease", choices=[(column_name, column_name) for column_name in column_names]) + print(symptomp_list) submit = SubmitField("Submit") class PatientDetailsForm(FlaskForm): diff --git a/server.py b/server.py index 83b544b..593b6f5 100644 --- a/server.py +++ b/server.py @@ -11,7 +11,7 @@ from werkzeug.security import generate_password_hash, check_password_hash from speechToText import convert_speech_to_text - +from predict_disease import predict_disease from backend.mongoConnect import * @@ -164,6 +164,37 @@ def doctor_page(): text = convert_speech_to_text('recorded/recorded-audio.wav') return render_template('doctor.html', user=user, stt_form=stt_form, text=text) +@app.route("/predict", methods=["GET", "POST"]) +def disease_prediction(): + form = DiseaseDetailsForm(request.form) + if request.method == "POST": + print("Form:", request.form) + print("Form Submitted") + # if form.validate_on_submit(): + selected_symptoms = request.form.getlist("symptomp_list") # Use getlist to handle multiple selections + print(selected_symptoms) + input_symptoms_str = ",".join(selected_symptoms) + result = predict_disease(input_symptoms_str) + + unique_values = set() + + # Iterate through the values of the dictionary and add them to the set + for value in result.values(): + unique_values.add(value) + + # If the set contains only one value, then the prediction is successful + if len(unique_values) >= 1: + print(unique_values) + else: + print("Prediction Failed") + result = "Prediction Failed" + return render_template("prediction.html", form=form, result=unique_values, user=user) + # else: + # print("Form Validation Failed") # Debugging message + + return render_template("prediction.html", form=form, user=user) + + @app.route('/patient') @logged_in def patient_page(): diff --git a/templates/base.html b/templates/base.html index 033247c..dfa2843 100644 --- a/templates/base.html +++ b/templates/base.html @@ -72,7 +72,7 @@ {% endif %} {% if user.role == "doctor" %}