본문 바로가기

AI,DL,ML

[20겨울#3]3주차 활동

백준 풀이

- ?

 

3주차_모델 설명(+간단한 코드 설명) or 모두를 위한 딥러닝

진선님, 지원님



오늘 할 일

: 웹서버 구동

+ 저번 수업 하다가 궁금한 거(끝나고 물어봐도 됩니다.)

 

Rest API

2021/01/27 - [백엔드] - REST API#1

 

REST API#1

오늘은 REST API에 대해서 알아보려고 한다. 만약, 회원가입을 한다고 가정할 때, 한국은 GET을 쓰고, 미국은 POST를, 인도는 PATCH를 쓴다고 가정하자. 이렇게 세계별로 다르다면 우리 사용자는 모든

happylulurara.tistory.com

 

작성할 코드

import flask
import pandas as pd
from joblib import dump, load


with open(f'housepriceprediction.joblib', 'rb') as f: #read binary
    model = load(f)


app = flask.Flask(__name__, template_folder='templates') #어디서 시작할 지 알려줌


@app.route('/', methods=['GET', 'POST'])
def main():
    if flask.request.method == 'GET':
        return (flask.render_template('index.html'))

    if flask.request.method == 'POST':
        rooms = flask.request.form['rooms']
        bathroom = flask.request.form['bathroom']
        distance = flask.request.form['distance']
        car = flask.request.form['car']

        input_variables = pd.DataFrame([[rooms, bathroom, distance, car]],
                                       columns=['rooms', 'bathroom',
                                                'distance', 'car'],
                                       dtype='float',
                                       index=['input'])

        predictions = model.predict(input_variables)[0]
        print(predictions)

        return flask.render_template('index.html', original_input={'Rooms': rooms, 'Bathroom': bathroom, 'Distance': distance, 'Car': car}, result=predictions)


if __name__ == '__main__': #main함수, 본격적으로 시작
    app.run(debug=True)

 

flask.render_template()

1. return (flask.render_template('index.html'))
2. return flask.render_template('index.html', 
	original_input=
    	{'Rooms': rooms, 'Bathroom': bathroom, 'Distance': distance,  'Car': car}, 
        result=predictions)

1. Index.html를 렌더링한다

2. index.html에서 input variables의 요소가 original_input으로 들어가고,

result로 prediction의 값이 전달된다

 

 

github.com/h3yon/house_predict

 

h3yon/house_predict

Contribute to h3yon/house_predict development by creating an account on GitHub.

github.com

 


 

다음 소학회까지

 

1. 백준알고리즘 문제 2-3문제

반응형