flask创建前端
Signed-off-by: hsiatein <12955678+hsiatein@user.noreply.gitee.com>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/flask预测.iml" filepath="$PROJECT_DIR$/.idea/flask预测.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="24e3af27-9945-41d5-8675-b5bd58345323" name="更改" comment="" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="ProjectId" id="2SbMGtT9gi7gRIfUIXBzr4CPIbz" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="RunManager">
|
||||
<configuration name="app" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||
<module name="flask预测" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="IS_MODULE_SDK" value="true" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/app.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Python.app" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="应用程序级" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="默认任务">
|
||||
<changelist id="24e3af27-9945-41d5-8675-b5bd58345323" name="更改" comment="" />
|
||||
<created>1689410735641</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1689410735641</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,57 @@
|
||||
from flask import Flask, render_template, request
|
||||
import pandas
|
||||
import joblib
|
||||
|
||||
#导入模型
|
||||
model1=joblib.load('BaggingReg1.pkl')
|
||||
model2=joblib.load('BaggingReg2.pkl')
|
||||
model3=joblib.load('AdaBoostReg1.pkl')
|
||||
model4=joblib.load('AdaBoostReg2.pkl')
|
||||
|
||||
def model1_pre(edu,jobage,worktime):
|
||||
temp = {'education_toint': [edu], 'jobage': [jobage], 'worktime_weekly': [worktime]}
|
||||
df = pandas.DataFrame(temp)
|
||||
return model1.predict(df)[0]
|
||||
def model2_pre(edu,jobage):
|
||||
temp = {'education_toint': [edu], 'jobage': [jobage]}
|
||||
df = pandas.DataFrame(temp)
|
||||
return model2.predict(df)[0]
|
||||
def model3_pre(edu,jobage,worktime):
|
||||
temp = {'education_toint': [edu], 'jobage': [jobage], 'worktime_weekly': [worktime]}
|
||||
df = pandas.DataFrame(temp)
|
||||
return model3.predict(df)[0]
|
||||
def model4_pre(edu,jobage):
|
||||
temp = {'education_toint': [edu], 'jobage': [jobage]}
|
||||
df = pandas.DataFrame(temp)
|
||||
return model4.predict(df)[0]
|
||||
|
||||
xueli=['小学', '初中', '中专', '高中', '大专', '本科', '硕士', '博士']
|
||||
|
||||
app = Flask(__name__)
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def index():
|
||||
if request.method == 'POST':
|
||||
text1 = request.form['text1']
|
||||
text2 = request.form['text2']
|
||||
option = request.form['option']
|
||||
#将用户选择的学历与数字匹配
|
||||
xuelishu=0
|
||||
for i in range(8):
|
||||
if(option==xueli[i]):
|
||||
xuelishu=i
|
||||
break
|
||||
else:
|
||||
i+=1
|
||||
|
||||
# 预测薪资
|
||||
xinzi1=model1_pre(xuelishu,int(text1),int(text2))
|
||||
xinzi2=model2_pre(xuelishu,int(text1))
|
||||
xinzi3=model3_pre(xuelishu,int(text1),int(text2))
|
||||
xinzi4=model4_pre(xuelishu,int(text1))
|
||||
avg=(xinzi1+xinzi2+xinzi3+xinzi4)/4
|
||||
return f'你的工作经验是:{text1}年,你的学历是:{option},你能接受的每周工作时长为:{text2}小时<br><br>模型1:你的预计薪资为:{xinzi1}元<br><br>模型2:你的预计薪资为:{xinzi2}元<br><br>模型3:你的预计薪资为:{xinzi3}元<br><br>模型4:你的预计薪资为:{xinzi4}元<br><br>你的平均预计薪资为:{avg}元'
|
||||
return render_template('index.html')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(port=8002)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Flask Web App</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>人才招聘数据分析可视化及薪资预测模型</h1>
|
||||
<form method="POST" action="/">
|
||||
|
||||
<label for="option">你的学历:</label>
|
||||
<input type="radio" id="option1" name="option" value="小学" required>
|
||||
<label for="option1">小学</label>
|
||||
<input type="radio" id="option2" name="option" value="初中" required>
|
||||
<label for="option2">初中</label>
|
||||
<input type="radio" id="option3" name="option" value="中专" required>
|
||||
<label for="option3">中专</label>
|
||||
<input type="radio" id="option4" name="option" value="高中" required>
|
||||
<label for="option4">高中</label>
|
||||
<input type="radio" id="option5" name="option" value="大专" required>
|
||||
<label for="option5">大专</label>
|
||||
<input type="radio" id="option6" name="option" value="本科" required>
|
||||
<label for="option6">本科</label>
|
||||
<input type="radio" id="option7" name="option" value="硕士" required>
|
||||
<label for="option7">硕士</label>
|
||||
<input type="radio" id="option8" name="option" value="博士" required>
|
||||
<label for="option8">博士</label><br><br>
|
||||
|
||||
<label for="text">参加工作年份:</label>
|
||||
<input type="text" id="text1" name="text1" required><br><br>
|
||||
|
||||
<label for="text">工作时间:</label>
|
||||
<input type="text" id="text2" name="text2" required><br><br>
|
||||
|
||||
<input type="submit" value="提交">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user