You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from flask import Flask, render_template, request
import pickle
from model import *
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from nltk.stem import WordNetLemmatizer
from sklearn import *
app = Flask(__name__)
model = pickle.load(open('dengue.pkl', 'rb'))
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST', 'GET'])
def predict():
symptoms = str(request.form['text'])
stop_words = set(stopwords.words('english'))
words = word_tokenize(symptoms.lower())
words = [word for word in words if word.isalpha() and word not in stop_words]
preprocessed_symptoms = ' '.join(words)
tfidf_vectorizer = TfidfVectorizer(max_features=1500)
symptom_tfidf = tfidf_vectorizer.fit_transform([preprocessed_symptoms]).toarray
X_train, X_test, y_train, y_test = train_test_split(tfidf_features, labels, test_size=0.2, random_state=42)
knn_classifier = KNeighborsClassifier(n_neighbors=5)
knn_classifier.fit(X_train, y_train)
predictions = knn_classifier.predict(X_test)
symptom_tfidf = tfidf_vectorizer.fit_transform([preprocessed_symptoms])
result = model.predict(symptom_tfidf)
if result[0] == "Dengue":
result = "You are more likely to be suffering from dengue!"
else :
result = "You have less chances that you are suffering from dengue but there are chances that you are suffering from", result[0]
return render_template('index.html', result=result)
if __name__ == '__main__':
app.run(debug=True)
The text was updated successfully, but these errors were encountered:
Flask code
The text was updated successfully, but these errors were encountered: