[Python] Flask Can't see html file

Discussão em 'Python' iniciado por Stack, Maio 4, 2025.

  1. Stack

    Stack Membro Participativo

    Based on the data given here : https://www.kaggle.com/code/bhavikjikadara/loan-status-prediction-decisiontreeclassifier/input

    i want to make flask based ML model prediction for loan status, here is my html code and screenshot

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Prediction of Loan Status</title>
    </head>
    <body>

    <form action="/prediction" method="GET">
    <label for="Gender">Enter Gender:</label><br>
    <input type="text" id="Gender" name="Gender"><br>
    <label for="Married">Enter Married:</label><br>
    <input type="text" id="Married" name="Married"><br>
    <label for="Dependents">Enter Dependents:</label><br>
    <input type="text" id="Dependents" name="Dependents"><br>
    <label for="Education">Enter Education:</label><br>
    <input type="text" id="Education" name="Education"><br>
    <label for="Self_Employed">enter Self_Employed:</label><br>
    <input type="text" id="Self_Employed" name="Self_Employed"><br>
    <label for="ApplicantIncome">Enter ApplicantIncome:</label><br>
    <input type="text" id="ApplicantIncome" name="ApplicantIncome"><br>
    <label for="CoapplicantIncome">Enter CoapplicantIncome:</label><br>
    <input type="text" id="CoapplicantIncome" name="CoapplicantIncome"><br>
    <label for="LoanAmount">Enter LoanAmountn:</label><br>
    <input type="text" id="LoanAmount" name="LoanAmount"><br>
    <label for="Loan_Amount_Term">EnterLoan_Amount_Term:</label><br>
    <input type="text" id="Loan_Amount_Term" name="Loan_Amount_Term"><br>
    <label for="Credit_History">Enter Credit_History:</label><br>
    <input type="text" id="Credit_History" name="Credit_History"><br>
    <label for="Property_Area">Enter Property_Area:</label><br>
    <input type="text" id="Property_Area" name="Property_Area"><br>
    <input type ='submit' value="Make Prediction">

    </form>
    <p>score of Model is {{ score }}</p>

    </body>
    </html>


    [​IMG]

    and corresponding code is this :

    import pandas as pd
    from flask import Flask,request,render_template
    from sklearn.tree import DecisionTreeClassifier
    from sklearn.model_selection import train_test_split
    app =Flask(__name__)
    def convert_gender(gender):
    if gender=='Male':
    return 1
    else:
    return 0
    def convert_Martial(status):
    if status =="Yes":
    return 1
    else:
    return 0
    def convert_dependencies(numbr_dependency):
    if numbr_dependency=='3+':
    return 3
    else:
    return float(numbr_dependency)
    def convert_education(education):
    if education =='Graduate':
    return 1
    else:
    return 0
    def self_employeed_status(status):
    if status =='Yes':
    return 1
    else:
    return 0
    def get_Property_Area(area):
    if area=='Rural':
    return 0
    elif area=='Urban':
    return 1
    else:
    return 2
    @app.route('/Prediction',methods=['POST',"GET"])
    def welcome_Prediction():
    return render_template("Loan_Status.html")
    @app.route('/prediction',methods=['POST',"GET"])
    def prediction():
    data =pd.read_csv("loan_data.csv")
    data.drop('Loan_ID',axis=1,inplace=True)
    data.dropna(axis=0,inplace=True)
    data['Loan_Status'] =data['Loan_Status'].map({'N':0,'Y':1})
    # print(data.head())
    # print(data['Gender'].unique())
    print(data.columns)
    categorical_columns =data.select_dtypes(include='object').columns
    for column in categorical_columns:
    if column =='Gender':
    data[column] =data[column].map(convert_gender)
    elif column =='Married':
    data[column] = data[column].map(convert_Martial)
    elif column =='Dependents':
    data[column] = data[column].map(convert_dependencies)

    elif column =='Education':
    data[column] = data[column].map(convert_education)
    elif column =='Self_Employed':
    data[column] = data[column].map(self_employeed_status)
    elif column =='Property_Area':
    data[column] = data[column].map(get_Property_Area)
    y =data['Loan_Status']
    X =data.drop('Loan_Status',axis=1)
    X_train,X_test,y_train,y_test =train_test_split(X,y,test_size=0.2,random_state=1)
    model =DecisionTreeClassifier()
    model.fit(X_train,y_train)
    myscore =model.score(X_test,y_test)
    print(myscore)
    Gender = float(convert_gender(request.form['Gender']))
    Married = float(convert_Martial(request.form['Married']))

    Dependents =float(convert_dependencies(request.form['Dependents']))
    Education = float(convert_dependencies(request.form['Education']))
    Self_Employed = float(self_employeed_status(request.form['Self_Employed']))
    ApplicantIncome = float((request.form['ApplicantIncome']))
    CoapplicantIncome = float((request.form['CoapplicantIncome']))
    LoanAmount = float((request.form['LoanAmount']))
    Loan_Amount_Term = float((request.form['Loan_Amount_Term']))
    Credit_History = float((request.form['Credit_History']))
    Property_Area = float(get_Property_Area(request.form['Property_Area']))
    prediction =model.predict([[Gender,Married,Dependents,
    Education,Self_Employed,ApplicantIncome,CoapplicantIncome,
    LoanAmount,Loan_Amount_Term,Credit_History,Credit_History,Property_Area]])

    return render_template('Loan_Status.html',score =prediction)


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


    when i run code, i got this error : [​IMG]

    i know that i am missing a little part, but can't guess exactly what it is, please give me hint

    Continue reading...

Compartilhe esta Página