Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -1,106 +1,89 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
import pandas as pd
|
4 |
import tensorflow as tf
|
5 |
from huggingface_hub import hf_hub_download
|
6 |
from datasets import load_dataset
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
model_path = hf_hub_download(repo_id='neuronetties/bezrabot', filename='bezrabotica.keras')
|
10 |
model = tf.keras.models.load_model(model_path)
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
def
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
with gr.Blocks() as demo:
|
91 |
-
genre_selector = gr.CheckboxGroup(choices=all_genres, label="Выберите жанры")
|
92 |
-
result_output = gr.Textbox(label="Рекомендации")
|
93 |
-
|
94 |
-
with gr.Row():
|
95 |
-
recommend_button = gr.Button("Рекомендовать 10 фильмов")
|
96 |
-
reset_button = gr.Button("Сбросить список")
|
97 |
-
|
98 |
-
recommend_button.click(fn=recommend_movies, inputs=genre_selector, outputs=result_output)
|
99 |
-
reset_button.click(fn=reset_index, outputs=result_output)
|
100 |
-
|
101 |
-
for movie in recommended_movies_list:
|
102 |
-
remove_button = gr.Button(f"Уже смотрел: {movie['names']}")
|
103 |
-
remove_button.click(fn=remove_movie, inputs=[gr.Textbox(value=movie['names'], visible=False)], outputs=result_output)
|
104 |
-
|
105 |
-
# Запуск интерфейса
|
106 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
1 |
import tensorflow as tf
|
2 |
from huggingface_hub import hf_hub_download
|
3 |
from datasets import load_dataset
|
4 |
+
import numpy as np
|
5 |
+
import gradio as gr
|
6 |
+
from sklearn.preprocessing import MinMaxScaler
|
7 |
+
import pandas as pd
|
8 |
|
9 |
+
model_path = hf_hub_download(repo_id='neuronetties/bezrabotica', filename='BEZRAB.keras')
|
|
|
10 |
model = tf.keras.models.load_model(model_path)
|
11 |
|
12 |
+
dataset = load_dataset("Vilyam888/BEZRAB_DATA")
|
13 |
+
data = pd.DataFrame(dataset['train'])
|
14 |
+
|
15 |
+
columns_to_keep = [
|
16 |
+
'territory',
|
17 |
+
'num_economactivepopulation_all',
|
18 |
+
'employed_num_all',
|
19 |
+
'unemployed_num_all',
|
20 |
+
'eactivity_lvl',
|
21 |
+
'employment_lvl',
|
22 |
+
'unemployment_lvl',
|
23 |
+
'dis_unagegroup_30-39',
|
24 |
+
'dis_emagegroup_30-39',
|
25 |
+
'num_unagegroup_30-39',
|
26 |
+
'num_emagegroup_30-39',
|
27 |
+
'year'
|
28 |
+
]
|
29 |
+
data = data[columns_to_keep]
|
30 |
+
data.fillna(data.mean(numeric_only=True), inplace=True)
|
31 |
+
|
32 |
+
def clean_territory(value):
|
33 |
+
if isinstance(value, str) and len(value) > 100:
|
34 |
+
return value[:100]
|
35 |
+
return value
|
36 |
+
|
37 |
+
data['territory'] = data['territory'].apply(clean_territory)
|
38 |
+
data['territory'] = data['territory'].astype(str).str.strip()
|
39 |
+
territory_mapping = {territory: idx for idx, territory in enumerate(data['territory'].unique())}
|
40 |
+
data['territory'] = data['territory'].map(territory_mapping)
|
41 |
+
|
42 |
+
scaler = MinMaxScaler()
|
43 |
+
normalized_data = scaler.fit_transform(data.drop(['year'], axis=1))
|
44 |
+
normalized_df = pd.DataFrame(normalized_data, columns=[col for col in data.columns if col != 'year'])
|
45 |
+
normalized_df['year'] = data['year'].values
|
46 |
+
|
47 |
+
def predict(territory, year, num_economactivepopulation_all, employed_num_all, unemployed_num_all,
|
48 |
+
eactivity_lvl, employment_lvl, dis_unagegroup_30_39, dis_emagegroup_30_39,
|
49 |
+
num_unagegroup_30_39, num_emagegroup_30_39):
|
50 |
+
input_data = pd.DataFrame({
|
51 |
+
'territory': [territory_mapping[territory]],
|
52 |
+
'num_economactivepopulation_all': [num_economactivepopulation_all],
|
53 |
+
'employed_num_all': [employed_num_all],
|
54 |
+
'unemployed_num_all': [unemployed_num_all],
|
55 |
+
'eactivity_lvl': [eactivity_lvl],
|
56 |
+
'employment_lvl': [employment_lvl],
|
57 |
+
'dis_unagegroup_30-39': [dis_unagegroup_30_39],
|
58 |
+
'dis_emagegroup_30-39': [dis_emagegroup_30_39],
|
59 |
+
'num_unagegroup_30-39': [num_unagegroup_30_39],
|
60 |
+
'num_emagegroup_30-39': [num_emagegroup_30_39]
|
61 |
+
})
|
62 |
+
|
63 |
+
input_normalized = scaler.transform(input_data)
|
64 |
+
input_sequence = np.expand_dims(input_normalized, axis=0)
|
65 |
+
|
66 |
+
prediction = model.predict(input_sequence)
|
67 |
+
return round(prediction[0][0], 2)
|
68 |
+
|
69 |
+
interface = gr.Interface(
|
70 |
+
fn=predict,
|
71 |
+
inputs=[
|
72 |
+
gr.Textbox(label="Territory", placeholder="Введите название территории"),
|
73 |
+
gr.Number(label="Year"),
|
74 |
+
gr.Number(label="Economic Active Population"),
|
75 |
+
gr.Number(label="Employed Population"),
|
76 |
+
gr.Number(label="Unemployed Population"),
|
77 |
+
gr.Number(label="Economic Activity Level"),
|
78 |
+
gr.Number(label="Employment Level"),
|
79 |
+
gr.Number(label="Disunemployed Age Group 30-39"),
|
80 |
+
gr.Number(label="Disemployed Age Group 30-39"),
|
81 |
+
gr.Number(label="Unemployed Age Group 30-39"),
|
82 |
+
gr.Number(label="Employed Age Group 30-39")
|
83 |
+
],
|
84 |
+
outputs=gr.Textbox(label="Predicted Value"),
|
85 |
+
title="Unemployment Prediction Model",
|
86 |
+
description="Введите значения для прогноза уровня безработицы."
|
87 |
+
)
|
88 |
+
|
89 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|