Vilyam888 commited on
Commit
1c18b6b
·
verified ·
1 Parent(s): 4be2bb0

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -40
app.py CHANGED
@@ -51,52 +51,41 @@ normalized_df = pd.DataFrame(normalized_data, columns=[col for col in data.colum
51
  normalized_df['year'] = data['year'].values
52
 
53
  # Функция предсказания
54
- def predict(territory, year, num_economactivepopulation_all, employed_num_all, unemployed_num_all,
55
- eactivity_lvl, employment_lvl, dis_unagegroup_30_39, dis_emagegroup_30_39,
56
- num_unagegroup_30_39, num_emagegroup_30_39):
57
  if territory not in territory_mapping:
58
- return "Invalid territory name. Please choose a valid one."
59
-
60
- input_data = pd.DataFrame({
61
- 'territory': [territory_mapping[territory]],
62
- 'num_economactivepopulation_all': [num_economactivepopulation_all],
63
- 'employed_num_all': [employed_num_all],
64
- 'unemployed_num_all': [unemployed_num_all],
65
- 'eactivity_lvl': [eactivity_lvl],
66
- 'employment_lvl': [employment_lvl],
67
- 'dis_unagegroup_30-39': [dis_unagegroup_30_39],
68
- 'dis_emagegroup_30-39': [dis_emagegroup_30_39],
69
- 'num_unagegroup_30-39': [num_unagegroup_30_39],
70
- 'num_emagegroup_30-39': [num_emagegroup_30_39]
71
- })
72
-
73
- # Нормализация входных данных
74
- input_normalized = scaler.transform(input_data)
75
- input_sequence = np.expand_dims(input_normalized, axis=0)
76
-
77
- # Прогноз
78
- prediction = model.predict(input_sequence)
79
- return round(prediction[0][0], 2)
80
 
81
  # Интерфейс Gradio
82
  interface = gr.Interface(
83
- fn=predict,
84
  inputs=[
85
- gr.Dropdown(label="Territory", choices=list(territory_mapping.keys())),
86
- gr.Number(label="Year"),
87
- gr.Number(label="Economic Active Population"),
88
- gr.Number(label="Employed Population"),
89
- gr.Number(label="Unemployed Population"),
90
- gr.Number(label="Economic Activity Level"),
91
- gr.Number(label="Employment Level"),
92
- gr.Number(label="Disunemployed Age Group 30-39"),
93
- gr.Number(label="Disemployed Age Group 30-39"),
94
- gr.Number(label="Unemployed Age Group 30-39"),
95
- gr.Number(label="Employed Age Group 30-39")
96
  ],
97
- outputs=gr.Textbox(label="Predicted Value"),
98
- title="Unemployment Prediction Model",
99
- description="Введите значения для прогноза уровня безработицы."
100
  )
101
 
102
  interface.launch()
 
51
  normalized_df['year'] = data['year'].values
52
 
53
  # Функция предсказания
54
+
55
+ def predict_unemployment(territory):
 
56
  if territory not in territory_mapping:
57
+ return "Неверное название территории. Пожалуйста, выберите из списка."
58
+
59
+ predictions = []
60
+ current_year = data['year'].max() + 1
61
+
62
+ for i in range(5):
63
+ sample_row = data[data['territory'] == territory_mapping[territory]].iloc[-1].copy()
64
+ sample_row['year'] = current_year
65
+ input_data = sample_row.drop('year').values.reshape(1, -1)
66
+
67
+ # Нормализация входных данных
68
+ input_normalized = scaler.transform(input_data)
69
+ input_sequence = np.expand_dims(input_normalized, axis=0)
70
+
71
+ # Прогноз
72
+ prediction = model.predict(input_sequence)
73
+ predictions.append((current_year, round(prediction[0][0] * 100, 2)))
74
+
75
+ # Обновление года
76
+ current_year += 1
77
+
78
+ return "\n".join([f"{year}: {value}%" for year, value in predictions])
79
 
80
  # Интерфейс Gradio
81
  interface = gr.Interface(
82
+ fn=predict_unemployment,
83
  inputs=[
84
+ gr.Dropdown(label="Территория", choices=list(territory_mapping.keys()))
 
 
 
 
 
 
 
 
 
 
85
  ],
86
+ outputs=gr.Textbox(label="Прогноз на ближайшие 5 лет"),
87
+ title="Модель прогнозирования уровня безработицы",
88
+ description="Выберите территорию для прогноза уровня безработицы на ближайшие 5 лет."
89
  )
90
 
91
  interface.launch()