annikwag commited on
Commit
ddf3e12
·
verified ·
1 Parent(s): 7cb3d61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -3
app.py CHANGED
@@ -72,6 +72,14 @@ def lookup_crs_value(crs_key):
72
  ###########################################
73
  # RAG Answer function (Change 1 & 2 & 3)
74
  ###########################################
 
 
 
 
 
 
 
 
75
  def get_rag_answer(query, top_results):
76
  # Build context from each top result using title, objectives, and description.
77
  context = "\n\n".join([build_context_for_result(res) for res in top_results])
@@ -119,6 +127,20 @@ def get_crs_options(_client, collection_name):
119
  crs_set.add(crs_combined)
120
  return sorted(crs_set)
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  ###########################################
123
  # Revised filter_results with budget filtering (Change 7 & 9)
124
  ###########################################
@@ -204,8 +226,8 @@ with col_about:
204
  ###########################################
205
  # Query input and budget slider (Change 9)
206
  ###########################################
207
- var = st.text_input("Enter Search Question")
208
- min_budget = st.slider("Minimum Project Budget (Million €)", min_value=0.0, max_value=100.0, value=0.0)
209
 
210
  ###########################################
211
  # Load region lookup CSV
@@ -261,7 +283,7 @@ country_name_mapping, iso_code_to_sub_region = get_country_name_and_region_mappi
261
  unique_country_names = sorted(country_name_mapping.keys())
262
 
263
  # Layout filter columns
264
- col1, col2, col3, col4 = st.columns([1, 1, 1, 1])
265
  with col1:
266
  region_filter = st.selectbox("Region", ["All/Not allocated"] + sorted(unique_sub_regions))
267
  if region_filter == "All/Not allocated":
@@ -277,6 +299,14 @@ with col3:
277
  with col4:
278
  crs_options = ["All/Not allocated"] + get_crs_options(client, collection_name)
279
  crs_filter = st.selectbox("CRS", crs_options)
 
 
 
 
 
 
 
 
280
 
281
  # Checkbox for exact matches
282
  show_exact_matches = st.checkbox("Show only exact matches", value=False)
 
72
  ###########################################
73
  # RAG Answer function (Change 1 & 2 & 3)
74
  ###########################################
75
+ # ToDo move functions to utils and model specifications to config file!
76
+ # Configuration for the dedicated model
77
+ #https://qu2d8m6dmsollhly.us-east-1.aws.endpoints.huggingface.cloud
78
+ DEDICATED_MODEL = "meta-llama/Llama-3.1-8B-Instruct"
79
+ DEDICATED_ENDPOINT = "https://nwea79x4q1clc89l.eu-west-1.aws.endpoints.huggingface.cloud"
80
+ # Write access token from the settings
81
+ WRITE_ACCESS_TOKEN = st.secrets["Llama_3_1"]
82
+
83
  def get_rag_answer(query, top_results):
84
  # Build context from each top result using title, objectives, and description.
85
  context = "\n\n".join([build_context_for_result(res) for res in top_results])
 
127
  crs_set.add(crs_combined)
128
  return sorted(crs_set)
129
 
130
+ @st.cache_data
131
+ def load_project_data():
132
+ # Load your full project DataFrame using your processing function.
133
+ return process_giz_worldwide()
134
+
135
+ # Load the project data (cached)
136
+ project_data = load_project_data()
137
+
138
+ # Convert the 'total_project' column to numeric (dropping errors) and compute min and max.
139
+ # The budget is assumed to be in euros, so we convert to million euros.
140
+ budget_series = pd.to_numeric(project_data['total_project'], errors='coerce').dropna()
141
+ min_budget_val = float(budget_series.min() / 1e6)
142
+ max_budget_val = float(budget_series.max() / 1e6)
143
+
144
  ###########################################
145
  # Revised filter_results with budget filtering (Change 7 & 9)
146
  ###########################################
 
226
  ###########################################
227
  # Query input and budget slider (Change 9)
228
  ###########################################
229
+ var = st.text_input("Enter Question")
230
+
231
 
232
  ###########################################
233
  # Load region lookup CSV
 
283
  unique_country_names = sorted(country_name_mapping.keys())
284
 
285
  # Layout filter columns
286
+ col1, col2, col3, col4, col5 = st.columns([1, 1, 1, 1, 1])
287
  with col1:
288
  region_filter = st.selectbox("Region", ["All/Not allocated"] + sorted(unique_sub_regions))
289
  if region_filter == "All/Not allocated":
 
299
  with col4:
300
  crs_options = ["All/Not allocated"] + get_crs_options(client, collection_name)
301
  crs_filter = st.selectbox("CRS", crs_options)
302
+ with col5:
303
+ # Now use these values as the slider range:
304
+ min_budget = st.slider(
305
+ "Minimum Project Budget (Million €)",
306
+ min_value=min_budget_val,
307
+ max_value=max_budget_val,
308
+ value=min_budget_val)
309
+
310
 
311
  # Checkbox for exact matches
312
  show_exact_matches = st.checkbox("Show only exact matches", value=False)