fschwartzer commited on
Commit
f573577
1 Parent(s): 375ee24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -12,7 +12,7 @@ def calculate_distance(lat1, lon1, lat2, lon2):
12
  coords_2 = (lat2, lon2)
13
  return geodesic(coords_1, coords_2).meters
14
 
15
- # Function to apply KNN and return Vunit values
16
  def knn_predict(df, target_column, features_columns, k=5):
17
  # Separate features and target variable
18
  X = df[features_columns]
@@ -24,7 +24,7 @@ def knn_predict(df, target_column, features_columns, k=5):
24
  # Fit the model
25
  knn.fit(X, y)
26
 
27
- # Use the model to predict Vunit for the filtered_data
28
  predictions = knn.predict(df[features_columns])
29
 
30
  return predictions
@@ -56,8 +56,9 @@ st.markdown(
56
  unsafe_allow_html=True
57
  )
58
 
 
59
  # Create a DataFrame with sample data
60
- data = pd.read_excel('ven_ter_fim_PEDÓ.xlsx')
61
 
62
  # Initialize variables to avoid NameError
63
  selected_coords = 'Direcionada'
@@ -80,7 +81,7 @@ zoom_level = round(17 - np.log10(max_distance))
80
 
81
  # Set font to 'Quicksand' for title_html
82
  title_html = """
83
- <style>
84
  @font-face {font-family: 'Quicksand';
85
  src: url('font/Quicksand-VariableFont_wght.ttf') format('truetype');
86
  }
@@ -91,7 +92,7 @@ title_html = """
91
  <span style='color: gray; font-size: 50px;'>aval</span>
92
  <span style='color: white; font-size: 50px;'>ia</span>
93
  <span style='color: gray; font-size: 50px;'>.NEXUS</span>
94
- """
95
 
96
  # Set font to 'Quicksand' for factor_html
97
  factor_html = """
@@ -131,6 +132,9 @@ with st.sidebar:
131
  #st.title('avalia.se')
132
 
133
  st.sidebar.markdown(title_html, unsafe_allow_html=True)
 
 
 
134
 
135
  selected_coords = st.selectbox('Selecione o tipo de pesquisa', ['Ampla', 'Direcionada'])
136
 
@@ -193,10 +197,10 @@ st.markdown(f"""<style>
193
 
194
  # Check if KNN should be applied
195
  if selected_coords == 'Direcionada' and radius_visible:
196
- # Apply KNN and get predicted Vunit values
197
- predicted_vunit = knn_predict(filtered_data, 'Vunit', ['latitude', 'longitude', 'Area']) # Update with your features
198
- # Add predicted Vunit values to filtered_data
199
- filtered_data['Predicted_Vunit'] = predicted_vunit
200
 
201
  # Display the map and filtered_data
202
  with st.container():
@@ -205,7 +209,7 @@ with st.container():
205
  elif selected_coords == 'Ampla':
206
  st.map(data, zoom=zoom_level, use_container_width=True)
207
 
208
- # Display the predicted Vunit values if applicable
209
- if 'Predicted_Vunit' in filtered_data.columns:
210
  st.write("Valores (R$/m²) previstos com algoritmo KNN:")
211
- st.write(filtered_data[['latitude', 'longitude', 'Vunit', 'Predicted_Vunit']])
 
12
  coords_2 = (lat2, lon2)
13
  return geodesic(coords_1, coords_2).meters
14
 
15
+ # Function to apply KNN and return V_oferta values
16
  def knn_predict(df, target_column, features_columns, k=5):
17
  # Separate features and target variable
18
  X = df[features_columns]
 
24
  # Fit the model
25
  knn.fit(X, y)
26
 
27
+ # Use the model to predict V_oferta for the filtered_data
28
  predictions = knn.predict(df[features_columns])
29
 
30
  return predictions
 
56
  unsafe_allow_html=True
57
  )
58
 
59
+
60
  # Create a DataFrame with sample data
61
+ data = pd.read_excel('ven_fim_PEDÓ_nov_23.xlsx)
62
 
63
  # Initialize variables to avoid NameError
64
  selected_coords = 'Direcionada'
 
81
 
82
  # Set font to 'Quicksand' for title_html
83
  title_html = """
84
+ <style>
85
  @font-face {font-family: 'Quicksand';
86
  src: url('font/Quicksand-VariableFont_wght.ttf') format('truetype');
87
  }
 
92
  <span style='color: gray; font-size: 50px;'>aval</span>
93
  <span style='color: white; font-size: 50px;'>ia</span>
94
  <span style='color: gray; font-size: 50px;'>.NEXUS</span>
95
+ """
96
 
97
  # Set font to 'Quicksand' for factor_html
98
  factor_html = """
 
132
  #st.title('avalia.se')
133
 
134
  st.sidebar.markdown(title_html, unsafe_allow_html=True)
135
+
136
+ # Add a dropdown for filtering "Tipo"
137
+ selected_tipo = st.selectbox('Filtrar por Tipo', data['Tipo'].unique())
138
 
139
  selected_coords = st.selectbox('Selecione o tipo de pesquisa', ['Ampla', 'Direcionada'])
140
 
 
197
 
198
  # Check if KNN should be applied
199
  if selected_coords == 'Direcionada' and radius_visible:
200
+ # Apply KNN and get predicted V_oferta values
201
+ predicted_V_oferta = knn_predict(filtered_data, 'V_oferta', ['latitude', 'longitude', 'Area']) # Update with your features
202
+ # Add predicted V_oferta values to filtered_data
203
+ filtered_data['Predicted_V_oferta'] = predicted_V_oferta
204
 
205
  # Display the map and filtered_data
206
  with st.container():
 
209
  elif selected_coords == 'Ampla':
210
  st.map(data, zoom=zoom_level, use_container_width=True)
211
 
212
+ # Display the predicted V_oferta values if applicable
213
+ if 'Predicted_V_oferta' in filtered_data.columns:
214
  st.write("Valores (R$/m²) previstos com algoritmo KNN:")
215
+ st.write(filtered_data[['latitude', 'longitude', 'V_oferta', 'Predicted_V_oferta']])