Skip to content

Commit

Permalink
Merge pull request #50 from Dv04/Heet
Browse files Browse the repository at this point in the history
working disease prediction
  • Loading branch information
Dv04 authored Aug 26, 2023
2 parents 95b70a9 + aebccd0 commit ea733df
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 4 deletions.
5 changes: 3 additions & 2 deletions forms.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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):
Expand Down
33 changes: 32 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down Expand Up @@ -166,6 +166,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():
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
{% endif %}
{% if user.role == "doctor" %}
<li class="nav-item" style="cursor: pointer;">
<a class="nav-link" aria-current="page" onclick="showDoctorSection('predictive-model')">AI-ML</a>
<a class="nav-link" aria-current="page" onclick="showDoctorSection('predictive-model')" href="{{ url_for('disease_prediction') }}">AI-ML</a>
</li>
<li class="nav-item" style="cursor: pointer;">
<a class="nav-link" aria-current="page" onclick="showDoctorSection('speech-to-text')">Speech-To-Text</a>
Expand Down
64 changes: 64 additions & 0 deletions templates/prediction.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{% extends 'base.html' %}
{% import "bootstrap/wtf.html" as wtf %}

{% block title %}Prediction{% endblock title %}

<style>
/* CSS for the form */
form {
margin: 20px;
padding: 10px;
border: 1px solid #ccc;
background-color: #f9f9f9;
max-width: 400px;
}

label {
font-weight: bold;
}

select {
width: 100%;
padding: 5px;
margin-bottom: 10px;
}

button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
}

button:hover {
background-color: #0056b3;
}

/* CSS for the result div */
#result {
margin: 20px;
padding: 10px;
border: 1px solid #ccc;
background-color: #f9f9f9;
max-width: 400px;
}
</style>

{% block body %}

<h1>Disease Predictor</h1>
<form method="POST" action="{{url_for('disease_prediction')}}">
{{ form.hidden_tag() }}
<label for="symptoms">Select Symptoms:</label>
{{ form.symptomp_list() }}
<br>
<button type="submit">Predict Disease</button>
</form>
<div id="result">
{{result}}
</div>

{% endblock body %}


0 comments on commit ea733df

Please sign in to comment.