|
- from flask import Flask, render_template, jsonify, abort,request
- import pandas as pd
- from flask_cors import CORS # 引入 CORS
-
- import calculate.cal
- from calculate import cal
-
-
- app = Flask(__name__)
- CORS(app) # 启用 CORS,允许所有来源的请求
-
- @app.route('/')
- def main():
- return render_template('main.html')
-
- @app.route('/accurate')
- def accurate():
- try:
- columns = ['Model', 'AV', 'AC', 'PR', 'UI', 'S', 'C', 'I', 'A']
- df = pd.read_csv('calculate/accurate.csv', header=None, names=columns)
-
- # 原始雷达图配置
- indicators = [{'name': col, 'max': df[col].max() * 1.1} for col in df.columns if col != 'Model']
- series_data = []
- for index, row in df.iterrows():
- series_data.append({
- 'value': [row[col] for col in df.columns if col != 'Model'],
- 'name': row['Model']
- })
- option = {
- 'title': {
- 'text': '',
- 'left': 'center'
- },
- 'legend': {
- 'data': df['Model'].tolist()
- },
- 'radar': {
- 'indicator': indicators
- },
- 'series': [
- {
- 'name': 'Model Performance',
- 'type': 'radar',
- 'areaStyle': {},
- 'data': series_data,
- 'animation': True,
- 'animationDuration': 1000
- }
- ]
- }
-
- # 前四个指标雷达图配置
- indicators_ex = [{'name': col, 'max': df[col].max() * 1.1} for col in df.columns[1:5]]
- series_data_ex = []
- for index, row in df.iterrows():
- series_data_ex.append({
- 'value': [row[col] for col in df.columns[1:5]],
- 'name': row['Model']
- })
- option_ex = {
- 'title': {
- 'text': '',
- 'left': 'center'
- },
- 'legend': {
- 'data': df['Model'].tolist()
- },
- 'radar': {
- 'indicator': indicators_ex
- },
- 'series': [
- {
- 'name': 'Model Performance (ex)',
- 'type': 'radar',
- 'areaStyle': {},
- 'data': series_data_ex,
- 'animation': True,
- 'animationDuration': 1000
- }
- ]
- }
-
- # 后四个指标雷达图配置
- indicators_im = [{'name': col, 'max': df[col].max() * 1.1} for col in df.columns[5:]]
- series_data_im = []
- for index, row in df.iterrows():
- series_data_im.append({
- 'value': [row[col] for col in df.columns[5:]],
- 'name': row['Model']
- })
- option_im = {
- 'title': {
- 'text': '',
- 'left': 'center'
- },
- 'legend': {
- 'data': df['Model'].tolist()
- },
- 'radar': {
- 'indicator': indicators_im
- },
- 'series': [
- {
- 'name': 'Model Performance (im)',
- 'type': 'radar',
- 'areaStyle': {},
- 'data': series_data_im,
- 'animation': True,
- 'animationDuration': 1000
- }
- ]
- }
-
- table_data = df.to_dict(orient='records')
- table_columns = df.columns.tolist()
- return render_template('accurate.html', option=option, option_ex=option_ex, option_im=option_im,
- table_data=table_data, table_columns=table_columns)
- except FileNotFoundError:
- abort(404, description="accurate.csv file not found.")
-
- @app.route('/basemse')
- def basemse():
- return render_template('basemse.html')
-
- @app.route('/exploitabilitymse')
- def exploitabilitymse():
- return render_template('exploitabilitymse.html')
-
- @app.route('/impactmse')
- def impactmse():
- return render_template('impactmse.html')
-
- @app.route('/distrobution')
- def distrobution():
- return render_template('distrobution.html')
-
- @app.route('/bert')
- def bert():
- return render_template('bert.html')
-
- @app.route('/compute', methods=['GET', 'POST'])
- def compute():
- if request.method == 'POST':
- text = request.form.get('text')
- print(text)
- value1 = calculate.cal.calbasescore('N', 'L', 'N', 'R', 'U', 'N', 'N', 'H', 'CVSS:3.0') #6.5
- value2 = calculate.cal.calexploitabilityscore('N', 'L', 'N', 'R') # 2.8
- value3 = calculate.cal.calimpactscore('U', 'N', 'N', 'H') # 2.8
- return jsonify({
- 'value1': value1,
- 'value2': value2,
- 'value3': value3
- })
- return render_template('compute.html')
-
- if __name__ == '__main__':
- app.run(debug=True)
|