177 lines
10 KiB
Plaintext
177 lines
10 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "2f54e447-af06-4046-85b9-b340b8c855b3",
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
" * Serving Flask app '__main__'\n",
|
||
|
" * Debug mode: off\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"\u001b[31m\u001b[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.\u001b[0m\n",
|
||
|
" * Running on http://127.0.0.1:5001\n",
|
||
|
"\u001b[33mPress CTRL+C to quit\u001b[0m\n",
|
||
|
"127.0.0.1 - - [19/Feb/2024 19:27:12] \"POST /pytanie HTTP/1.1\" 200 -\n",
|
||
|
"127.0.0.1 - - [19/Feb/2024 19:27:13] \"POST /pytanie HTTP/1.1\" 200 -\n",
|
||
|
"127.0.0.1 - - [19/Feb/2024 19:27:13] \"POST /pytanie HTTP/1.1\" 200 -\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"from flask import Flask, request, jsonify\n",
|
||
|
"import pandas as pd\n",
|
||
|
"import numpy as np\n",
|
||
|
"import joblib\n",
|
||
|
"\n",
|
||
|
"df = pd.read_csv('Lista_projektow_FE_2014_2020_020124.csv')\n",
|
||
|
"tfidf_vectorizer=joblib.load(\"vectoriser.sav\")\n",
|
||
|
"model_fin_warto=joblib.load(\"model_fin_warto.sav\")\n",
|
||
|
"model_fin_kwali=joblib.load(\"model_fin_kwali.sav\")\n",
|
||
|
"model_fin_dofin=joblib.load(\"model_fin_dofin.sav\")\n",
|
||
|
"model_fundusz=joblib.load(\"model_fundusz.sav\")\n",
|
||
|
"model_dziedz=joblib.load(\"model_dziedz.sav\")\n",
|
||
|
"nn_model =joblib.load(\"model_nn.sav\")\n",
|
||
|
"\n",
|
||
|
"app = Flask(__name__)\n",
|
||
|
"\n",
|
||
|
"@app.route('/pytanie', methods=['POST'])\n",
|
||
|
"def obsluga_pytania():\n",
|
||
|
" data = request.get_json()\n",
|
||
|
" pytanie = data.get('pytanie', '')\n",
|
||
|
"\n",
|
||
|
" if pytanie:\n",
|
||
|
" pytanie_tfidf = tfidf_vectorizer.transform([pytanie])\n",
|
||
|
" projects = nn_model.kneighbors(pytanie_tfidf)[1].flatten()\n",
|
||
|
" return jsonify(\n",
|
||
|
" Predicted_fin_warto = str(np.round(np.exp(model_fin_warto.predict(pytanie_tfidf)),2)),\n",
|
||
|
" Predicted_fin_kwali = str(np.round(np.exp(model_fin_kwali.predict(pytanie_tfidf)),2)),\n",
|
||
|
" Predicted_fin_dofin = str(np.round(np.exp(model_fin_dofin.predict(pytanie_tfidf)),2)),\n",
|
||
|
" Predicted_fundusz = str(model_fundusz.predict(pytanie_tfidf)),\n",
|
||
|
" Predicted_dziedzina = str(model_dziedz.predict(pytanie_tfidf)),\n",
|
||
|
" P1_Project_name = str(df.iloc[projects[0]].iloc[0]),\n",
|
||
|
" P1_Project_summary = str(df.iloc[projects[0]].iloc[1]),\n",
|
||
|
" P1_Contract_number = str(df.iloc[projects[0]].iloc[2]),\n",
|
||
|
" P1_Beneficiary_name = str(df.iloc[projects[0]].iloc[3]),\n",
|
||
|
" P1_Fund = str(df.iloc[projects[0]].iloc[4]),\n",
|
||
|
" P1_Programme = str(df.iloc[projects[0]].iloc[5]),\n",
|
||
|
" P1_Priority_axis = str(df.iloc[projects[0]].iloc[6]),\n",
|
||
|
" P1_Measure = str(df.iloc[projects[0]].iloc[7]),\n",
|
||
|
" P1_Submeasure = str(df.iloc[projects[0]].iloc[8]),\n",
|
||
|
" P1_Total_project_value = str(df.iloc[projects[0]].iloc[9]),\n",
|
||
|
" P1_Total_eligible_expenditure = str(df.iloc[projects[0]].iloc[10]),\n",
|
||
|
" P1_Amount_of_EU_co_financing = str(df.iloc[projects[0]].iloc[11]),\n",
|
||
|
" P1_Union_co_financing_rate = str(df.iloc[projects[0]].iloc[12]),\n",
|
||
|
" P1_Form_of_finance = str(df.iloc[projects[0]].iloc[13]),\n",
|
||
|
" P1_Project_location = str(df.iloc[projects[0]].iloc[14]),\n",
|
||
|
" P1_Territory_type = str(df.iloc[projects[0]].iloc[15]),\n",
|
||
|
" P1_Project_start_date = str(df.iloc[projects[0]].iloc[16]),\n",
|
||
|
" P1_Project_end_date = str(df.iloc[projects[0]].iloc[17]),\n",
|
||
|
" P1_Project_implemented_under_competitive_or_non_competitive_procedure = str(df.iloc[projects[0]].iloc[18]),\n",
|
||
|
" P1_Area_of_economic_activity = str(df.iloc[projects[0]].iloc[19]),\n",
|
||
|
" P1_Area_of_project_intervention = str(df.iloc[projects[0]].iloc[20]),\n",
|
||
|
" P1_Project_thematic_objective = str(df.iloc[projects[0]].iloc[21]),\n",
|
||
|
" P1_ESF_secondary_theme = str(df.iloc[projects[0]].iloc[22]),\n",
|
||
|
" P1_Project_implemented_under_territorial_delivery_mechanisms = str(df.iloc[projects[0]].iloc[23]),\n",
|
||
|
" P1_Funding_completed = str(df.iloc[projects[0]].iloc[24]),\n",
|
||
|
" P2_Project_name = str(df.iloc[projects[1]].iloc[0]),\n",
|
||
|
" P2_Project_summary = str(df.iloc[projects[1]].iloc[1]),\n",
|
||
|
" P2_Contract_number = str(df.iloc[projects[1]].iloc[2]),\n",
|
||
|
" P2_Beneficiary_name = str(df.iloc[projects[1]].iloc[3]),\n",
|
||
|
" P2_Fund = str(df.iloc[projects[1]].iloc[4]),\n",
|
||
|
" P2_Programme = str(df.iloc[projects[1]].iloc[5]),\n",
|
||
|
" P2_Priority_axis = str(df.iloc[projects[1]].iloc[6]),\n",
|
||
|
" P2_Measure = str(df.iloc[projects[1]].iloc[7]),\n",
|
||
|
" P2_Submeasure = str(df.iloc[projects[1]].iloc[8]),\n",
|
||
|
" P2_Total_project_value = str(df.iloc[projects[1]].iloc[9]),\n",
|
||
|
" P2_Total_eligible_expenditure = str(df.iloc[projects[1]].iloc[10]),\n",
|
||
|
" P2_Amount_of_EU_co_financing = str(df.iloc[projects[1]].iloc[11]),\n",
|
||
|
" P2_Union_co_financing_rate = str(df.iloc[projects[1]].iloc[12]),\n",
|
||
|
" P2_Form_of_finance = str(df.iloc[projects[1]].iloc[13]),\n",
|
||
|
" P2_Project_location = str(df.iloc[projects[1]].iloc[14]),\n",
|
||
|
" P2_Territory_type = str(df.iloc[projects[1]].iloc[15]),\n",
|
||
|
" P2_Project_start_date = str(df.iloc[projects[1]].iloc[16]),\n",
|
||
|
" P2_Project_end_date = str(df.iloc[projects[1]].iloc[17]),\n",
|
||
|
" P2_Project_implemented_under_competitive_or_non_competitive_procedure = str(df.iloc[projects[1]].iloc[18]),\n",
|
||
|
" P2_Area_of_economic_activity = str(df.iloc[projects[1]].iloc[19]),\n",
|
||
|
" P2_Area_of_project_intervention = str(df.iloc[projects[1]].iloc[20]),\n",
|
||
|
" P2_Project_thematic_objective = str(df.iloc[projects[1]].iloc[21]),\n",
|
||
|
" P2_ESF_secondary_theme = str(df.iloc[projects[1]].iloc[22]),\n",
|
||
|
" P2_Project_implemented_under_territorial_delivery_mechanisms = str(df.iloc[projects[1]].iloc[23]),\n",
|
||
|
" P2_Funding_completed = str(df.iloc[projects[1]].iloc[24]),\n",
|
||
|
" P3_Project_name = str(df.iloc[projects[2]].iloc[0]),\n",
|
||
|
" P3_Project_summary = str(df.iloc[projects[2]].iloc[1]),\n",
|
||
|
" P3_Contract_number = str(df.iloc[projects[2]].iloc[2]),\n",
|
||
|
" P3_Beneficiary_name = str(df.iloc[projects[2]].iloc[3]),\n",
|
||
|
" P3_Fund = str(df.iloc[projects[2]].iloc[4]),\n",
|
||
|
" P3_Programme = str(df.iloc[projects[2]].iloc[5]),\n",
|
||
|
" P3_Priority_axis = str(df.iloc[projects[2]].iloc[6]),\n",
|
||
|
" P3_Measure = str(df.iloc[projects[2]].iloc[7]),\n",
|
||
|
" P3_Submeasure = str(df.iloc[projects[2]].iloc[8]),\n",
|
||
|
" P3_Total_project_value = str(df.iloc[projects[2]].iloc[9]),\n",
|
||
|
" P3_Total_eligible_expenditure = str(df.iloc[projects[2]].iloc[10]),\n",
|
||
|
" P3_Amount_of_EU_co_financing = str(df.iloc[projects[2]].iloc[11]),\n",
|
||
|
" P3_Union_co_financing_rate = str(df.iloc[projects[2]].iloc[12]),\n",
|
||
|
" P3_Form_of_finance = str(df.iloc[projects[2]].iloc[13]),\n",
|
||
|
" P3_Project_location = str(df.iloc[projects[2]].iloc[14]),\n",
|
||
|
" P3_Territory_type = str(df.iloc[projects[2]].iloc[15]),\n",
|
||
|
" P3_Project_start_date = str(df.iloc[projects[2]].iloc[16]),\n",
|
||
|
" P3_Project_end_date = str(df.iloc[projects[2]].iloc[17]),\n",
|
||
|
" P3_Project_implemented_under_competitive_or_non_competitive_procedure = str(df.iloc[projects[2]].iloc[18]),\n",
|
||
|
" P3_Area_of_economic_activity = str(df.iloc[projects[2]].iloc[19]),\n",
|
||
|
" P3_Area_of_project_intervention = str(df.iloc[projects[2]].iloc[20]),\n",
|
||
|
" P3_Project_thematic_objective = str(df.iloc[projects[2]].iloc[21]),\n",
|
||
|
" P3_ESF_secondary_theme = str(df.iloc[projects[2]].iloc[22]),\n",
|
||
|
" P3_Project_implemented_under_territorial_delivery_mechanisms = str(df.iloc[projects[2]].iloc[23]),\n",
|
||
|
" P3_Funding_completed = str(df.iloc[projects[2]].iloc[24])\n",
|
||
|
" )\n",
|
||
|
" else:\n",
|
||
|
" return jsonify({'error': 'Brak pytania'}), 400\n",
|
||
|
"\n",
|
||
|
"if __name__ == '__main__':\n",
|
||
|
" app.run(debug=False, port=5001)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"id": "1e33ccee-21cd-4e47-bf26-d324d777fc81",
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"df.info()"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3 (ipykernel)",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.11.7"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 5
|
||
|
}
|