euproj/euproj_server/server.ipynb
2024-02-19 20:16:33 +01:00

10 KiB
Raw Permalink Blame History

from flask import Flask, request, jsonify
import pandas as pd
import numpy as np
import joblib

df = pd.read_csv('Lista_projektow_FE_2014_2020_020124.csv')
tfidf_vectorizer=joblib.load("vectoriser.sav")
model_fin_warto=joblib.load("model_fin_warto.sav")
model_fin_kwali=joblib.load("model_fin_kwali.sav")
model_fin_dofin=joblib.load("model_fin_dofin.sav")
model_fundusz=joblib.load("model_fundusz.sav")
model_dziedz=joblib.load("model_dziedz.sav")
nn_model =joblib.load("model_nn.sav")

app = Flask(__name__)

@app.route('/pytanie', methods=['POST'])
def obsluga_pytania():
    data = request.get_json()
    pytanie = data.get('pytanie', '')

    if pytanie:
        pytanie_tfidf = tfidf_vectorizer.transform([pytanie])
        projects = nn_model.kneighbors(pytanie_tfidf)[1].flatten()
        return jsonify(
                        Predicted_fin_warto = str(np.round(np.exp(model_fin_warto.predict(pytanie_tfidf)),2)),
                        Predicted_fin_kwali = str(np.round(np.exp(model_fin_kwali.predict(pytanie_tfidf)),2)),
                        Predicted_fin_dofin = str(np.round(np.exp(model_fin_dofin.predict(pytanie_tfidf)),2)),
                        Predicted_fundusz = str(model_fundusz.predict(pytanie_tfidf)),
                        Predicted_dziedzina = str(model_dziedz.predict(pytanie_tfidf)),
                        P1_Project_name = str(df.iloc[projects[0]].iloc[0]),
                        P1_Project_summary = str(df.iloc[projects[0]].iloc[1]),
                        P1_Contract_number = str(df.iloc[projects[0]].iloc[2]),
                        P1_Beneficiary_name = str(df.iloc[projects[0]].iloc[3]),
                        P1_Fund = str(df.iloc[projects[0]].iloc[4]),
                        P1_Programme = str(df.iloc[projects[0]].iloc[5]),
                        P1_Priority_axis = str(df.iloc[projects[0]].iloc[6]),
                        P1_Measure = str(df.iloc[projects[0]].iloc[7]),
                        P1_Submeasure = str(df.iloc[projects[0]].iloc[8]),
                        P1_Total_project_value = str(df.iloc[projects[0]].iloc[9]),
                        P1_Total_eligible_expenditure = str(df.iloc[projects[0]].iloc[10]),
                        P1_Amount_of_EU_co_financing = str(df.iloc[projects[0]].iloc[11]),
                        P1_Union_co_financing_rate = str(df.iloc[projects[0]].iloc[12]),
                        P1_Form_of_finance = str(df.iloc[projects[0]].iloc[13]),
                        P1_Project_location = str(df.iloc[projects[0]].iloc[14]),
                        P1_Territory_type = str(df.iloc[projects[0]].iloc[15]),
                        P1_Project_start_date = str(df.iloc[projects[0]].iloc[16]),
                        P1_Project_end_date = str(df.iloc[projects[0]].iloc[17]),
                        P1_Project_implemented_under_competitive_or_non_competitive_procedure = str(df.iloc[projects[0]].iloc[18]),
                        P1_Area_of_economic_activity = str(df.iloc[projects[0]].iloc[19]),
                        P1_Area_of_project_intervention = str(df.iloc[projects[0]].iloc[20]),
                        P1_Project_thematic_objective = str(df.iloc[projects[0]].iloc[21]),
                        P1_ESF_secondary_theme = str(df.iloc[projects[0]].iloc[22]),
                        P1_Project_implemented_under_territorial_delivery_mechanisms = str(df.iloc[projects[0]].iloc[23]),
                        P1_Funding_completed = str(df.iloc[projects[0]].iloc[24]),
                        P2_Project_name = str(df.iloc[projects[1]].iloc[0]),
                        P2_Project_summary = str(df.iloc[projects[1]].iloc[1]),
                        P2_Contract_number = str(df.iloc[projects[1]].iloc[2]),
                        P2_Beneficiary_name = str(df.iloc[projects[1]].iloc[3]),
                        P2_Fund = str(df.iloc[projects[1]].iloc[4]),
                        P2_Programme = str(df.iloc[projects[1]].iloc[5]),
                        P2_Priority_axis = str(df.iloc[projects[1]].iloc[6]),
                        P2_Measure = str(df.iloc[projects[1]].iloc[7]),
                        P2_Submeasure = str(df.iloc[projects[1]].iloc[8]),
                        P2_Total_project_value = str(df.iloc[projects[1]].iloc[9]),
                        P2_Total_eligible_expenditure = str(df.iloc[projects[1]].iloc[10]),
                        P2_Amount_of_EU_co_financing = str(df.iloc[projects[1]].iloc[11]),
                        P2_Union_co_financing_rate = str(df.iloc[projects[1]].iloc[12]),
                        P2_Form_of_finance = str(df.iloc[projects[1]].iloc[13]),
                        P2_Project_location = str(df.iloc[projects[1]].iloc[14]),
                        P2_Territory_type = str(df.iloc[projects[1]].iloc[15]),
                        P2_Project_start_date = str(df.iloc[projects[1]].iloc[16]),
                        P2_Project_end_date = str(df.iloc[projects[1]].iloc[17]),
                        P2_Project_implemented_under_competitive_or_non_competitive_procedure = str(df.iloc[projects[1]].iloc[18]),
                        P2_Area_of_economic_activity = str(df.iloc[projects[1]].iloc[19]),
                        P2_Area_of_project_intervention = str(df.iloc[projects[1]].iloc[20]),
                        P2_Project_thematic_objective = str(df.iloc[projects[1]].iloc[21]),
                        P2_ESF_secondary_theme = str(df.iloc[projects[1]].iloc[22]),
                        P2_Project_implemented_under_territorial_delivery_mechanisms = str(df.iloc[projects[1]].iloc[23]),
                        P2_Funding_completed = str(df.iloc[projects[1]].iloc[24]),
                        P3_Project_name = str(df.iloc[projects[2]].iloc[0]),
                        P3_Project_summary = str(df.iloc[projects[2]].iloc[1]),
                        P3_Contract_number = str(df.iloc[projects[2]].iloc[2]),
                        P3_Beneficiary_name = str(df.iloc[projects[2]].iloc[3]),
                        P3_Fund = str(df.iloc[projects[2]].iloc[4]),
                        P3_Programme = str(df.iloc[projects[2]].iloc[5]),
                        P3_Priority_axis = str(df.iloc[projects[2]].iloc[6]),
                        P3_Measure = str(df.iloc[projects[2]].iloc[7]),
                        P3_Submeasure = str(df.iloc[projects[2]].iloc[8]),
                        P3_Total_project_value = str(df.iloc[projects[2]].iloc[9]),
                        P3_Total_eligible_expenditure = str(df.iloc[projects[2]].iloc[10]),
                        P3_Amount_of_EU_co_financing = str(df.iloc[projects[2]].iloc[11]),
                        P3_Union_co_financing_rate = str(df.iloc[projects[2]].iloc[12]),
                        P3_Form_of_finance = str(df.iloc[projects[2]].iloc[13]),
                        P3_Project_location = str(df.iloc[projects[2]].iloc[14]),
                        P3_Territory_type = str(df.iloc[projects[2]].iloc[15]),
                        P3_Project_start_date = str(df.iloc[projects[2]].iloc[16]),
                        P3_Project_end_date = str(df.iloc[projects[2]].iloc[17]),
                        P3_Project_implemented_under_competitive_or_non_competitive_procedure = str(df.iloc[projects[2]].iloc[18]),
                        P3_Area_of_economic_activity = str(df.iloc[projects[2]].iloc[19]),
                        P3_Area_of_project_intervention = str(df.iloc[projects[2]].iloc[20]),
                        P3_Project_thematic_objective = str(df.iloc[projects[2]].iloc[21]),
                        P3_ESF_secondary_theme = str(df.iloc[projects[2]].iloc[22]),
                        P3_Project_implemented_under_territorial_delivery_mechanisms = str(df.iloc[projects[2]].iloc[23]),
                        P3_Funding_completed = str(df.iloc[projects[2]].iloc[24])
                     )
    else:
        return jsonify({'error': 'Brak pytania'}), 400

if __name__ == '__main__':
    app.run(debug=False, port=5001)
 * Serving Flask app '__main__'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5001
Press CTRL+C to quit
127.0.0.1 - - [19/Feb/2024 19:27:12] "POST /pytanie HTTP/1.1" 200 -
127.0.0.1 - - [19/Feb/2024 19:27:13] "POST /pytanie HTTP/1.1" 200 -
127.0.0.1 - - [19/Feb/2024 19:27:13] "POST /pytanie HTTP/1.1" 200 -
df.info()